[alg.modifying.operations] (original) (raw)

26 Algorithms library [algorithms]

26.7 Mutating sequence operations [alg.modifying.operations]

26.7.1 Copy [alg.copy]

template<class InputIterator, class OutputIterator> constexpr OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result);template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result);

Preconditions: result is not in the range [first, last).

Effects: Copies elements in the range [first, last) into the range [result, result + N) starting from first and proceeding to last.

For each non-negative integer , performs *(result + n) = *(first + n).

Returns:

Complexity: Exactly N assignments.

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 copy(ExecutionPolicy&& policy, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result);

Preconditions: The ranges [first, last) and [result, result + (last - first)) do not overlap.

Effects: Copies elements in the range [first, last) into the range [result, result + (last - first)).

For each non-negative integer n < (last - first), performs *(result + n) = *(first + n).

Returns: result + (last - first).

Complexity: Exactly last - first assignments.

template<class InputIterator, class Size, class OutputIterator> constexpr OutputIterator copy_n(InputIterator first, Size n, OutputIterator result);template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2> ForwardIterator2 copy_n(ExecutionPolicy&& exec, ForwardIterator1 first, Size n, ForwardIterator2 result);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> constexpr ranges::copy_n_result<I, O> ranges::copy_n(I first, iter_difference_t<I> n, O result);

Effects: For each non-negative integer , performs *(result + i) = *(first + i).

Returns:

Complexity: Exactly N assignments.

