From cppreference.com
Defined in header
T is not a specialization of
template<classT,classAlloc,class...Args>constexprautouses_allocator_construction_args(constAlloc&alloc,Args&&...args)noexcept; (1) (since C++20)T is a specialization of
template<classT,classAlloc,classTuple1,classTuple2>constexprautouses_allocator_construction_args(constAlloc&alloc,std::piecewise_construct_t,Tuple1&&x,Tuple2&&y)noexcept; (2) (since C++20)template<classT,classAlloc>constexprautouses_allocator_construction_args(constAlloc&alloc)noexcept; (3) (since C++20)template<classT,classAlloc,classU,classV>constexprautouses_allocator_construction_args(constAlloc&alloc,U&&u,V&&v)noexcept; (4) (since C++20)template<classT,classAlloc,classU,classV>constexprautouses_allocator_construction_args(constAlloc&alloc,std::pair<U,V>&pr)noexcept; (5) (since C++23)template<classT,classAlloc,classU,classV>constexprautouses_allocator_construction_args(constAlloc&alloc,conststd::pair<U,V>&pr)noexcept; (6) (since C++20)template<classT,classAlloc,classU,classV>constexprautouses_allocator_construction_args(constAlloc&alloc,std::pair<U,V>&&pr)noexcept; (7) (since C++20)template<classT,classAlloc,classU,classV>constexprautouses_allocator_construction_args(constAlloc&alloc,conststd::pair<U,V>&&pr)noexcept; (8) (since C++23)template<classT,classAlloc,classNonPair>constexprautouses_allocator_construction_args(constAlloc&alloc,NonPair&&non_pair)noexcept; (9) (since C++20)Prepares the argument list needed to create an object of the given type T by means of
.
1) This overload participates in overload resolution only if T is not a specialization of
. Returns
determined as follows:
If std::uses_allocator_v<T,Alloc> is false and std::is_constructible_v<T,Args...> is true, returns std::forward_as_tuple(std::forward<Args>(args)...).
Otherwise, if std::uses_allocator_v<T,Alloc> is true and std::is_constructible_v<T,std::allocator_arg_t,constAlloc&,Args...> is true, returns
std::tuple<std::allocator_arg_t,constAlloc&,Args&&...>(std::allocator_arg,alloc,
std::forward<Args>(args)...).
Otherwise, if std::uses_allocator_v<T,Alloc> is true and std::is_constructible_v<T,Args...,constAlloc&> is true, returns std::forward_as_tuple(std::forward<Args>(args)...,alloc).
Otherwise, the program is ill-formed.
2) This overload participates in overload resolution only if T is a specialization of
. For T that is std::pair<T1,T2>, equivalent to
returnstd::make_tuple(std::piecewise_construct,std::apply([&alloc](auto&&...args1){returnstd::uses_allocator_construction_args<T1>(alloc,std::forward<decltype(args1)>(args1)...);},std::forward<Tuple1>(x)),std::apply([&alloc](auto&&...args2){returnstd::uses_allocator_construction_args<T2>(alloc,std::forward<decltype(args2)>(args2)...);},std::forward<Tuple2>(y)));3) This overload participates in overload resolution only if T is a specialization of
. Equivalent to
returnstd::uses_allocator_construction_args<T>(alloc,std::piecewise_construct,std::tuple<>{},std::tuple<>{});4) This overload participates in overload resolution only if T is a specialization of
. Equivalent to
returnstd::uses_allocator_construction_args<T>(alloc,std::piecewise_construct,std::forward_as_tuple(std::forward<U>(u)),std::forward_as_tuple(std::forward<V>(v)));5,6) This overload participates in overload resolution only if T is a specialization of
. Equivalent to
returnstd::uses_allocator_construction_args<T>(alloc,std::piecewise_construct,std::forward_as_tuple(pr.first),std::forward_as_tuple(pr.second));7,8) This overload participates in overload resolution only if T is a specialization of
. Equivalent to
returnstd::uses_allocator_construction_args<T>(alloc,std::piecewise_construct,std::forward_as_tuple(std::get<0>(std::move(pr))),std::forward_as_tuple(std::get<1>(std::move(pr))));9) This overload participates in overload resolution only if T is a specialization of
, and given the exposition-only function template
template<classA,classB>void/*deduce-as-pair*/(conststd::pair<A,B>&);, /*deduce-as-pair*/(non_pair) is ill-formed when considered as an unevaluated operand.
Let the exposition-only class pair-constructor be defined as
class/*pair-constructor*/{constAlloc&alloc_;// exposition onlyNonPair&u_;// exposition onlyconstexprreconstruct(conststd::remove_cv<T>&p)const// exposition only{returnstd::make_obj_using_allocator<std::remove_cv<T>>(alloc_,p);}constexprreconstruct(std::remove_cv<T>&&p)const// exposition only{returnstd::make_obj_using_allocator<std::remove_cv<T>>(alloc_,std::move(p));}public:constexproperatorstd::remove_cv<T>()const{returnreconstruct(std::forward<NonPair>(u_));}};This overload is equivalent to returnstd::make_tuple(pair_construction);, where pair_construction is a value of type pair-constructor whose alloc_ and u_ members are alloc and non_pair respectively.
Parameters
alloc - the allocator to use args - the arguments to pass to T's constructor x - tuple of arguments to pass to the constructors of T's first data member y - tuple of arguments to pass to the constructors of T's second data member u - single argument to pass to the constructor of T's first data member v - single argument to pass to the constructor of T's second data member pr - a pair whose first data member will be passed to the constructor of T's first data member and second data member will be passed to the constructor of T's second data member non_pair - single argument to convert to a
for further construction Return value
of arguments suitable for passing to the constructor of T.
Notes
The overloads (2-9) provide allocator propagation into
, which supports neither leading-allocator nor trailing-allocator calling conventions (unlike, e.g.
, which uses leading-allocator convention).
When used in uses-allocator construction, the conversion function of pair-constructor converts the provided argument to
at first, and then constructs the result from that
by uses-allocator construction.
Example
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++20 no overload could handle non-pair types convertible to pairreconstructing overload added See also