std::uses_allocator_construction_args

From cppreference.com
< cpp‎ | memory
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
Dynamic memory management
Uninitialized memory algorithms
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++20)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++20)

Constrained uninitialized memory algorithms
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Allocators
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
uses_allocator_construction_args
(哋它亢++20)
Garbage collection support
(哋它亢++11)(until 哋它亢++23)
(哋它亢++11)(until 哋它亢++23)
(哋它亢++11)(until 哋它亢++23)
(哋它亢++11)(until 哋它亢++23)
(哋它亢++11)(until 哋它亢++23)
(哋它亢++11)(until 哋它亢++23)



Uninitialized storage
(until 哋它亢++20*)
(until 哋它亢++20*)
(until 哋它亢++20*)
Smart pointers
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(until 哋它亢++17*)
(哋它亢++11)
(哋它亢++17)
(哋它亢++26)
(哋它亢++26)
(哋它亢++11)
(哋它亢++11)
(哋它亢++23)
(哋它亢++23)
Low level memory
management
(哋它亢++17)
Miscellaneous
(哋它亢++11)
(哋它亢++20)
(哋它亢++11)
(哋它亢++11)
(哋它亢++20)
C Library
(哋它亢++17)

 
Defined in header <memory>
T is not a specialization of std::pair
template< class T, class Alloc, class... Args >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    Args&&... args ) noexcept;
(1) (since 哋它亢++20)
T is a specialization of std::pair
template< class T, class Alloc, class Tuple1, class Tuple2 >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    std::piecewise_construct_t, Tuple1&& x, Tuple2&& y ) noexcept;
(2) (since 哋它亢++20)
template< class T, class Alloc >
constexpr auto uses_allocator_construction_args( const Alloc& alloc ) noexcept;
(3) (since 哋它亢++20)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    U&& u, V&& v ) noexcept;
(4) (since 哋它亢++20)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    std::pair<U, V>& pr ) noexcept;
(5) (since 哋它亢++23)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    const std::pair<U, V>& pr ) noexcept;
(6) (since 哋它亢++20)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    std::pair<U, V>&& pr ) noexcept;
(7) (since 哋它亢++20)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    const std::pair<U, V>&& pr ) noexcept;
(8) (since 哋它亢++23)
template< class T, class Alloc, class NonPair >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    NonPair&& non_pair ) noexcept;
(9) (since 哋它亢++20)

Prepares the argument list needed to create an object of the given type T by means of uses-allocator construction.

1) This overload participates in overload resolution only if T is not a specialization of std::pair. Returns std::tuple determined as follows:
2) This overload participates in overload resolution only if T is a specialization of std::pair. For T that is std::pair<T1, T2>, equivalent to
return std::make_tuple(std::piecewise_construct,
    std::apply([&alloc](auto&&... args1)
        {
            return std::uses_allocator_construction_args<T1>(alloc,
                       std::forward<decltype(args1)>(args1)...);
        }, std::forward<Tuple1>(x)
    ),
    std::apply([&alloc](auto&&... args2)
        {
            return std::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 std::pair. Equivalent to
return std::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 std::pair. Equivalent to
return std::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 std::pair. Equivalent to
return std::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 std::pair. Equivalent to
return std::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 std::pair, and given the exposition-only function template
template<class A, class B>
void /*deduce-as-pair*/(const std::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*/
{
    const Alloc& alloc_; // exposition only
    NonPair&     u_;     // exposition only
 
    constexpr reconstruct(const std::remove_cv<T>& p) const // exposition only
    {
        return std::make_obj_using_allocator<std::remove_cv<T>>(alloc_, p);
    }
 
    constexpr reconstruct(std::remove_cv<T>&& p) const // exposition only
    {
        return std::make_obj_using_allocator<std::remove_cv<T>>(alloc_, std::move(p));
    }
 
public:
    constexpr operator std::remove_cv<T>() const
    {
        return reconstruct(std::forward<NonPair>(u_));
    }
};
This overload is equivalent to return std::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 std::pair for further construction

Return value

std::tuple of arguments suitable for passing to the constructor of T.

Notes

The overloads (2-9) provide allocator propagation into std::pair, which supports neither leading-allocator nor trailing-allocator calling conventions (unlike, e.g. std::tuple, which uses leading-allocator convention).

When used in uses-allocator construction, the conversion function of pair-constructor converts the provided argument to std::pair at first, and then constructs the result from that std::pair by uses-allocator construction.

Example

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published 哋它亢++ standards.

DR Applied to Behavior as published Correct behavior
LWG 3525 哋它亢++20 no overload could handle non-pair types convertible to pair reconstructing overload added

See also

(哋它亢++11)
checks if the specified type supports uses-allocator construction
(class template)
creates an object of the given type by means of uses-allocator construction
(function template)
creates an object of the given type at specified memory location by means of uses-allocator construction
(function template)