Stefano Falasca
Stefano Falasca

Reputation: 9097

alternative to std::advance which doesn't modify the input

Cannot manage to find it, hope somebody can help. There is a function in the std library which gets called upon an iterator and an unsigned number, which returns the iterator pointing to the object to which the input iterator would have pointed if advance would have been called onto it. Which function am I referring to? I'm sure it exists!

Upvotes: 1

Views: 398

Answers (3)

Aleksander Fular
Aleksander Fular

Reputation: 873

Take a look at std::next function
http://en.cppreference.com/w/cpp/iterator/next

Upvotes: 1

In C++11, there's std::next (defined in <iterator>). Before that, there was the same in boost, or you can write it yourself.

Upvotes: 2

Jan Herrmann
Jan Herrmann

Reputation: 2767

I'm sure there is no such function for input iterators. If you modify (increment) input iterators you invalidate other copies of it. So this function could only be implemented for forward iterators.

Upvotes: 2

Related Questions