Files
cppdraft_translate/cppdraft/alg/move.md
2025-10-25 03:02:53 +03:00

9.9 KiB
Raw Blame History

[alg.move]

26 Algorithms library [algorithms]

26.7 Mutating sequence operations [alg.modifying.operations]

26.7.2 Move [alg.move]

🔗

`template<class InputIterator, class OutputIterator> constexpr OutputIterator move(InputIterator first, InputIterator last, OutputIterator result);

template<input_iterator I, sentinel_for S, weakly_incrementable O> requires indirectly_movable<I, O> constexpr ranges::move_result<I, O> ranges::move(I first, S last, O result); template<input_range R, weakly_incrementable O> requires indirectly_movable<iterator_t, O> constexpr ranges::move_result<borrowed_iterator_t, O> ranges::move(R&& r, O result); `

1

#

Let E(n) be

std::move(*(first + n)) for the overload in namespace std;

ranges::iter_move(first + n) for the overloads in namespace ranges.

Let N be last - first.

2

#

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

3

#

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 n<N, performs *(result + n) = E(n).

4

#

Returns:

  • (4.1)

    result + N for the overload in namespace std.

  • (4.2)

    {last, result + N} for the overloads in namespace ranges.

5

#

Complexity: Exactly N assignments.

🔗

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

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, random_access_iterator O, sized_sentinel_for OutS> requires indirectly_movable<I, O> ranges::move_result<I, O> ranges::move(Ep&& exec, I first, S last, O result, OutS result_last); template<execution-policy Ep, sized-random-access-range R, sized-random-access-range OutR> requires indirectly_movable<iterator_t, iterator_t> ranges::move_result<borrowed_iterator_t, borrowed_iterator_t> ranges::move(Ep&& exec, R&& r, OutR&& result_r); `

6

#

Let E(n) be:

std::move(*(first + n)) for the overload in namespace std;

ranges::iter_move(first + n) for the overloads in namespace ranges.

7

#

Let result_last be result + (last - first) for the overloads in namespace std.

8

#

Let N be min(last - first, result_last - result).

9

#

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

10

#

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

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

11

#

Returns:

  • (11.1)

    result + N for the overload in namespace std.

  • (11.2)

    {first + N, result + N} for the overloads in namespace ranges.

12

#

Complexity: Exactly N assignments.

🔗

`template<class BidirectionalIterator1, class BidirectionalIterator2> constexpr BidirectionalIterator2 move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result);

template<bidirectional_iterator I1, sentinel_for S1, bidirectional_iterator I2> requires indirectly_movable<I1, I2> constexpr ranges::move_backward_result<I1, I2> ranges::move_backward(I1 first, S1 last, I2 result); template<bidirectional_range R, bidirectional_iterator I> requires indirectly_movable<iterator_t, I> constexpr ranges::move_backward_result<borrowed_iterator_t, I> ranges::move_backward(R&& r, I result); `

13

#

Let E(n) be

std::move(*(last - n)) for the overload in namespace std;

ranges::iter_move(last - n) for the overloads in namespace ranges.

Let N be last - first.

14

#

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

15

#

Effects: Moves 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) = E(n).

16

#

Returns:

  • (16.1)

    result - N for the overload in namespace std.

  • (16.2)

    {last, result - N} for the overloads in namespace ranges.

17

#

Complexity: Exactly N assignments.

202)202)

move_backward can be used instead of move when last is in the range [result - N, result).