std::uninit...g_allocator(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

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 to T'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 from T's constructor, and typically std::bad_alloc is 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