Should C ++ Iterators decrease after passing the last element?

I modified my containers as compatible with STL. I modified my iterators to have the necessary functions. These are all random access iterators. They currently work perfectly with all applicable STL algorithms. But one of my iterators will not function as soon as it becomes invalid (beyond). Do I need to have this property? In particular, I am afraid of the end () iterator, which cannot be reduced. Note that it can be compared, and even the distance can be calculated using other valid iterators. The iterator is currently 4 bytes in size, I really don't want to add 4 more if it is not really needed.

Thanks in advance,
Cem

+4
source share
2 answers

With a random_access_iterator this is required. You will have to implement it. In particular, according to 24.1.4.1 for a bidirectional_iterator (of which a random_access_iterator is a specialization) the decrement must always be valid.

+4
source

std :: reverse_iterator depends on the .end () container to be valid and be able to reduce.

+3
source

All Articles