9 Iterators library [iterators]

9.3 Iterator requirements [iterator.requirements]

9.3.14 Concept BidirectionalIterator [iterators.bidirectional]

The BidirectionalIterator concept refines ForwardIterator ([iterators.forward]), and adds the ability to move an iterator backward as well as forward.

  template <class I>
  concept bool BidirectionalIterator =
    ForwardIterator<I> &&
    DerivedFrom<iterator_category_t<I>, bidirectional_iterator_tag> &&
    requires(I i) {
      { --i } -> Same<I>&;
      { i-- } -> Same<I>&&;

A bidirectional iterator r is decrementable if and only if there exists some s such that ++s == r. Decrementable iterators r shall be in the domain of the expressions --r and r--.

Let a and b be decrementable objects of type I. BidirectionalIterator<I> is satisfied only if:

  • &--a == &a.

  • If bool(a == b), then bool(a-- == b).

  • If bool(a == b), then after evaluating both a-- and --b, bool(a == b) still holds.

  • If a is incrementable and bool(a == b), then bool(--(++a) == b).

  • If bool(a == b), then bool(++(--a) == b).