Namespaces
Variants
Views
Actions

std::scoped_allocator_adaptor<OuterAlloc,InnerAlloc...>::construct

From cppreference.com

Template:cpp/memory/scoped allocator adaptor/sidebar Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <scoped_allocator>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
template < class T, class... Args >
void construct( T* p, Args&&... args )
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class T1, class T2, class... Args1, class... Args2 >

void construct( std::pair<T1, T2>* p,
                std::piecewise_construct_t,
                std::tuple<Args1...> x,

                std::tuple<Args2...> y )
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class T1, class T2 >
void construct( std::pair<T1, T2>* p )
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class T1, class T2, class U, class V >
void construct( std::pair<T1, T2>* p, U&& x, V&& y )
</td>

<td > (4) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class T1, class T2, class U, class V >
void construct( std::pair<T1, T2>* p, const std::pair<U, V>& xy )
</td>

<td > (5) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class T1, class T2, class U, class V >
void construct( std::pair<T1, T2>* p, std::pair<U, V>&& xy );
</td>

<td > (6) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Constructs an object in allocated, but not initialized storage pointed to by p using OuterAllocator and the provided constructor arguments. If the object is of type that itself uses allocators, or if it is std::pair, passes InnerAllocator down to the constructed object.

First, determines the outermost allocator type OUTERMOST: it is the type that would be returned by calling Template:cpp, and then calling the outer_allocator() member function recursively on the result of this call until reaching the type that has no such member function. That type is the outermost allocator.

Then:

1) If Template:cpp (the type T does not use allocators) and if Template:cpp, then calls

Template:cpp

Otherwise, if Template:cpp (the type T uses allocators, e.g. it is a container) and if Template:cpp, then calls

Template:cpp

Otherwise, Template:cpp (the type T uses allocators, e.g. it is a container) and if Template:cpp, then calls

Template:cpp

Otherwise, compilation error is issued because although std::uses_allocator<T> claimed that T is allocator-aware, it lacks either form of allocator-accepting constructors.

2) First, if either T1 or T2 is allocator-aware, modifies the tuples x and y to include the appropriate inner allocator, resulting in the two new tuples xprime and yprime, according to the following three rules:

2a) if T1 is not allocator-aware (Template:cpp, then xprime is x, unmodified. (it is also required that Template:cpp)

2b) if T1 is allocator-aware (Template:cpp), and its constructor takes an allocator tag (Template:cpp, then xprime is Template:cpp 2c) if T1 is allocator-aware (Template:cpp), and its constructor takes the allocator as the last argument (Template:cpp), then xprime is Template:cpp.

Same rules apply to T2 and the replacement of y with yprime

Once xprime and yprime are constructed (this also requires that all types in Args1... and Args2... are Template:concept), constructs the pair p in allocated storage by calling

Template:cpp


3) Equivalent to Template:cpp, that is, passes the inner allocator on to the pair's member types if they accept them.

4) Equivalent to

Template:cpp

5) Equivalent to

Template:cpp

6) Equivalent to

Template:cpp

Contents

Parameters

p - pointer to allocated, but not initialized storage
args... - the constructor arguments to pass to the constructor of T
x - the constructor arguments to pass to the constructor of T1
y - the constructor arguments to pass to the constructor of T2
xy - the pair whose two members are the constructor arguments for T1 and T2

Return value

(none)

Notes

This function is called (through Template:cpp) by any allocator-aware object, such as Template:cpp, that was given a Template:cpp as the allocator to use. Since inner_allocator is itself an instance of Template:cpp, this function will also be called when the allocator-aware objects constructed through this function start constructing their own members.

See also

Template:cpp/memory/allocator traits/dcl list constructTemplate:cpp/memory/allocator/dcl list construct