23 Ranges library [ranges]

23.8 Range adaptors [range.adaptors]

23.8.11 Reverse view [range.reverse]

23.8.11.1 Overview [range.reverse.overview]

reverse_­view takes a bidirectional View and produces another View that iterates the same elements in reverse order.
[Example
:
vector<int> is {0,1,2,3,4};
reverse_view rv {is};
for (int i : rv)
  cout << i << ' '; // prints: 4 3 2 1 0
end example
]

23.8.11.2 Class template reverse_­view [range.reverse.view]

namespace std::ranges {
  template<View V>
    requires BidirectionalRange<V>
  class reverse_view : public view_interface<reverse_view<V>> {
  private:
    V base_ = V();  // exposition only
  public:
    reverse_view() = default;

    constexpr explicit reverse_view(V r);

    template<ViewableRange R>
      requires BidirectionalRange<R> && Constructible<V, all_view<R>>
    constexpr explicit reverse_view(R&& r);

    constexpr V base() const;

    constexpr reverse_iterator<iterator_t<V>> begin();
    constexpr reverse_iterator<iterator_t<V>> begin() requires CommonRange<V>;
    constexpr reverse_iterator<iterator_t<const V>> begin() const
      requires CommonRange<const V>;

    constexpr reverse_iterator<iterator_t<V>> end();
    constexpr reverse_iterator<iterator_t<const V>> end() const
      requires CommonRange<const V>;

    constexpr auto size() requires SizedRange<V> {
      return ranges::size(base_);
    }
    constexpr auto size() const requires SizedRange<const V> {
      return ranges::size(base_);
    }
  };

  template<class R>
    reverse_view(R&&) -> reverse_view<all_view<R>>;
}
constexpr explicit reverse_view(V base);
Effects: Initializes base_­ with std::move(base).
template<ViewableRange R> requires BidirectionalRange<R> && Constructible<V, all_view<R>> constexpr explicit reverse_view(R&& r);
Effects: Initializes base_­ with view::all(std::forward<R>(r)).
constexpr V base() const;
Effects: Equivalent to: return base_­;
constexpr reverse_iterator<iterator_t<V>> begin();
Returns:
make_reverse_iterator(ranges::next(ranges::begin(base_), ranges::end(base_)))
Remarks: In order to provide the amortized constant time complexity required by the Range concept, this function caches the result within the reverse_­view for use on subsequent calls.
constexpr reverse_iterator<iterator_t<V>> begin() requires CommonRange<V>; constexpr reverse_iterator<iterator_t<const V>> begin() const requires CommonRange<const V>;
Effects: Equivalent to: return make_­reverse_­iterator(ranges::end(base_­));
constexpr reverse_iterator<iterator_t<V>> end(); constexpr reverse_iterator<iterator_t<const V>> end() const requires CommonRange<const V>;
Effects: Equivalent to: return make_­reverse_­iterator(ranges::begin(base_­));

23.8.11.3 view​::​reverse [range.reverse.adaptor]

The name view::reverse denotes a range adaptor object.
For some subexpression E, the expression view::reverse(E) is expression-equivalent to reverse_­view{E}.