std::pmr::p...c_allocator(3)

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

πŸ’– NAME πŸ’–

okay bestie, this page is all about std::pmr::polymorphic_allocator::polymorphic_allocator β€” yes, that’s the same name twice, because it’s the constructor page for std::pmr::polymorphic_allocator. It lives in the C++ Standard Libary manual (and yes, that’s how the manual name is spelled β€” I’m not fixing it, I’m just reporting the vibes 😭).


🌸 Synopsis 🌸

Here’s the whole constructor squad, laid out exactly like the page does it:

polymorphic_allocator() noexcept;
(1)
polymorphic_allocator( const polymorphic_allocator& other ) = default;   (2)
template< class U >
(3)
polymorphic_allocator( const polymorphic_allocator<U>& other ) noexcept;
polymorphic_allocator( std::pmr::memory_resource* r );
(4)

Constructs a new polymorphic_allocator. That’s the main character job, periodt πŸ’…

  1. (1) β€” Constructs a polymorphic_allocator using the return value of std::pmr::get_default_resource() as the underlying memory resource.
  2. (2), (3) β€” Constructs a polymorphic_allocator using other.resource() as the underlying memory resource.
  3. (4) β€” Constructs a polymorphic_allocator using r as the underlying memory resource. This constructor provides an implicit conversion from std::pmr::memory_resource*.

πŸŽ€ Parameters πŸŽ€

  • other β€” another polymorphic_allocator to copy from. πŸ’–
  • r β€” pointer to the memory resource to use. May not be null. fr fr do not pass null πŸ”₯

πŸ’€ Exceptions πŸ’€

  • (4) β€” Throws nothing. Iconic. No drama, no chaos, just quiet slay.

🧚 Notes 🧚

Copying a container using a polymorphic_allocator will not call the allocator’s copy constructor. Nope, that’s not the move.

Instead, the new container will use the return value of select_on_container_copy_construction (a default-constructed polymorphic_allocator) as its allocator. That’s the lowkey important plot twist πŸ‘‘


πŸ‘‘ See also πŸ‘‘

  • select_on_container_copy_construction β€” create a new polymorphic_allocator for use by a container’s copy constructor (public member function). 🫢

mwah πŸ’‹ source: http://cppreference.com Β· version/date: 2024.06.10 Β· page title: std::pmr::p...c_allocator(3)

πŸ“¦ where this page comes from