If your container implements begin()
and end()
as member functions, and the return type of the functions supports the pre-increment operator, you can use it in most contexts. The important ones that I can think of are:
range-for
. You can use:
Container c;
for ( auto& item : c ) { ... }
Functions that work with iterators. Example:
Container c;
Item item;
std::find(c.begin(), c.end(), item);
Making the iterator a sub-class of std::iterator is best way to ensure that it will be compatible with all the standard algorithms. (Thanks @Adrian).