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: 24.5.1.2 [reverse.iterator], 24.5.1.6 [reverse.iter.elem] Status: New Submitter: Robert Haberlach Opened: 2016-02-28 Last modified: 2021-06-06

Priority: 3

View all other issues in [reverse.iterator].

View all issues with New status.

Discussion:

Issue 386(i) 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 24.5.1.2 [reverse.iterator]'s synopsis and 24.5.1.6 [reverse.iter.elem] to use reference instead of unspecified.

[2021-06-06 Tim syncs wording to current working draft]

Proposed resolution:

This wording is relative to N4885.

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

    namespace std {
      template <class Iterator>
      class reverse_iterator {
      public:
        […]
        using reference         = iter_reference_t<Iterator>;
        […]
        constexpr referenceunspecified operator[](difference_type n) const;
        […]
      };
    }
    
  2. Change 24.5.1.6 [reverse.iter.elem] before p3 as indicated:

    constexpr referenceunspecified operator[](difference_type n) const;