You can pass pointers to algorithms such as std::sort , std::find or std::copy . These are templates that are customizable for everything that works as a suitable iterator.
This does not mean that different iterators are necessarily converted to each other.
The erase method of the std::vector<int> container can only work with iterators, only with elements of the same vector. As already mentioned, this can be implemented as a pointer, but usually it is not for the reasons indicated here: C ++ std :: vector <gt; :: iterator is not a pointer, why?
Consider std::find :
template< class InputIt, class T > InputIt find( InputIt first, InputIt last, const T& value );
Here InputIt is a template parameter. The std::find pattern will work with any type of iterator that satisfies the requirements of the input iterator and whose operator* returns what can be compared to enter T Pointers work well here. As Fire Lancer correctly pointed out in the comment, both first and last must be of type InputIt .
Now compare this to std :: vector :: erase :
iterator erase( const_iterator pos );
This takes const_iterator , which is one of the typedefs of the std::vector class. This is one specific type of iterator, not a template parameter.
Paulr
source share