A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../error/error_code/../../utility/../algorithm/move.html below:

std::move - cppreference.com

template< class InputIt, class OutputIt >

OutputIt move( InputIt first, InputIt last,

               OutputIt d_first );
(1) (since C++11)
(constexpr since C++20) template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2 >

ForwardIt2 move( ExecutionPolicy&& policy,
                 ForwardIt1 first, ForwardIt1 last,

                 ForwardIt2 d_first );
(2) (since C++17)

1) Moves the elements in the range [firstlast), to another range beginning at d_first, starting from first and proceeding to last. After this operation the elements in the moved-from range will still contain valid values of the appropriate type, but not necessarily the same values as before the move.

2) Same as (1), but executed according to policy.

This overload participates in overload resolution only if all following conditions are satisfied:

If d_first is within the range [firstlast), the behavior is undefined. In this case, std::move_backward may be used instead.

[edit] Parameters [edit] Return value

The iterator to the element past the last element moved.

[edit] Complexity

Exactly std::distance(first, last) move assignments.

[edit] Exceptions

The overload with a template parameter named ExecutionPolicy reports errors as follows:

[edit] Possible implementation
template<class InputIt, class OutputIt>
OutputIt move(InputIt first, InputIt last, OutputIt d_first)
{
    for (; first != last; ++d_first, ++first)
        *d_first = std::move(*first);
 
    return d_first;
}
[edit] Notes

When moving overlapping ranges, std::move is appropriate when moving to the left (beginning of the destination range is outside the source range) while std::move_backward is appropriate when moving to the right (end of the destination range is outside the source range).

[edit] Example

The following code moves thread objects (which themselves are not copyable) from one container to another.

Output:

thread 1 ended
thread 2 ended
thread 3 ended
[edit] See also moves a range of elements to a new location in backwards order
(function template) [edit] converts the argument to an xvalue
(function template) [edit] moves a range of elements to a new location
(algorithm function object)[edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4