I want to initialize an iterator (of an arbitrary type) with a successor to another iterator (of the same type). The following code works with random access iterators, but it does not work with forwards or bidirectional iterators:
Iterator i = j + 1;
A simple workaround is:
Iterator i = j; ++i;
But this does not work as an init-stament for loop. I could use a function template as follows:
template <typename Iterator> Iterator succ(Iterator it) { return ++it; }
and then use it like this:
Iterator i = succ(j);
Is there anything similar in STL or Boost, or is there an even better solution that I don't know about?
fredoverflow
source share