std::pmr::p...::construct(3)
π NAME π
std::pmr::polymorphic_allocator::construct β std::pmr::polymorphic_allocator::construct. Yes bestie, it said the name twice and we're keeping both π«Ά. This is the std::pmr::p...::construct(3) page from the C++ Standard Libary (that spelling is literally in the header, not me π).
β¨ Synopsis β¨
okay so here's the whole signature lineup, every overload, no skips, no cap π:
template< class U, class... Args >
(1) (since C++17)
void construct( U* p, Args&&... args );
template< class T1, class T2, class... Args1, class... Args2 >
void construct( std::pair<T1, T2>* p,
(since C++17)
std::piecewise_construct_t,
(2) (until C++20)
std::tuple<Args1...> x,
std::tuple<Args2...> y );
template< class T1, class T2 >
(3) (since C++17)
void construct( std::pair<T1, T2>* p );
(until C++20)
template< class T1, class T2, class U, class V >
(4) (since C++17)
void construct( std::pair<T1, T2>* p, U&& x, V&& y );
(until C++20)
template< class T1, class T2, class U, class V >
(5) (since C++17)
void construct( std::pair<T1, T2>* p, const std::pair<U, V>& xy );
(until C++20)
template< class T1, class T2, class U, class V >
(6) (since C++17)
void construct( std::pair<T1, T2>* p, std::pair<U, V>&& xy );
(until C++20)
template< class T1, class T2, class NonPair >
(7) (since C++17)
void construct( std::pair<T1, T2>* p, NonPair&& non_pair );
(until C++20)
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 down to the constructed object π.
- Overload 1 β
(since C++17);(until C++20). Creates an object of the given typeUby means of uses-allocator construction at the uninitialized memory location indicated byp, using*thisas the allocator. This overload participates in overload resolution only ifUis not a specialization ofstd::pair.(until C++20) - Overload 2 β
(since C++17);(until C++20). First, if eitherT1orT2is allocator-aware, modifies the tuplesxandyto includethis->resource(), resulting in the two new tuplesxprimeandyprime, according to the following three rules:- 2a) if
T1is not allocator-aware (std::uses_allocator<T1, polymorphic_allocator>::value==false) andstd::is_constructible<T1, Args1...>::value==true, thenxprimeisx, unmodified. - 2b) if
T1is allocator-aware (std::uses_allocator<T1, polymorphic_allocator>::value==true), and its constructor takes an allocator tag, wherestd::is_constructible<T1, std::allocator_arg_t, polymorphic_allocator, Args1...>::value==true, thenxprimeisstd::tuple_cat(std::make_tuple(std::allocator_arg, *this), std::move(x)). - 2c) if
T1is allocator-aware (std::uses_allocator<T1, polymorphic_allocator>::value==true), and its constructor takes the allocator as the last argument (std::is_constructible<T1, Args1..., polymorphic_allocator>::value==true), thenxprimeisstd::tuple_cat(std::move(x), std::make_tuple(*this)). - 2d) Otherwise, the program is ill-formed.
- 2a) if
Same rules apply to T2 and the replacement of y with yprime. Once xprime and yprime are constructed, 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));.
- Overload 3 β
(since C++17);(until C++20). Equivalent toconstruct(p, std::piecewise_construct, std::tuple<>(), std::tuple<>()), that is, passes the memory resource on to the pair's member types if they accept them. - Overload 4 β
(since C++17);(until C++20). Equivalent toconstruct(p, std::piecewise_construct, std::forward_as_tuple(std::forward<U>(x)), std::forward_as_tuple(std::forward<V>(y))) - Overload 5 β
(since C++17);(until C++20). Equivalent toconstruct(p, std::piecewise_construct, std::forward_as_tuple(xy.first), std::forward_as_tuple(xy.second)) - Overload 6 β
(since C++17);(until C++20). Equivalent toconstruct(p, std::piecewise_construct, std::forward_as_tuple(std::forward<U>(xy.first)), std::forward_as_tuple(std::forward<V>(xy.second))) - Overload 7 β
(since C++17);(until C++20). This overload participates in overload resolution only if, 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. Equivalent to construct<T1, T2, T1, T2>(p, std::forward<NonPair>(non_pair));
πΈ Parameters πΈ
pβ pointer to allocated, but not initialized storageargs...β the constructor arguments to pass to the constructor ofTxβ the constructor arguments to pass to the constructor ofT1yβ the constructor arguments to pass to the constructor ofT2xyβ the pair whose two members are the constructor arguments forT1andT2non_pairβ non-pair argument to convert to pair for further construction
π«Ά Return value π«Ά
(none) β literally nothing comes back, bestie. Void-coded π
.
π¦ Notes π¦
This function is called (through std::allocator_traits) by any allocator-aware object, such as std::pmr::vector (or another std::vector that was given a std::pmr::polymorphic_allocator as the allocator to use).
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
LWG 2969, applied to C++17. Behavior as published: uses-allocator construction passedresource(). Correct behavior: passes*this.LWG 2975, applied to C++17. Behavior as published: first overload is mistakenly used for pair construction in some cases. Correct behavior: constrained to not accept pairs.LWG 3525, applied to C++17. Behavior as published: no overload could handle non-pair types convertible to pair. Correct behavior: reconstructing overload added.
π See also π
construct[static]β constructs an object in the allocated storage (function template)constructβ constructs an object in allocated storage(until C++20)(public member function ofstd::allocator<T>)
okay bestie that's the whole page π source/version: http://cppreference.com, dated 2024.06.10 β¨
π¦ 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