What if I increment an iterator by 2 when it points onto the last element of a vector? In this question asking how to adjust the iterator to an STL container by 2 elements t
Perhaps you should have something like this:
template
Itr safe_advance(Itr i, Itr end, size_t delta)
{
while(i != end && delta--)
i++;
return i;
}
You can overload this for when iterator_category
is random_access_iterator
to do something like the following:
return (delta > end - i)? end : i + delta;