In “Effective STL” tip 16, it says that we should avoid to pass iterator to a function which accepts a pointer. Could anyone explain the detail for me please?
void doSomething(const int* pInts, size_t numInts);
vector<int> v;
...
doSomething(&v[0],v.size()) //correct
doSomething(v.begin(),v.size()) //incorrect
In some early implementations of the standard library iterators were implemented as pointers.
Code that depended on that property stopped working when iterators became non-pointers.
So, you should not pass an iterator where a pointer is expected, because if it compiles then it’s just by happen-chance. An iterator is not necessarily a pointer. And if it is a pointer, then it may not necessarily be a pointer in some later version (of the library, compiler, whatever).