A RetroSearch Logo

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

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../error/../symbol_index/../algorithm/ranges/move.html below:

std::ranges::move, std::ranges::move_result - cppreference.com

Call signature

(1) (since C++20) (2) (since C++20)

Helper types

(3) (since C++20) 1)

Moves the elements in the range, defined by

[firstlast)

, to another range beginning at

result

. The behavior is undefined if

result

is within the range

[firstlast)

. In such a case,

ranges::move_backward

may be used instead.

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.

The function-like entities described on this page are algorithm function objects (informally known as niebloids), that is:

[edit] Parameters first, last - the iterator-sentinel pair defining the range of elements to move r - the range of the elements to move result - the beginning of the destination range [edit] Return value

{last, result + N}, where

[edit] Complexity

Exactly N move assignments.

[edit] Notes

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

[edit] Possible implementation
struct move_fn
{
    template<std::input_iterator I, std::sentinel_for<I> S, std::weakly_incrementable O>
    requires std::indirectly_movable<I, O>
    constexpr ranges::move_result<I, O>
        operator()(I first, S last, O result) const
    {
        for (; first != last; ++first, ++result)
            *result = ranges::iter_move(first);
        return {std::move(first), std::move(result)};
    }
    template<ranges::input_range R, std::weakly_incrementable O>
    requires std::indirectly_movable<ranges::iterator_t<R>, O>
    constexpr ranges::move_result<ranges::borrowed_iterator_t<R>, O>
        operator()(R&& r, O result) const
    {
        return (*this)(ranges::begin(r), ranges::end(r), std::move(result));
    }
};
 
inline constexpr move_fn move {};
[edit] Example

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

Output:

thread with n=400ms ended
thread with n=600ms ended
thread with n=800ms ended
[edit] See also

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