This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

2595. reverse_iterator::operator[]'s return type revisited

Section: [reverse.iterator], [reverse.iter.opindex] Status: New Submitter: Robert Haberlach Opened: 2016-02-28 Last modified: 2016-05-02

Priority: 3

View all other issues in [reverse.iterator].

View all issues with New status.


Issue 386 changed the return type of reverse_iterator::operator[] to unspecified. However, as of N3066, the return type of a random access iterator's operator[] shall be convertible to reference; thus the return type of reverse_iterator::operator[] should be reference (and it is in all common implementations).

Suggested resolution: Adjust [reverse.iterator]'s synopsis and [reverse.iter.opindex] to use reference instead of unspecified.

Proposed resolution:

This wording is relative to N4582.

  1. Edit [reverse.iterator], class template synopsis, as indicated:

    namespace std {
      template <class Iterator>
      class reverse_iterator {
        typedef typename iterator_traits<Iterator>::reference reference;
        constexpr referenceunspecified operator[](difference_type n) const;
  2. Change [reverse.iter.opindex] before p1 as indicated:

    constexpr referenceunspecified operator[](
      typename reverse_iterator<Iterator>::difference_type n) const;