I'm trying to overload a certain function so only iterators of contiguous containers (which are std::vector::iterator ,std::array::iterator ,and built-in arrays iterators == raw pointers) can be a valid argument.
for some reason my functions fail to compile for vector and std::array :
functions:
template <class T,size_t N>
void catchIterator(typename std::array<T, N>::iterator it) {
//do somthing
}
template <class T>
void catchIterator(typename std::vector<T>::iterator it) {
//do somthing
}
example of use :
std::array<int, 10> arr;
auto it = arr.begin();
catchIterator(it);
std::vector<int> vec;
auto it0 = vec.begin();
catchIterator(it0);
Errors :
Error (active) no instance of overloaded function "catchIterator" matches the argument list
Error (active) no instance of overloaded function "catchIterator" matches the argument list
Error C2783 'void catchIterator(std::array<_Ty,_Size>::iterator)': could not deduce template argument for 'T'
Error C2783 'void catchIterator(std::array<_Ty,_Size>::iterator)': could not deduce template argument for 'N'
Error C2672 'catchIterator': no matching overloaded function found
I'm using VC++ with Visual studio 2015 RTM.
The errors are pretty self-explanatory, but I wonder if the compiler couldn't really deduce T and N from it and it0, after all, it is part of it/it0 type..
how can make it work?
Edit:
I'll go with @ForEveR suggestion and pass the container+iterator/index as arguments instead.
thanks!