std::experi...::construct(3)
π NAME π
std::experimental::pmr::polymorphic_allocator::construct β literally std::experimental::pmr::polymorphic_allocator::construct. Bestie, the NAME line repeats it and we are keeping that energy π
. This page lives in the C++ Standard Libary manual, and its title-line vibe is std::experi...::construct(3).
β¨ Synopsis β¨
template< class U, class... Args > (1) (library
fundamentals TS)
void construct( U* p, Args&&... args );
template< class T1, class T2, class... Args1, class...
Args2 >
void construct( std::pair<T1, T2>* p, (2) (library
fundamentals TS)
std::piecewise_construct_t,
std::tuple<Args1...> x,
std::tuple<Args2...> y );
template< class T1, class T2 > (3) (library
fundamentals TS)
void construct( std::pair<T1, T2>* p );
template< class T1, class T2, class U, class V > (4) (library
fundamentals TS)
void construct( std::pair<T1, T2>* p, U&& x, V&& y );
template< class T1, class T2, class U, class V >
void construct( std::pair<T1, T2>* p, const (5) (library
fundamentals TS)
std::pair<U, V>& xy );
template< class T1, class T2, class U, class V >
void construct( std::pair<T1, T2>* p, std::pair<U, (6) (library
fundamentals TS)
V>&& xy );
Okay so the whole point is: it constructs an object in allocated, but not initialized storage pointed to by p, using the provided constructor arguments. If the object is of a type that itself uses allocators, or if it is std::pair, it passes this->resource() down to the constructed object π«Ά.
1) If std::uses_allocator<U, memory_resource*>::value == false (the type U does not use allocators) and std::is_constructible<U, Args...>::value == true, then it constructs the object as if by ::new((void *) p) U(std::forward<Args>(args)...);.
Otherwise, if std::uses_allocator<U, memory_resource*>::value == true (the type U uses allocators, e.g. it is a container) and std::is_constructible<U, std::allocator_arg_t, memory_resource*, Args...>::value == true, then it constructs the object as if by ::new((void *) p) U(std::allocator_arg, this->resource(), std::forward<Args>(args)...);.
Otherwise, if std::uses_allocator<U, memory_resource*>::value == true (the type U uses allocators, e.g. it is a container) and std::is_constructible<U, Args..., memory_resource*>::value == true, then it constructs the object as if by ::new((void *) p) U(std::forward<Args>(args)..., this->resource());.
Otherwise, the program is ill-formed π.
2) First, if either T1 or T2 is allocator-aware, it modifies the tuples x and y to include this->resource(), resulting in the two new tuples xprime and yprime, according to the following three rules:
- 2a) if
T1is not allocator-aware (std::uses_allocator<T1, memory_resource*>::value == false) andstd::is_constructible<T1, Args1...>::value == true, thenxprimeisx, unmodified. - 2b) if
T1is allocator-aware (std::uses_allocator<T1, memory_resource*>::value == true), and its constructor takes an allocator tag (std::is_constructible<T1, std::allocator_arg_t, memory_resource*, Args1...>::value == true), thenxprimeisstd::tuple_cat(std::make_tuple(std::allocator_arg, this->resource()), std::move(x)). - 2c) if
T1is allocator-aware (std::uses_allocator<T1, memory_resource*>::value == true), and its constructor takes the allocator as the last argument (std::is_constructible<T1, Args1..., memory_resource*>::value == true), thenxprimeisstd::tuple_cat(std::move(x), std::make_tuple(this->resource())). - 2d) Otherwise, the program is ill-formed.
Same rules apply to T2 and the replacement of y with yprime.
Once xprime and yprime are constructed, it constructs the pair p in allocated storage as if by ::new((void *) p) pair<T1, T2>(std::piecewise_construct, std::move(xprime), std::move(yprime));.
3) Equivalent to construct(p, std::piecewise_construct, std::tuple<>(), std::tuple<>()), that is, it passes the memory resource on to the pair's member types if they accept them.
4) Equivalent to:
construct(p, std::piecewise_construct,
std::forward_as_tuple(std::forward<U>(x)),
std::forward_as_tuple(std::forward<V>(y)))
5) Equivalent to:
construct(p, std::piecewise_construct,
std::forward_as_tuple(xy.first),
std::forward_as_tuple(xy.second))
6) Equivalent to:
construct(p, std::piecewise_construct,
std::forward_as_tuple(std::forward<U>(xy.first)),
std::forward_as_tuple(std::forward<V>(xy.second)))
πΈ Parameters πΈ
pβ pointer to allocated, but not initialized storage.args...β the constructor arguments to pass to the constructor ofT.xβ the constructor arguments to pass to the constructor ofT1.yβ the constructor arguments to pass to the constructor ofT2.xyβ the pair whose two members are the constructor arguments forT1andT2.
π Return value π
(none) β bestie, it's giving βvoid energyβ β¨.
π¦ Notes π¦
This function is called (through std::allocator_traits) by any allocator-aware object, such as std::vector, that was given a std::polymorphic_allocator as the allocator to use. Since memory_resource* implicitly converts to polymorphic_allocator, the memory resource pointer will propagate to any allocator-aware subobjects using polymorphic allocators π«Ά.
π₯ See also π₯
constructβ constructs an object in the allocated storage;[static](function template).constructβ constructs an object in allocated storage;(until C++20)(public member function ofstd::allocator<T>).
π Category π
Noindexed pages
π source/version: http://cppreference.com Β· date: 2024.06.10 β that's the whole page, bestie, no cap πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms