--begin (container) - determined by behavior?

I use the decrement operator for my custom bidirectional iterator. Is a decrementing iterator pointing to the 1st element of the range defined behavior? Does it have any special meaning after decrementing, for example Range.end ()?

+4
source share
2 answers

The requirements of the iterator are pretty clear: in 24.2.6 [bidirectional iterators], Table 110:

--r (expression) X& (return type) pre: there is s such that r == ++s .

Since there is no such s for c.begin() , it cannot be reduced without violating the precondition.

+3
source

In iterators of all standard library containers, that is, undefined behavior. But if you create your own iterator class, this is not necessary.

+8
source

Source: https://habr.com/ru/post/1436432/


All Articles