Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the return type of std::reverse_iterator::operator[] unspecified?

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?

like image 427
Vincent Avatar asked Feb 28 '16 15:02

Vincent


1 Answers

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++.

like image 114
Columbo Avatar answered Sep 20 '22 13:09

Columbo