9 Iterators library [iterators]

9.5 Common algorithm requirements [commonalgoreq]

9.5.1 General [commonalgoreq.general]

There are several additional iterator concepts that are commonly applied to families of algorithms. These group together iterator requirements of algorithm families. There are three relational concepts that specify how element values are transferred between Readable and Writable types: IndirectlyMovable, IndirectlyCopyable, and IndirectlySwappable. There are three relational concepts for rearrangements: Permutable, Mergeable, and Sortable. There is one relational concept for comparing values from different sequences: IndirectlyComparable.

Note: The equal_to<> and less<> ([comparisons]) function types used in the concepts below impose additional constraints on their arguments beyond those that appear explicitly in the concepts' bodies. equal_to<> requires its arguments satisfy EqualityComparableWith ([concepts.lib.compare.equalitycomparable]), and less<> requires its arguments satisfy StrictTotallyOrderedWith ([concepts.lib.compare.stricttotallyordered]). — end note ]

9.5.2 Concept IndirectlyMovable [commonalgoreq.indirectlymovable]

The IndirectlyMovable concept specifies the relationship between a Readable type and a Writable type between which values may be moved.

  template <class In, class Out>
  concept bool IndirectlyMovable =
    Readable<In> &&
    Writable<Out, rvalue_reference_t<In>>;

The IndirectlyMovableStorable concept augments IndirectlyMovable with additional requirements enabling the transfer to be performed through an intermediate object of the Readable type's value type.

  template <class In, class Out>
  concept bool IndirectlyMovableStorable =
    IndirectlyMovable<In, Out> &&
    Writable<Out, value_type_t<In>> &&
    Movable<value_type_t<In>> &&
    Constructible<value_type_t<In>, rvalue_reference_t<In>> &&
    Assignable<value_type_t<In>&, rvalue_reference_t<In>>;

9.5.3 Concept IndirectlyCopyable [commonalgoreq.indirectlycopyable]

The IndirectlyCopyable concept specifies the relationship between a Readable type and a Writable type between which values may be copied.

  template <class In, class Out>
  concept bool IndirectlyCopyable =
    Readable<In> &&
    Writable<Out, reference_t<In>>;

The IndirectlyCopyableStorable concept augments IndirectlyCopyable with additional requirements enabling the transfer to be performed through an intermediate object of the Readable type's value type. It also requires the capability to make copies of values.

  template <class In, class Out>
  concept bool IndirectlyCopyableStorable =
    IndirectlyCopyable<In, Out> &&
    Writable<Out, const value_type_t<In>&> &&
    Copyable<value_type_t<In>> &&
    Constructible<value_type_t<In>, reference_t<In>> &&
    Assignable<value_type_t<In>&, reference_t<In>>;

9.5.4 Concept IndirectlySwappable [commonalgoreq.indirectlyswappable]

The IndirectlySwappable concept specifies a swappable relationship between the values referenced by two Readable types.

  template <class I1, class I2 = I1>
  concept bool IndirectlySwappable =
    Readable<I1> && Readable<I2> &&
    requires(I1&& i1, I2&& i2) {
      ranges::iter_swap(std::forward<I1>(i1), std::forward<I2>(i2));
      ranges::iter_swap(std::forward<I2>(i2), std::forward<I1>(i1));
      ranges::iter_swap(std::forward<I1>(i1), std::forward<I1>(i1));
      ranges::iter_swap(std::forward<I2>(i2), std::forward<I2>(i2));
    };

Given an object i1 of type I1 and an object i2 of type I2, IndirectlySwappable<I1, I2> is satisfied if after ranges::iter_swap(i1, i2), the value of *i1 is equal to the value of *i2 before the call, and vice versa.

9.5.5 Concept IndirectlyComparable [commonalgoreq.indirectlycomparable]

The IndirectlyComparable concept specifies the common requirements of algorithms that compare values from two different sequences.

  template <class I1, class I2, class R = equal_to<>, class P1 = identity,
    class P2 = identity>
  concept bool IndirectlyComparable =
    IndirectRelation<R, projected<I1, P1>, projected<I2, P2>>;

9.5.6 Concept Permutable [commonalgoreq.permutable]

The Permutable concept specifies the common requirements of algorithms that reorder elements in place by moving or swapping them.

  template <class I>
  concept bool Permutable =
    ForwardIterator<I> &&
    IndirectlyMovableStorable<I, I> &&
    IndirectlySwappable<I, I>;

9.5.7 Concept Mergeable [commonalgoreq.mergeable]

The Mergeable concept specifies the requirements of algorithms that merge sorted sequences into an output sequence by copying elements.

  template <class I1, class I2, class Out,
      class R = less<>, class P1 = identity, class P2 = identity>
  concept bool Mergeable =
    InputIterator<I1> &&
    InputIterator<I2> &&
    WeaklyIncrementable<Out> &&
    IndirectlyCopyable<I1, Out> &&
    IndirectlyCopyable<I2, Out> &&
    IndirectStrictWeakOrder<R, projected<I1, P1>, projected<I2, P2>>;

9.5.8 Concept Sortable [commonalgoreq.sortable]

The Sortable concept specifies the common requirements of algorithms that permute sequences into ordered sequences (e.g., sort).

  template <class I, class R = less<>, class P = identity>
  concept bool Sortable =
    Permutable<I> &&
    IndirectStrictWeakOrder<R, projected<I, P>>;