I’d like get far next value for STL list iterator but it doesn’t implement operator+, vector has it though. Why and how can I get the value where I want?
I think I can do that if I call operator++ several times, but isn’t that a little bit dirty?
What I want to do is the following:
list<int> l;
...omitted...
list<int>::iterator itr = l.begin() + 3; // but, list iterator does not have
// operator+
What is the best solution for what I want?
You can also use
std::next(and prev) or the equivalents provided by Boost if you don’t have access to C++11.Rationale:
std::advanceis awkward to use (it works by side-effect, not by returning a copy).