Namespaces
Variants
Actions

std::uninitialized_move_n

From cppreference.com
< cpp‎ | memory
 
 
Memory management library
(exposition only*)
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
(until C++20*)
(until C++20*)

Garbage collector support (until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
 
Defined in header <memory>
template< class InputIt, class Size, class NoThrowForwardIt >

std::pair<InputIt, NoThrowForwardIt>
    uninitialized_move_n( InputIt first, Size count,

                          NoThrowForwardIt d_first );
(1) (since C++17)
(constexpr since C++26)
template< class ExecutionPolicy,

          class ForwardIt, class Size, class NoThrowForwardIt >
std::pair<ForwardIt, NoThrowForwardIt>
    uninitialized_move_n( ExecutionPolicy&& policy, ForwardIt first,

                          Size count, NoThrowForwardIt d_first );
(2) (since C++17)
1) Copies the elements from first + [0count) (using move semantics if supported) to an uninitialized memory area beginning at d_first as if by

for (; count > 0; ++d_first, (void) ++first, --count)
    ::new (voidify(*d_first))
        typename std::iterator_traits<NoThrowForwardIt>::value_type(/* value */);
return {first, d_first};

where /* value */ is std::move(*first) if *first is of an lvalue reference type, or *first otherwise.
If an exception is thrown during the initialization, some objects in first + [0count) are left in a valid but unspecified state, and the objects already constructed are destroyed in an unspecified order.
2) Same as (1), but executed according to policy.
This overload participates in overload resolution only if all following conditions are satisfied:

std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> is true.

(until C++20)

std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>> is true.

(since C++20)


If d_first + [0count) overlaps with first + [0count), the behavior is undefined.

(since C++20)

Contents

[edit] Parameters

first - the beginning of the range of the elements to move
d_first - the beginning of the destination range
count - the number of elements to move
policy - the execution policy to use
Type requirements
-
InputIt must meet the requirements of LegacyInputIterator.
-
ForwardIt must meet the requirements of LegacyForwardIterator.
-
NoThrowForwardIt must meet the requirements of LegacyForwardIterator.
-
No increment, assignment, comparison, or indirection through valid instances of NoThrowForwardIt may throw exceptions.

[edit] Return value

As described above.

[edit] Complexity

Linear in count.

[