STD::__NEW_ALLOCATOR(3)

πŸ’– NAME πŸ’–

std::__new_allocator< _Tp > β€” an allocator that uses global new, as per C++03 [20.4.1]. That's the whole vibe, bestie, it's the blueprint allocator, the OG, the one the standard literally wrote down. πŸ‘‘


✨ SYNOPSIS ✨

#include <memory>

So like, it's lowkey inherited by a whole friend group: std::allocator< _Up >, std::allocator< value_type >, std::allocator< void >, std::allocator< byte >, __gnu_cxx::new_allocator< _Tp >, and std::allocator< _Tp >. They all showed up to the party and this is the base they're standing on. 🫢

🌸 Public Types 🌸

  • typedef std::ptrdiff_t difference_type β€” the type that measures distance between pointers, so iconic for pointer math.
  • typedef std::true_type propagate_on_container_move_assignment β€” yes bestie, it propagates on container move assignment, it said so itself.
  • typedef std::size_t size_type β€” the unsigned type for sizes, classic, never misses.
  • typedef _Tp value_type β€” the type of the thing being allocated, obviously. πŸ’…

πŸŽ€ Public Member Functions πŸŽ€

  • constexpr __new_allocator (const __new_allocator &) noexcept β€” copy constructor, noexcept, it does not do drama. 🧚
  • template<typename _Tp1> constexpr __new_allocator (const __new_allocator< _Tp1 > &) noexcept β€” the templated converting copy constructor, also noexcept, it will literally accept a cousin allocator like it's family. 🌈
  • constexpr _Tp * allocate (size_type __n, const void *=static_cast< const void * >(0)) β€” hands you _Tp* for __n objects, and that second parameter defaults to static_cast< const void * >(0). πŸ‘‘
  • constexpr void deallocate (_Tp *__p, size_type __n) β€” gives the memory back, takes the pointer __p and the count __n, no questions asked. πŸ’–
  • __new_allocator & operator= (const __new_allocator &)=default β€” assignment operator, defaulted, because why reinvent the wheel. ✨

πŸ¦‹ Friends πŸ¦‹

  • template<typename _Up> constexpr bool operator== (const __new_allocator &, const __new_allocator< _Up > &) noexcept β€” the equality bestie, noexcept, comparing two allocators across _Up. fr fr, it's giving friendship goals. πŸ’œ

🌟 Detailed Description 🌟

template<typename _Tp>
class std::__new_allocator< _Tp >
"An allocator that uses global new, as per C++03 [20.4.1]."

Okay so bestie, listen: this is precisely the allocator defined in the C++ Standard. Not a remix, not a cover, the actual canonical text. Periodt. πŸ’…

  • all allocation calls operator new πŸ”₯
  • all deallocation calls operator delete πŸ’€

This is the default base-class implementation of std::allocator, and it's also the base-class of the __gnu_cxx::new_allocator extension. πŸŽ€

Not me begging you to use either std::allocator or __gnu_cxx::new_allocator instead of using this directly. Like, please. This one is the behind-the-scenes main character, not the one you date. πŸ™ˆ

⭐ Template Parameters ⭐

  • _Tp β€” type of allocated object. That's it, that's the parameter, it's the type of the thing you're allocating. Slay. 🌸

πŸ’œ Author πŸ’œ

Generated automatically by Doxygen for libstdc++ from the source code. The robot wrote it, we just gave it the glow-up. πŸ€–βœ¨


That's the whole page, babe β€” this one lives in the libstdc++ collection, filed under std::__new...ator< _Tp >(3) in the Library Functions Manual, and it's exactly the kind of low-level lore that makes containers work while nobody claps for it. 🫢 Go forth and let std::allocator handle it for you, iykyk. πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms