I am implementing decrement operator for my custom bidirectional iterator. Is decrementing iterator pointing at 1st element of Range is defined behavior? Does it have some special value after decrementing, like Range.end()?
In the iterators of all of the standard library containers, that is undefined behavior. But if you are making your own iterator class, it doesn't have to be.
The iterator requirements are rather clear: In 24.2.6 [bidirectional.iterators], Table 110:
--r
(Expression)X&
(Return type) pre: there existss
such thatr == ++s
.
Since there is no such s
for c.begin()
, it can't be decremented without violating the precondition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With