Namespaces
Variants
Actions

std::ranges::uninitialized_value_construct

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>
Call signature
template< no-throw-forward-iterator I, no-throw-sentinel-for<I> S >

    requires std::default_initializable<std::iter_value_t<I>>

I uninitialized_value_construct( I first, S last );
(1) (since C++20)
(constexpr since C++26)
template< no-throw-forward-range R >

    requires std::default_initializable<ranges::range_value_t<R>>
ranges::borrowed_iterator_t<R>

    uninitialized_value_construct( R&& r );
(2) (since C++20)
(constexpr since C++26)
1) Constructs objects of type std::iter_value_t<I> in the uninitialized memory area [firstlast) by value-initialization, as if by

for (; first != last; ++first)
    ::new (voidify(*first))
        std::remove_reference_t<std::iter_reference_t<I>>();
return first;

If an exception is thrown during the initialization, the objects already constructed are destroyed in an unspecified order.
2) Equivalent to ranges::uninitialized_value_construct(ranges::begin(r), ranges::end(r)).

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

Contents

[edit] Parameters

first, last - the iterator-sentinel pair defining the range of elements to value-initialize
r - the range of the elements to value-initialize

[edit] Return value

As described above.

[edit] Complexity

Linear in the distance between first and last.

[edit] Exceptions

Any exception thrown on construction of the elements in the destination range.

[edit] Notes

An implementation may improve the efficiency of the ranges::uninitialized_value_construct, e.g. by using ranges::fill, if the value type of the range is a CopyAssignable TrivialType.