From cppreference.com
Defined in header
template<classT,class...Args>voidconstruct(T*p,Args&&...args); (1) template<classT1,classT2,class...Args1,class...Args2>voidconstruct(std::pair<T1,T2>*p,std::piecewise_construct_t,std::tuple<Args1...>x,std::tuple<Args2...>y); (2) (until C++20)template<classT1,classT2>voidconstruct(std::pair<T1,T2>*p); (3) (until C++20)template<classT1,classT2,classU,classV>voidconstruct(std::pair<T1,T2>*p,U&&x,V&&y); (4) (until C++20)template<classT1,classT2,classU,classV>voidconstruct(std::pair<T1,T2>*p,conststd::pair<U,V>&xy); (5) (until C++20)template<classT1,classT2,classU,classV>voidconstruct(std::pair<T1,T2>*p,std::pair<U,V>&&xy); (6) (until C++20)Helper function templates
template<classT,class...Args>std::tuple</* see below */>/*concat-args*/(std::tuple<Args...>&&tup); (7)(until C++20)
(exposition only*)Constructs an object in allocated, but not initialized storage pointed to by p using the outer allocator and the provided constructor arguments. If the object is of a type that itself uses allocators, or if it is
(until C++20), passes the inner allocator down to the constructed object.
1) Constructs an object of type T by
at the uninitialized memory location indicated by p using the outermost allocator.
Given std::uses_allocator<T,inner_allocator_type>::value as uses_inner:
If uses_inner is false and std::is_constructible<T,Args...>::value is true, calls
(p,std::forward<Args>(args)...).
Otherwise, if uses_inner and std::is_constructible<T,std::allocator_arg_t,
inner_allocator_type&,
Args...>::value are both true, calls
(p,std::allocator_arg,
inner_allocator(),
std::forward<Args>(args)...).
Otherwise, if uses_inner and std::is_constructible<T,Args...,inner_allocator_type&>::value are both true, calls
(p,std::forward<Args>(args)...,inner_allocator()).
Otherwise, the program is ill-formed.
This overload participates in overload resolution only if T is not a specialization of
.
(until C++20)Equivalent to std::apply
(
[p,this](auto&&...newargs)
{
(p,std::forward<decltype(newargs)>(newargs)...);
},
std::uses_allocator_construction_args
(inner_allocator(),std::forward<Args>(args)...)
);.
(since C++20)2-6) Constructs a
object by
at the uninitialized memory location indicated by p using the outermost allocator.
2) Let xprime be concat-args<T1>(std::move(x)), yprime be concat-args<T2>(std::move(y)), calls
(p,std::piecewise_construct,std::move(xprime),std::move(yprime)).
3) Equivalent to construct(p,std::piecewise_construct,std::tuple<>(),std::tuple<>());.
4-6) Equivalent to construct(p,std::piecewise_construct,
std::forward_as_tuple(xarg),std::forward_as_tuple(yarg));, where xarg and yarg are defined as follows:
Overload xargyarg(4)std::forward<U>(x)std::forward<V>(y)(5)xy.firstxy.second(6)std::forward<U>(xy.first)std::forward<V>(xy.second)7) Merges the arguments contained in tup and additional arguments required by
of an object of type T.
Given std::uses_allocator<T,inner_allocator_type>::value as uses_inner:
If uses_inner is false and std::is_constructible<T,Args...>::value is true, returns std::tuple<Args&&...>(std::move(tup)).
Otherwise, if uses_inner and std::is_constructible<T,std::allocator_arg_t,
inner_allocator_type&,
Args...>::value are both true, returns std::tuple_cat(std::tuple<std::allocator_arg_t,inner_allocator_type&>
(std::allocator_arg,inner_allocator()),
std::tuple<Args&&...>(std::move(tup))).
Otherwise, if uses_inner and std::is_constructible<T,Args...,inner_allocator_type&>::value are both true, returns std::tuple_cat(std::tuple<Args&&...>(std::move(tup)),
std::tuple<inner_allocator_type&>(inner_allocator()).
Otherwise, the program is ill-formed.
Parameters
p - pointer to allocated, but not initialized storage args - the constructor arguments to pass to the constructor of Tx - the constructor arguments to pass to the constructor of T1y - the constructor arguments to pass to the constructor of T2xy - the pair whose two members are the constructor arguments for T1 and T2tup - the arguments to be merged Notes
This function is called (through
) by any allocator-aware object, such as
, that was given a
as the allocator to use. Since inner_allocator_type is itself a specialization of
, this function will also be called when the allocator-aware objects constructed through this function start constructing their own members.
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++11 inner allocators were obtained by value-initializing
an inner_allocator_type object obtained by calling
(
) C++11 concat-args might copy elements of
s eliminated all element copy operations
C++11 only constructions from
inner_allocator_type rvalues were checked checks constructions from non-const
inner_allocator_type lvalues instead
C++11 overload (1) was not constrained constrained to refuse
See also
[static]
constructs an object in the allocated storage
(function template)
(until C++20)
constructs an object in allocated storage
(public member function of std::allocator<T>)