|
|
|
|
|
by commonlisp94
1040 days ago
|
|
> something about within an allocation and one past the end? Yeah, I forgot about that. So I agree there is some subtly which is likely to catch beginners. Your example could safely be: if (std::distance(begin, end) > 5)
Another approach I would recommend is to write a `guarded_advance` which takes an integer and the end pointer.Also note that the situation you are describing is still a little unusual because the baseline assumption is it takes linear time to advance an iterator by more than 1 increment. > but neither will valid increment between two integers. No need for iterators in that case either. The purpose of an iterator is to abstract data structure access. The coordinate inside a complex data structure may not be representable by an integer. |
|