template<class InputIterator, class OutputIterator, class Predicate> constexpr OutputIterator copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,class Predicate> ForwardIterator2 copy_if(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, Predicate pred);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, class Proj = identity,[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> constexpr ranges::copy_if_result<I, O> ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, class Proj = identity,[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O> ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {});

Let E be:

and N be the number of iterators i in the range [first, last) for which the condition E holds.

Preconditions: The ranges [first, last) and [result, result + (last - first)) do not overlap.

[Note 1:

For the overload with an ExecutionPolicy, there might be a performance cost if iterator_traits<ForwardIterator1>​::​value_typeis not Cpp17MoveConstructible (Table 31).

— _end note_]

Effects: Copies all of the elements referred to by the iterator i in the range [first, last) for which E is true.

Returns:

Complexity: Exactly last - first applications of the corresponding predicate and any projection.

template<class BidirectionalIterator1, class BidirectionalIterator2> constexpr BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result);template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional%5Fiterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I1> S1, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional%5Fiterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I2> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I1, I2> constexpr ranges::copy_backward_result<I1, I2> ranges::copy_backward(I1 first, S1 last, I2 result);template<[bidirectional_range](range.refinements#concept:bidirectional%5Frange "25.4.5 Other range refinements [range.refinements]") R, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional%5Fiterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, I> constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I> ranges::copy_backward(R&& r, I result);

Preconditions: result is not in the range (first, last].

Effects: Copies elements in the range [first, last) into the range [result - N, result) starting from last - 1 and proceeding to first.202

For each positive integer n ≤ N, performs *(result - n) = *(last - n).

Returns:

Complexity: Exactly N assignments.

26.7.2 Move [alg.move]

template<class InputIterator, class OutputIterator> constexpr OutputIterator move(InputIterator first, InputIterator last, OutputIterator result);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O> requires [indirectly_movable](alg.req.ind.move#concept:indirectly%5Fmovable "24.3.7.2 Concept indirectly_­movable [alg.req.ind.move]")<I, O> constexpr ranges::move_result<I, O> ranges::move(I first, S last, O result);template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O> requires [indirectly_movable](alg.req.ind.move#concept:indirectly%5Fmovable "24.3.7.2 Concept indirectly_­movable [alg.req.ind.move]")<iterator_t<R>, O> constexpr ranges::move_result<borrowed_iterator_t<R>, O> ranges::move(R&& r, O result);

Let E be

Let N be last - first.

Preconditions: result is not in the range [first, last).

Effects: Moves elements in the range [first, last) into the range [result, result + N) starting from first and proceeding to last.

For each non-negative integer , performs *(result + n) = E.

Returns:

Complexity: Exactly N assignments.

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 move(ExecutionPolicy&& policy, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result);

Preconditions: The ranges [first, last) and [result, result + N) do not overlap.

Effects: Moves elements in the range [first, last) into the range [result, result + N).

For each non-negative integer , performs *(result + n) = std​::​​move(*(first + n)).

Complexity: Exactly N assignments.

template<class BidirectionalIterator1, class BidirectionalIterator2> constexpr BidirectionalIterator2 move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result);template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional%5Fiterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I1> S1, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional%5Fiterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I2> requires [indirectly_movable](alg.req.ind.move#concept:indirectly%5Fmovable "24.3.7.2 Concept indirectly_­movable [alg.req.ind.move]")<I1, I2> constexpr ranges::move_backward_result<I1, I2> ranges::move_backward(I1 first, S1 last, I2 result);template<[bidirectional_range](range.refinements#concept:bidirectional%5Frange "25.4.5 Other range refinements [range.refinements]") R, [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional%5Fiterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I> requires [indirectly_movable](alg.req.ind.move#concept:indirectly%5Fmovable "24.3.7.2 Concept indirectly_­movable [alg.req.ind.move]")<iterator_t<R>, I> constexpr ranges::move_backward_result<borrowed_iterator_t<R>, I> ranges::move_backward(R&& r, I result);

Let E be

Let N be last - first.

Preconditions: result is not in the range (first, last].

Effects: Moves elements in the range [first, last) into the range [result - N, result) starting from last - 1 and proceeding to first.203

For each positive integer n ≤ N, performs *(result - n) = E.

Returns:

Complexity: Exactly N assignments.

26.7.3 Swap [alg.swap]

template<class ForwardIterator1, class ForwardIterator2> constexpr ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 swap_ranges(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I2> S2> requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly%5Fswappable "24.3.7.4 Concept indirectly_­swappable [alg.req.ind.swap]")<I1, I2> constexpr ranges::swap_ranges_result<I1, I2> ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R2> requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly%5Fswappable "24.3.7.4 Concept indirectly_­swappable [alg.req.ind.swap]")<iterator_t<R1>, iterator_t<R2>> constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>> ranges::swap_ranges(R1&& r1, R2&& r2);

Let:

Preconditions: The two ranges [first1, last1) and [first2, last2) do not overlap.

For the overloads in namespace std,*(first1 + n) is swappable with ([swappable.requirements])*(first2 + n).

Effects: For each non-negative integer performs:

Returns:

Complexity: Exactly M swaps.

template<class ForwardIterator1, class ForwardIterator2> constexpr void iter_swap(ForwardIterator1 a, ForwardIterator2 b);

Preconditions: a and b are dereferenceable.

Effects: As if by swap(*a, *b).

26.7.4 Transform [alg.transform]

template<class InputIterator, class OutputIterator,class UnaryOperation> constexpr OutputIterator transform(InputIterator first1, InputIterator last1, OutputIterator result, UnaryOperation op);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,class UnaryOperation> ForwardIterator2 transform(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 result, UnaryOperation op);template<class InputIterator1, class InputIterator2,class OutputIterator, class BinaryOperation> constexpr OutputIterator transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryOperation binary_op);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,class ForwardIterator, class BinaryOperation> ForwardIterator transform(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator result, BinaryOperation binary_op);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O,[copy_constructible](concept.copyconstructible#concept:copy%5Fconstructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]") F, class Proj = identity> requires [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<O, indirect_result_t<F&, projected<I, Proj>>> constexpr ranges::unary_transform_result<I, O> ranges::transform(I first1, S last1, O result, F op, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, [copy_constructible](concept.copyconstructible#concept:copy%5Fconstructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]") F,class Proj = identity> requires [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>> constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O> ranges::transform(R&& r, O result, F op, Proj proj = {});template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I2> S2,[weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, [copy_constructible](concept.copyconstructible#concept:copy%5Fconstructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]") F, class Proj1 = identity,class Proj2 = identity> requires [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<O, indirect_result_t<F&, projected<I1, Proj1>, projected<I2, Proj2>>> constexpr ranges::binary_transform_result<I1, I2, O> ranges::transform(I1 first1, S1 last1, I2 first2, S2 last2, O result, F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R2, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O,[copy_constructible](concept.copyconstructible#concept:copy%5Fconstructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]") F, class Proj1 = identity, class Proj2 = identity> requires [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>, projected<iterator_t<R2>, Proj2>>> constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O> ranges::transform(R1&& r1, R2&& r2, O result, F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});

Let:

Preconditions: op and binary_op do not invalidate iterators or subranges, nor modify elements in the ranges

Effects: Assigns through every iterator iin the range [result, result + N) a new corresponding value equal to E.

Returns:

Complexity: Exactly N applications of op or binary_op, and any projections.

This requirement also applies to the overload with an ExecutionPolicy.

Remarks: result may be equal to first1 or first2.

26.7.5 Replace [alg.replace]

template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type> constexpr void replace(ForwardIterator first, ForwardIterator last,const T& old_value, const T& new_value);template<class ExecutionPolicy, class ForwardIterator,class T = iterator_traits<ForwardIterator>::value_type> void replace(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,const T& old_value, const T& new_value);template<class ForwardIterator, class Predicate,class T = iterator_traits<ForwardIterator>::value_type> constexpr void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);template<class ExecutionPolicy, class ForwardIterator, class Predicate,class T = iterator_traits<ForwardIterator>::value_type> void replace_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, class Proj = identity,class T1 = projected_value_t<I, Proj>, class T2 = T1> requires [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<I, const T2&> && [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Fbinary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T1*> constexpr I ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, class Proj = identity,class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1> requires [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<iterator_t<R>, const T2&> && [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Fbinary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*> constexpr borrowed_iterator_t<R> ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, class Proj = identity,class T = projected_value_t<I, Proj>,[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred> requires [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<I, const T&> constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>,[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred> requires [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<iterator_t<R>, const T&> constexpr borrowed_iterator_t<R> ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});

Let E be

Effects: Substitutes elements referred by the iterator iin the range [first, last) with new_value, when E is true.

Returns: last for the overloads in namespace ranges.

Complexity: Exactly last - first applications of the corresponding predicate and any projection.

template<class InputIterator, class OutputIterator, class T> constexpr OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result,const T& old_value, const T& new_value);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T> ForwardIterator2 replace_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result,const T& old_value, const T& new_value);template<class InputIterator, class OutputIterator, class Predicate, class T> constexpr OutputIterator replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,class Predicate, class T> ForwardIterator2 replace_copy_if(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, Predicate pred, const T& new_value);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, class O,class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = iter_value_t<O>> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> && [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Fbinary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T1*> && [output_iterator](iterator.concept.output#concept:output%5Fiterator "24.3.4.10 Concept output_­iterator [iterator.concept.output]")<O, const T2&> constexpr ranges::replace_copy_result<I, O> ranges::replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, class O, class Proj = identity,class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = iter_value_t<O>> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> && [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Fbinary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*> && [output_iterator](iterator.concept.output#concept:output%5Fiterator "24.3.4.10 Concept output_­iterator [iterator.concept.output]")<O, const T2&> constexpr ranges::replace_copy_result<borrowed_iterator_t<R>, O> ranges::replace_copy(R&& r, O result, const T1& old_value, const T2& new_value, Proj proj = {});template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S,class O, class T = iter_value_t<O>,class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> && [output_iterator](iterator.concept.output#concept:output%5Fiterator "24.3.4.10 Concept output_­iterator [iterator.concept.output]")<O, const T&> constexpr ranges::replace_copy_if_result<I, O> ranges::replace_copy_if(I first, S last, O result, Pred pred, const T& new_value, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, class O, class T = iter_value_t<O>, class Proj = identity,[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> && [output_iterator](iterator.concept.output#concept:output%5Fiterator "24.3.4.10 Concept output_­iterator [iterator.concept.output]")<O, const T&> constexpr ranges::replace_copy_if_result<borrowed_iterator_t<R>, O> ranges::replace_copy_if(R&& r, O result, Pred pred, const T& new_value, Proj proj = {});

Let E be

Preconditions: The ranges [first, last) and [result, result + (last - first)) do not overlap.

Effects: Assigns through every iterator iin the range [result, result + (last - first)) a new corresponding value

Returns:

Complexity: Exactly last - first applications of the corresponding predicate and any projection.

26.7.6 Fill [alg.fill]

template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type> constexpr void fill(ForwardIterator first, ForwardIterator last, const T& value);template<class ExecutionPolicy, class ForwardIterator,class T = iterator_traits<ForwardIterator>::value_type> void fill(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& value);template<class OutputIterator, class Size, class T = iterator_traits<OutputIterator>::value_type> constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);template<class ExecutionPolicy, class ForwardIterator, class Size,class T = iterator_traits<ForwardIterator>::value_type> ForwardIterator fill_n(ExecutionPolicy&& exec, ForwardIterator first, Size n, const T& value);template<class O, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<O> S, class T = iter_value_t<O>> requires [output_iterator](iterator.concept.output#concept:output%5Fiterator "24.3.4.10 Concept output_­iterator [iterator.concept.output]")<O, const T&> constexpr O ranges::fill(O first, S last, const T& value);template<class R, class T = range_value_t<R>> requires [output_range](range.refinements#concept:output%5Frange "25.4.5 Other range refinements [range.refinements]")<R, const T&> constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value);template<class O, class T = iter_value_t<O>> requires [output_iterator](iterator.concept.output#concept:output%5Fiterator "24.3.4.10 Concept output_­iterator [iterator.concept.output]")<O, const T&> constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value);

Let N be max(0, n) for the fill_n algorithms, andlast - first for the fill algorithms.

Effects: Assigns valuethrough all the iterators in the range [first, first + N).

Complexity: Exactly N assignments.

26.7.7 Generate [alg.generate]

template<class ForwardIterator, class Generator> constexpr void generate(ForwardIterator first, ForwardIterator last, Generator gen);template<class ExecutionPolicy, class ForwardIterator, class Generator> void generate(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Generator gen);template<class OutputIterator, class Size, class Generator> constexpr OutputIterator generate_n(OutputIterator first, Size n, Generator gen);template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator> ForwardIterator generate_n(ExecutionPolicy&& exec, ForwardIterator first, Size n, Generator gen);template<[input_or_output_iterator](iterator.concept.iterator#concept:input%5For%5Foutput%5Fiterator "24.3.4.6 Concept input_­or_­output_­iterator [iterator.concept.iterator]") O, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<O> S, [copy_constructible](concept.copyconstructible#concept:copy%5Fconstructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]") F> requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<O, invoke_result_t<F&>> constexpr O ranges::generate(O first, S last, F gen);template<class R, [copy_constructible](concept.copyconstructible#concept:copy%5Fconstructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]") F> requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [output_range](range.refinements#concept:output%5Frange "25.4.5 Other range refinements [range.refinements]")<R, invoke_result_t<F&>> constexpr borrowed_iterator_t<R> ranges::generate(R&& r, F gen);template<[input_or_output_iterator](iterator.concept.iterator#concept:input%5For%5Foutput%5Fiterator "24.3.4.6 Concept input_­or_­output_­iterator [iterator.concept.iterator]") O, [copy_constructible](concept.copyconstructible#concept:copy%5Fconstructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]") F> requires [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")<F&> && [indirectly_writable](iterator.concept.writable#concept:indirectly%5Fwritable "24.3.4.3 Concept indirectly_­writable [iterator.concept.writable]")<O, invoke_result_t<F&>> constexpr O ranges::generate_n(O first, iter_difference_t<O> n, F gen);

Let N be max(0, n) for the generate_n algorithms, andlast - first for the generate algorithms.

Effects: Assigns the result of successive evaluations of gen()through each iterator in the range [first, first + N).

Complexity: Exactly N evaluations of gen() and assignments.

26.7.8 Remove [alg.remove]

template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type> constexpr ForwardIterator remove(ForwardIterator first, ForwardIterator last,const T& value);template<class ExecutionPolicy, class ForwardIterator,class T = iterator_traits<ForwardIterator>::value_type> ForwardIterator remove(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,const T& value);template<class ForwardIterator, class Predicate> constexpr ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);template<class ExecutionPolicy, class ForwardIterator, class Predicate> ForwardIterator remove_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, class Proj = identity,class T = projected_value_t<I, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Fbinary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*> constexpr subrange<I> ranges::remove(I first, S last, const T& value, Proj proj = {});template<[forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R, class Proj = identity,class T = projected_value_t<iterator_t<R>, Proj>> requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> && [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Fbinary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*> constexpr borrowed_subrange_t<R> ranges::remove(R&& r, const T& value, Proj proj = {});template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, class Proj = identity,[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred> constexpr subrange<I> ranges::remove_if(I first, S last, Pred pred, Proj proj = {});template<[forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R, class Proj = identity,[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred> requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> constexpr borrowed_subrange_t<R> ranges::remove_if(R&& r, Pred pred, Proj proj = {});

Let E be

Preconditions: For the algorithms in namespace std, the type of *firstmeets the Cpp17MoveAssignable requirements (Table 33).

Effects: Eliminates all the elements referred to by iterator iin the range [first, last) for which E holds.

Returns: Let j be the end of the resulting range.

Returns:

Complexity: Exactly last - first applications of the corresponding predicate and any projection.

[Note 1:

Each element in the range [ret, last), where ret is the returned value, has a valid but unspecified state, because the algorithms can eliminate elements by moving from elements that were originally in that range.

— _end note_]

template<class InputIterator, class OutputIterator,class T = iterator_traits<InputIterator>::value_type> constexpr OutputIterator remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,class T = iterator_traits<ForwardIterator1>::value_type> ForwardIterator2 remove_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, const T& value);template<class InputIterator, class OutputIterator, class Predicate> constexpr OutputIterator remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,class Predicate> ForwardIterator2 remove_copy_if(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, Predicate pred);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O,class Proj = identity, class T = projected_value_t<I, Proj>> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> && [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Fbinary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, const T*> constexpr ranges::remove_copy_result<I, O> ranges::remove_copy(I first, S last, O result, const T& value, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, class Proj = identity,class T = projected_value_t<iterator_t<R>, Proj>> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> && [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Fbinary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*> constexpr ranges::remove_copy_result<borrowed_iterator_t<R>, O> ranges::remove_copy(R&& r, O result, const T& value, Proj proj = {});template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O,class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> Pred> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> constexpr ranges::remove_copy_if_result<I, O> ranges::remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, class Proj = identity,[indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect%5Funary%5Fpredicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Pred> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> constexpr ranges::remove_copy_if_result<borrowed_iterator_t<R>, O> ranges::remove_copy_if(R&& r, O result, Pred pred, Proj proj = {});

Let E be

Let N be the number of elements in [first, last) for which E is false.

Preconditions: The ranges [first, last) and [result, result + (last - first)) do not overlap.

[Note 2:

For the overloads with an ExecutionPolicy, there might be a performance cost if iterator_traits<ForwardIterator1>​::​value_type does not meet the Cpp17MoveConstructible (Table 31) requirements.

— _end note_]

Effects: Copies all the elements referred to by the iterator iin the range [first, last) for which E is false.

Returns:

Complexity: Exactly last - first applications of the corresponding predicate and any projection.

26.7.9 Unique [alg.unique]

template<class ForwardIterator> constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last);template<class ExecutionPolicy, class ForwardIterator> ForwardIterator unique(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last);template<class ForwardIterator, class BinaryPredicate> constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate> ForwardIterator unique(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, BinaryPredicate pred);template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, class Proj = identity,[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect%5Fequivalence%5Frelation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to> constexpr subrange<I> ranges::unique(I first, S last, C comp = {}, Proj proj = {});template<[forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R, class Proj = identity,[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect%5Fequivalence%5Frelation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> C = ranges::equal_to> requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> constexpr borrowed_subrange_t<R> ranges::unique(R&& r, C comp = {}, Proj proj = {});

Let pred be equal_to{}for the overloads with no parameter pred, and let E be

Preconditions: For the overloads in namespace std,pred is an equivalence relation and the type of *first meets the Cpp17MoveAssignable requirements (Table 33).

Effects: For a nonempty range, eliminates all but the first element from every consecutive group of equivalent elements referred to by the iterator i in the range [first + 1, last) for which E is true.

Returns: Let j be the end of the resulting range.

Returns:

Complexity: For nonempty ranges, exactly (last - first) - 1 applications of the corresponding predicate and no more than twice as many applications of any projection.

template<class InputIterator, class OutputIterator> constexpr OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 unique_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result);template<class InputIterator, class OutputIterator,class BinaryPredicate> constexpr OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,class BinaryPredicate> ForwardIterator2 unique_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryPredicate pred);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, class Proj = identity,[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect%5Fequivalence%5Frelation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<I, Proj>> C = ranges::equal_to> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> && ([forward_iterator](iterator.concept.forward#concept:forward%5Fiterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]")<I> || ([input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]")<O> && [same_as](concept.same#concept:same%5Fas "18.4.2 Concept same_­as [concept.same]")<iter_value_t<I>, iter_value_t<O>>) || [indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly%5Fcopyable%5Fstorable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O>) constexpr ranges::unique_copy_result<I, O> ranges::unique_copy(I first, S last, O result, C comp = {}, Proj proj = {});template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, class Proj = identity,[indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect%5Fequivalence%5Frelation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> C = ranges::equal_to> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> && ([forward_iterator](iterator.concept.forward#concept:forward%5Fiterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]")<iterator_t<R>> || ([input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]")<O> && [same_as](concept.same#concept:same%5Fas "18.4.2 Concept same_­as [concept.same]")<range_value_t<R>, iter_value_t<O>>) || [indirectly_copyable_storable](alg.req.ind.copy#concept:indirectly%5Fcopyable%5Fstorable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O>) constexpr ranges::unique_copy_result<borrowed_iterator_t<R>, O> ranges::unique_copy(R&& r, O result, C comp = {}, Proj proj = {});

Let pred be equal_to{} for the overloads in namespace std with no parameter pred, and let E be

Preconditions:

Effects: Copies only the first element from every consecutive group of equal elements referred to by the iterator i in the range [first, last) for which E holds.

Returns:

Complexity: Exactly last - first - 1 applications of the corresponding predicate and no more than twice as many applications of any projection.

26.7.10 Reverse [alg.reverse]

template<class BidirectionalIterator> constexpr void reverse(BidirectionalIterator first, BidirectionalIterator last);template<class ExecutionPolicy, class BidirectionalIterator> void reverse(ExecutionPolicy&& exec, BidirectionalIterator first, BidirectionalIterator last);template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional%5Fiterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S> requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<I> constexpr I ranges::reverse(I first, S last);template<[bidirectional_range](range.refinements#concept:bidirectional%5Frange "25.4.5 Other range refinements [range.refinements]") R> requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> constexpr borrowed_iterator_t<R> ranges::reverse(R&& r);

Effects: For each non-negative integer i < (last - first) / 2, applies std​::​iter_swap, orranges​::​​iter_swap for the overloads in namespace ranges, to all pairs of iterators first + i, (last - i) - 1.

Returns: last for the overloads in namespace ranges.

Complexity: Exactly (last - first)/2 swaps.

template<class BidirectionalIterator, class OutputIterator> constexpr OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator> ForwardIterator reverse_copy(ExecutionPolicy&& exec, BidirectionalIterator first, BidirectionalIterator last, ForwardIterator result);template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional%5Fiterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> constexpr ranges::reverse_copy_result<I, O> ranges::reverse_copy(I first, S last, O result);template<[bidirectional_range](range.refinements#concept:bidirectional%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O> ranges::reverse_copy(R&& r, O result);

Preconditions: The ranges [first, last) and [result, result + N) do not overlap.

Effects: Copies the range [first, last) to the range [result, result + N) such that for every non-negative integer i < Nthe following assignment takes place:*(result + N - 1 - i) = *(first + i).

Returns:

Complexity: Exactly N assignments.

26.7.11 Rotate [alg.rotate]

template<class ForwardIterator> constexpr ForwardIterator rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);template<class ExecutionPolicy, class ForwardIterator> ForwardIterator rotate(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator middle, ForwardIterator last);template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S> constexpr subrange<I> ranges::rotate(I first, I middle, S last);

Preconditions: [first, middle) and [middle, last) are valid ranges.

Effects: For each non-negative integer i < (last - first), places the element from the position first + iinto position first + (i + (last - middle)) % (last - first).

[Note 1:

This is a left rotate.

— _end note_]

Returns:

Complexity: At most last - first swaps.

template<[forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R> requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> constexpr borrowed_subrange_t<R> ranges::rotate(R&& r, iterator_t<R> middle);

Effects: Equivalent to:return ranges​::​rotate(ranges​::​begin(r), middle, ranges​::​end(r));

template<class ForwardIterator, class OutputIterator> constexpr OutputIterator rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 rotate_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last, ForwardIterator2 result);template<[forward_iterator](iterator.concept.forward#concept:forward%5Fiterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O> requires [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> constexpr ranges::rotate_copy_result<I, O> ranges::rotate_copy(I first, I middle, S last, O result);

Preconditions: [first, middle) and [middle, last) are valid ranges.

The ranges [first, last) and [result, result + N) do not overlap.

Effects: Copies the range [first, last) to the range [result, result + N) such that for each non-negative integer the following assignment takes place:*(result + i) = *(first + (i + (middle - first)) % N).

Returns:

Complexity: Exactly N assignments.

Effects: Equivalent to:return ranges::rotate_copy(ranges::begin(r), middle, ranges::end(r), std::move(result));

26.7.12 Sample [alg.random.sample]

template<class PopulationIterator, class SampleIterator,class Distance, class UniformRandomBitGenerator> SampleIterator sample(PopulationIterator first, PopulationIterator last, SampleIterator out, Distance n, UniformRandomBitGenerator&& g);template<[input_iterator](iterator.concept.input#concept:input%5Fiterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, class Gen> requires ([forward_iterator](iterator.concept.forward#concept:forward%5Fiterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]")<I> || [random_access_iterator](iterator.concept.random.access#concept:random%5Faccess%5Fiterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<O>) && [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<I, O> && [uniform_random_bit_generator](rand.req.urng#concept:uniform%5Frandom%5Fbit%5Fgenerator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_reference_t<Gen>> O ranges::sample(I first, S last, O out, iter_difference_t<I> n, Gen&& g);template<[input_range](range.refinements#concept:input%5Frange "25.4.5 Other range refinements [range.refinements]") R, [weakly_incrementable](iterator.concept.winc#concept:weakly%5Fincrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]") O, class Gen> requires ([forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]")<R> || [random_access_iterator](iterator.concept.random.access#concept:random%5Faccess%5Fiterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<O>) && [indirectly_copyable](alg.req.ind.copy#concept:indirectly%5Fcopyable "24.3.7.3 Concept indirectly_­copyable [alg.req.ind.copy]")<iterator_t<R>, O> && [uniform_random_bit_generator](rand.req.urng#concept:uniform%5Frandom%5Fbit%5Fgenerator "29.5.3.3 Uniform random bit generator requirements [rand.req.urng]")<remove_reference_t<Gen>> O ranges::sample(R&& r, O out, range_difference_t<R> n, Gen&& g);

Preconditions: out is not in the range [first, last).

For the overload in namespace std:

Effects: Copies min(last - first, n) elements (the sample) from [first, last) (the population) to outsuch that each possible sample has equal probability of appearance.

[Note 1:

Algorithms that obtain such effects include selection samplingand reservoir sampling.

— _end note_]

Returns: The end of the resulting sample range.

Remarks:

26.7.13 Shuffle [alg.random.shuffle]

Preconditions: For the overload in namespace std:

Effects: Permutes the elements in the range [first, last) such that each possible permutation of those elements has equal probability of appearance.

Returns: last for the overloads in namespace ranges.

Complexity: Exactly (last - first) - 1 swaps.

Remarks: To the extent that the implementation of this function makes use of random numbers, the object referenced by g shall serve as the implementation's source of randomness.

26.7.14 Shift [alg.shift]

template<class ForwardIterator> constexpr ForwardIterator shift_left(ForwardIterator first, ForwardIterator last,typename iterator_traits<ForwardIterator>::difference_type n);template<class ExecutionPolicy, class ForwardIterator> ForwardIterator shift_left(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,typename iterator_traits<ForwardIterator>::difference_type n);template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S> constexpr subrange<I> ranges::shift_left(I first, S last, iter_difference_t<I> n);template<[forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R> requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> constexpr borrowed_subrange_t<R> ranges::shift_left(R&& r, range_difference_t<R> n)

Preconditions: n >= 0 is true.

For the overloads in namespace std, the type of *first meets the Cpp17MoveAssignable requirements.

Effects: If n == 0 or n >= last - first, does nothing.

Otherwise, moves the element from position first + n + iinto position first + ifor each non-negative integer i < (last - first) - n.

For the overloads without an ExecutionPolicy template parameter, does so in order starting from i = 0 and proceeding to i = (last - first) - n - 1.

Returns: Let NEW_LAST be first + (last - first - n)if n < last - first, otherwise first.

Complexity: At most (last - first) - n assignments.

template<class ForwardIterator> constexpr ForwardIterator shift_right(ForwardIterator first, ForwardIterator last,typename iterator_traits<ForwardIterator>::difference_type n);template<class ExecutionPolicy, class ForwardIterator> ForwardIterator shift_right(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,typename iterator_traits<ForwardIterator>::difference_type n);template<[permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> S> constexpr subrange<I> ranges::shift_right(I first, S last, iter_difference_t<I> n);template<[forward_range](range.refinements#concept:forward%5Frange "25.4.5 Other range refinements [range.refinements]") R> requires [permutable](alg.req.permutable#concept:permutable "24.3.7.6 Concept permutable [alg.req.permutable]")<iterator_t<R>> constexpr borrowed_subrange_t<R> ranges::shift_right(R&& r, range_difference_t<R> n);

Preconditions: n >= 0 is true.

Effects: If n == 0 or n >= last - first, does nothing.

Otherwise, moves the element from position first + i into position first + n + ifor each non-negative integer i < (last - first) - n.

Does so in order starting from i = (last - first) - n - 1 and proceeding to i = 0 if

Returns: Let NEW_FIRST be first + n if n < last - first, otherwise last.

Complexity: At most (last - first) - n assignments or swaps.