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++.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.