I was wondering, why, in C++, the return type of std::reverse_iterator::operator[]
is left unspecified. Shouldn't it be std::reverse_iterator::reference
?
This is actually a superfluous relaxation; As of LWG 448 and LWG 299 (over N3066), which are incorporated in C++11, iterators' return types of operator[]
shall be convertible to reference
. The original LWG issue that introduced this underspecification (386) was unfortunately resolved before the one that changed the requirements on the return type of operator[]
.
Since the return type of iterators' operator[]
is now mandated to be convertible to reference
, the return type of reverse_iterator::operator[]
can clearly be just reference
- and it is, in both libc++ and libstdc++.
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