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

Section: 27.5.1.1 [reverse.iterator], 27.5.1.3.12 [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.

Discussion:

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 27.5.1.1 [reverse.iterator]'s synopsis and 27.5.1.3.12 [reverse.iter.opindex] to use reference instead of unspecified.

Proposed resolution:

This wording is relative to N4582.

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

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

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