lundi 24 septembre 2018

Why compiler said "candidate template ignored: couldn't infer template argument 'InputIterator'"?

I'm learning template and writing Vector, there is a constructor in Vector :

template <typename InputIterator>
Vector(typename __isInputIterator<InputIterator>::__result, typename __isInputIterator<InputIterator>::__result, const allocator &);

Template struct __isInputIterator :

struct InputIterator {
    constexpr static bool isInputIterator {true};
    //...
}
template <typename, bool>
struct __InputIteratorInferringAuxiliary {
    using __type = __falseType;
};
template <typename Iterator>
struct __InputIteratorInferringAuxiliary<Iterator, true> {
    using __type = Iterator;
};
template <typename Iterator>
struct __isInputIterator {
    using __result = typename __InputIteratorInferringAuxiliary<Iterator,
                __IteratorTraits<Iterator>::iteratorTag::isInputIterator
        >::__type;
};
template <typename T>
struct __IteratorTraits<T *> {
    using sizeType = unsigned long;
    using differenceType = long;
    using valueType = T;
    using reference = valueType &;
    using constReference = const valueType &;
    using rightValueReference = valueType &&;
    using pointer = valueType *;
    using constPointer = const valueType *;
    using iteratorTag = RandomAccessIterator;//isInputIterator tag in RandomAccessIterator class is true
};

Demo :

int arr[] {1, 2, 3};
Vector<int> vec(begin(arr), end(arr));//candidate template ignored: couldn't infer template argument 'InputIterator'

Why the compiler would say that candidate template ignored: couldn't infer template argument 'InputIterator'

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire