Class template reverse_iterator is an iterator adaptor that iterates from the end of the sequence defined by its underlying iterator to the beginning of that sequence. The fundamental relation between a reverse iterator and its corresponding underlying iterator i is established by the identity: *make_reverse_iterator(i) == *prev(i).
namespace std { namespace experimental { namespace ranges { inline namespace v1 { template <BidirectionalIterator I> class reverse_iterator { public: using iterator_type = I; using difference_type = difference_type_t<I>; using value_type = value_type_t<I>; using iterator_category = iterator_category_t<I>; using reference = reference_t<I>; using pointer = I; constexpr reverse_iterator(); explicit constexpr reverse_iterator(I x); constexpr reverse_iterator(const reverse_iterator<ConvertibleTo<I>>& i); constexpr reverse_iterator& operator=(const reverse_iterator<ConvertibleTo<I>>& i); constexpr I base() const; constexpr reference operator*() const; constexpr pointer operator->() const; constexpr reverse_iterator& operator++(); constexpr reverse_iterator operator++(int); constexpr reverse_iterator& operator--(); constexpr reverse_iterator operator--(int); constexpr reverse_iterator operator+ (difference_type n) const requires RandomAccessIterator<I>; constexpr reverse_iterator& operator+=(difference_type n) requires RandomAccessIterator<I>; constexpr reverse_iterator operator- (difference_type n) const requires RandomAccessIterator<I>; constexpr reverse_iterator& operator-=(difference_type n) requires RandomAccessIterator<I>; constexpr reference operator[](difference_type n) const requires RandomAccessIterator<I>; friend constexpr rvalue_reference_t<I> iter_move(const reverse_iterator& i) noexcept(see below); template <IndirectlySwappable<I> I2> friend constexpr void iter_swap(const reverse_iterator& x, const reverse_iterator<I2>& y) noexcept(see below); private: I current; // exposition only }; template <class I1, class I2> requires EqualityComparableWith<I1, I2> constexpr bool operator==( const reverse_iterator<I1>& x, const reverse_iterator<I2>& y); template <class I1, class I2> requires EqualityComparableWith<I1, I2> constexpr bool operator!=( const reverse_iterator<I1>& x, const reverse_iterator<I2>& y); template <class I1, class I2> requires StrictTotallyOrderedWith<I1, I2> constexpr bool operator<( const reverse_iterator<I1>& x, const reverse_iterator<I2>& y); template <class I1, class I2> requires StrictTotallyOrderedWith<I1, I2> constexpr bool operator>( const reverse_iterator<I1>& x, const reverse_iterator<I2>& y); template <class I1, class I2> requires StrictTotallyOrderedWith<I1, I2> constexpr bool operator>=( const reverse_iterator<I1>& x, const reverse_iterator<I2>& y); template <class I1, class I2> requires StrictTotallyOrderedWith<I1, I2> constexpr bool operator<=( const reverse_iterator<I1>& x, const reverse_iterator<I2>& y); template <class I1, class I2> requires SizedSentinel<I1, I2> constexpr difference_type_t<I2> operator-( const reverse_iterator<I1>& x, const reverse_iterator<I2>& y); template <RandomAccessIterator I> constexpr reverse_iterator<I> operator+( difference_type_t<I> n, const reverse_iterator<I>& x); template <BidirectionalIterator I> constexpr reverse_iterator<I> make_reverse_iterator(I i); }}}}
Effects: Value-initializes current. Iterator operations applied to the resulting iterator have defined behavior if and only if the corresponding operations are defined on a value-initialized iterator of type I.
explicit constexpr reverse_iterator(I x);
Effects: Initializes current with x.
constexpr reverse_iterator(const reverse_iterator<ConvertibleTo<I>>& i);
Effects: Initializes current with i.current.
constexpr reverse_iterator&
operator=(const reverse_iterator<ConvertibleTo<I>>& i);
Effects: Assigns i.current to current.
Returns: *this.
constexpr reference operator*() const;
Effects: Equivalent to: return *prev(current);
constexpr pointer operator->() const;
Effects: Equivalent to: return prev(current);
constexpr reverse_iterator& operator++();
Effects: -- current;
Returns: *this.
constexpr reverse_iterator operator++(int);
Effects:
reverse_iterator tmp = *this; --current; return tmp;
constexpr reverse_iterator& operator--();
Effects: ++current
Returns: *this.
constexpr reverse_iterator operator--(int);
Effects:
reverse_iterator tmp = *this; ++current; return tmp;
constexpr reverse_iterator
operator+(difference_type n) const
requires RandomAccessIterator<I>;
Returns: reverse_iterator(current-n).
constexpr reverse_iterator&
operator+=(difference_type n)
requires RandomAccessIterator<I>;
Effects: current -= n;
Returns: *this.
constexpr reverse_iterator
operator-(difference_type n) const
requires RandomAccessIterator<I>;
Returns: reverse_iterator(current+n).
constexpr reverse_iterator&
operator-=(difference_type n)
requires RandomAccessIterator<I>;
Effects: current += n;
Returns: *this.
constexpr reference operator[](
difference_type n) const
requires RandomAccessIterator<I>;
Returns: current[-n-1].
template <class I1, class I2>
requires EqualityComparableWith<I1, I2>
constexpr bool operator==(
const reverse_iterator<I1>& x,
const reverse_iterator<I2>& y);
Effects: Equivalent to: return x.current == y.current;
template <class I1, class I2>
requires EqualityComparableWith<I1, I2>
constexpr bool operator!=(
const reverse_iterator<I1>& x,
const reverse_iterator<I2>& y);
Effects: Equivalent to: return x.current != y.current;
template <class I1, class I2>
requires StrictTotallyOrderedWith<I1, I2>
constexpr bool operator<(
const reverse_iterator<I1>& x,
const reverse_iterator<I2>& y);
Effects: Equivalent to: return x.current > y.current;
template <class I1, class I2>
requires StrictTotallyOrderedWith<I1, I2>
constexpr bool operator>(
const reverse_iterator<I1>& x,
const reverse_iterator<I2>& y);
Effects: Equivalent to: return x.current < y.current;
template <class I1, class I2>
requires StrictTotallyOrderedWith<I1, I2>
constexpr bool operator>=(
const reverse_iterator<I1>& x,
const reverse_iterator<I2>& y);
Effects: Equivalent to: return x.current <= y.current;
template <class I1, class I2>
requires StrictTotallyOrderedWith<I1, I2>
constexpr bool operator<=(
const reverse_iterator<I1>& x,
const reverse_iterator<I2>& y);
Effects: Equivalent to: return x.current >= y.current;
template <class I1, class I2>
requires SizedSentinel<I1, I2>
constexpr difference_type_t<I2> operator-(
const reverse_iterator<I1>& x,
const reverse_iterator<I2>& y);
Effects: Equivalent to: return y.current - x.current;
template <RandomAccessIterator I>
constexpr reverse_iterator<I> operator+(
difference_type_t<I> n,
const reverse_iterator<I>& x);
Effects: Equivalent to: return reverse_iterator<I>(x.current - n);
friend constexpr rvalue_reference_t<I> iter_move(const reverse_iterator& i)
noexcept(see below);
Effects: Equivalent to: return ranges::iter_move(prev(i.current));
Remarks: The expression in noexcept is equivalent to:
noexcept(ranges::iter_move(declval<I&>())) && noexcept(--declval<I&>()) && is_nothrow_copy_constructible<I>::value
template <IndirectlySwappable<I> I2>
friend constexpr void iter_swap(const reverse_iterator& x, const reverse_iterator<I2>& y)
noexcept(see below);
Effects: Equivalent to ranges::iter_swap(prev(x.current), prev(y.current)).
Remarks: The expression in noexcept is equivalent to:
noexcept(ranges::iter_swap(declval<I>(), declval<I>())) && noexcept(--declval<I&>())
template <BidirectionalIterator I>
constexpr reverse_iterator<I> make_reverse_iterator(I i);
Returns: reverse_iterator<I>(i).