I need to get to the iterator having offset ofst
: it + ofst
: is there
a way to do that?
No, there is no operator+
overload defined for this for std::set::iterator
(aka bidirectional iterators). However, you can use std::next
, from <iterator>
header as follows to achive the same.
#include <iterator> // std::next
auto nthIter = std::next(it, ofst);
This basically behind the scene increments ofst
times too.
The std::set
has bidirectional iterators, which has no luxuries like random access iterators, and hence need to increment like this.
That being said, you could overload the operator+
(and maybe operator-
) for the bidirectional iterators, which will not be recommended though.