std::set<int> mySet;
//*********
//insert some elements
//*********
std::set<int>::iterator first = mySet.begin();
std::set<int>::iterator second = first + 1;
but my compiler says nono, no + operator.
I see the ++ and -- operators, but that would change what first points to, which I want to stay the same.
Athar:
Does not first++ CHANGE what first points to? ie, first != (first++)
The point is, I do not want to increment the first pointer, just get to the next element coming after it.
Seem like the advance function help to navigate our iterator around. You can say advance(itr, 1) to get what you want. Then you can advance(itr, -1) to go back to previous position.
No, a correct implementation of the postfix increment operator will never change the object. first != (first++) is true, but not because first is changed. A temporary, incremented iterator will be returned by first++.