Consider the following declarations of a std::vector (taken from cplusplus – EASTL has the same declarations)
iterator insert ( iterator position, const T& x );
void insert ( iterator position, size_type n, const T& x );
template <class InputIterator>
void insert ( iterator position, InputIterator first, InputIterator last );
If I type
someVector.insert(someVector.begin(), 10, 90);
how is that not confused (by the compiler) with the last overload, where 10 and 90 are ints and InputIterator‘s type is taken as int instead of the alternative which is to take 10 as size_type and 20 as a const int&?
Now I say “not” because I am implementing a vector container (learning purposes) and in my case with the above mentioned call, the third overload is selected by the compiler rather than the second overload and consequently fails to compile. If I remove the third overload then things seem fine.
Does it have something to do with what the last overload is calling (overloaded functions with iterator traits)? If so, then if I were to assume that all iterators are raw pointers (although in my case I am using the same declaration, that means that I have overload #3 with a template that expects an iterator… although expects is the wrong word here because in the end it can be anything and in this case, it is interpreted as int for me and fails to compile) how will I make sure the compiler selects the proper function?
Out of curiosity, I had a look at the GCC sources:
Later…
It seems that they were indeed worried that an ambiguity could arise, so an explicit use of typetraits and overloading is used to check whether the template matched an integral type or not.