std::uninit...g_allocator(3)
okay so welcome to the std::uninit...g_allocator(3) page from the C++ Standard Libary manual β yes, that's the manual name, typo and all, and we're moving on π
β¨ This whole page is about std::uninitialized_construct_using_allocator, and it's giving niche template main-character energy.
β¨ NAME β¨
std::uninitialized_construct_using_allocator β std::uninitialized_construct_using_allocator. They said it twice, bestie, and honestly? Iconic.
πΈ Synopsis πΈ
Defined in header <memory> π and this one is (since C++20), periodt.
template< class T, class Alloc, class... Args >
constexpr T* uninitialized_construct_using_allocator( T* p,
const Alloc& alloc,
Args&&... args
);
It creates an object of the given type T by means of uses-allocator construction at the uninitialized memory location indicated by p. Literally placing a whole new object at the spot p points to π«Ά
Equivalent to:
return std::apply(
[&]<class... Xs>(Xs&&...xs)
{
return std::construct_at(p, std::forward<Xs>(xs)...);
},
std::uses_allocator_construction_args<T>(alloc,
std::forward<Args>(args)...));
π Parameters π
pβ the memory location where the object will be placed. That's the spot, bestie.allocβ the allocator to use. Resource-management main character energy.argsβ the arguments to pass toT's constructor. Plural, pack it up, we love a parameter pack.
π Return value π
Pointer to the newly-created object of type T. Cute, it hands you back a T*.
π«Ά Exceptions π«Ά
May throw any exception thrown by the constructor of T, typically including std::bad_alloc.
Heads up: this can throw. The original page says any exception fromT's constructor, and typicallystd::bad_allocis in the mix. No cap π
π¦ Example π¦
This section is incomplete Reason: no example
So there is literally no example here π the page said it first, not me.
π See also π
uses_allocatorβ checks if the specified type supports uses-allocator construction. It's a class template, and it's(C++11).make_obj_using_allocatorβ creates an object of the given type by means of uses-allocator construction. It's a function template, and it's(C++20).
π Category π
- Todo no example
Signed with love: this page comes from http://cppreference.com, dated 2024.06.10, and the footer label is std::uninit...g_allocator(3). Bye bestie, go construct something cute π
πβ¨
π¦ 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