__GNU_CXX::_POINTER_ADAPTER(3)

πŸ¦‹ __gnu_cxx::_Pointer_adapter< _Storage_policy > πŸ¦‹

okay bestie, sit down, hydrate, because we are about to get deep into libstdc++'s pointer internals and honestly? it's giving genius. this little icon lives in the Library Functions Manual, and it's part of libstdc++, the GNU C++ standard library. yes, the one that's just there on your machine, doing the most, no cap. 🫢


✨ NAME ✨

__gnu_cxx::_Pointer_adapter< _Storage_policy > β€” the alternative pointer template that lets containers pretend your fancy custom pointer is just a normal pointer. it's the social chameleon of pointer types. πŸ’…


🌸 SYNOPSIS 🌸

#include <pointer.h>

πŸ’– Public Types πŸ’–

  • typedef std::ptrdiff_t difference_type
  • typedef _Storage_policy::element_type element_type
  • typedef std::random_access_iterator_tag iterator_category
  • typedef _Pointer_adapter pointer
  • typedef _Reference_type< element_type >::reference reference
  • typedef _Unqualified_type< element_type >::type value_type

πŸŽ€ Public Member Functions πŸŽ€

  • template<typename _Up> _Pointer_adapter (_Up *__arg)
  • _Pointer_adapter (const _Pointer_adapter &__arg)
  • template<typename _Up> _Pointer_adapter (const _Pointer_adapter< _Up > &__arg)
  • _Pointer_adapter (element_type *__arg=0)
  • operator bool () const
  • reference operator* () const
  • _Pointer_adapter & operator++ ()
  • _Pointer_adapter operator++ (int)
  • _Pointer_adapter & operator+= (int __offset)
  • _Pointer_adapter & operator+= (long __offset)
  • _Pointer_adapter & operator+= (long long __offset)
  • _Pointer_adapter & operator+= (short __offset)
  • _Pointer_adapter & operator+= (unsigned int __offset)
  • _Pointer_adapter & operator+= (unsigned long __offset)
  • _Pointer_adapter & operator+= (unsigned long long __offset)
  • _Pointer_adapter & operator+= (unsigned short __offset)
  • template<typename _Up> std::ptrdiff_t operator- (const _Pointer_adapter< _Up > &__rhs) const
  • _Pointer_adapter & operator-- ()
  • _Pointer_adapter operator-- (int)
  • _Pointer_adapter & operator-= (int __offset)
  • _Pointer_adapter & operator-= (long __offset)
  • _Pointer_adapter & operator-= (long long __offset)
  • _Pointer_adapter & operator-= (short __offset)
  • _Pointer_adapter & operator-= (unsigned int __offset)
  • _Pointer_adapter & operator-= (unsigned long __offset)
  • _Pointer_adapter & operator-= (unsigned long long __offset)
  • _Pointer_adapter & operator-= (unsigned short __offset)
  • element_type * operator-> () const
  • template<typename _Up> _Pointer_adapter & operator= (_Up *__arg)
  • _Pointer_adapter & operator= (const _Pointer_adapter &__arg)
  • template<typename _Up> _Pointer_adapter & operator= (const _Pointer_adapter< _Up > &__arg)
  • reference operator[] (std::ptrdiff_t __index) const

🧚 Friends 🧚

like, chosen family, but for operators. πŸ’œ

  • _Pointer_adapter operator+ (const _Pointer_adapter &__lhs, int __offset)
  • _Pointer_adapter operator+ (const _Pointer_adapter &__lhs, long __offset)
  • _Pointer_adapter operator+ (const _Pointer_adapter &__lhs, long long __offset)
  • _Pointer_adapter operator+ (const _Pointer_adapter &__lhs, short __offset)
  • _Pointer_adapter operator+ (const _Pointer_adapter &__lhs, unsigned int __offset)
  • _Pointer_adapter operator+ (const _Pointer_adapter &__lhs, unsigned long __offset)
  • _Pointer_adapter operator+ (const _Pointer_adapter &__lhs, unsigned long long __offset)
  • _Pointer_adapter operator+ (const _Pointer_adapter &__lhs, unsigned short __offset)
  • _Pointer_adapter operator+ (int __offset, const _Pointer_adapter &__rhs)
  • _Pointer_adapter operator+ (long __offset, const _Pointer_adapter &__rhs)
  • _Pointer_adapter operator+ (long long __offset, const _Pointer_adapter &__rhs)
  • _Pointer_adapter operator+ (short __offset, const _Pointer_adapter &__rhs)
  • _Pointer_adapter operator+ (unsigned int __offset, const _Pointer_adapter &__rhs)
  • _Pointer_adapter operator+ (unsigned long __offset, const _Pointer_adapter &__rhs)
  • _Pointer_adapter operator+ (unsigned long long __offset, const _Pointer_adapter &__rhs)
  • _Pointer_adapter operator+ (unsigned short __offset, const _Pointer_adapter &__rhs)
  • template<typename _Up> std::ptrdiff_t operator- (_Up *__lhs, const _Pointer_adapter &__rhs)
  • template<typename _Up> std::ptrdiff_t operator- (const _Pointer_adapter &__lhs, _Up *__rhs)
  • std::ptrdiff_t operator- (const _Pointer_adapter &__lhs, element_type *__rhs)
  • _Pointer_adapter operator- (const _Pointer_adapter &__lhs, int __offset)
  • _Pointer_adapter operator- (const _Pointer_adapter &__lhs, long __offset)
  • _Pointer_adapter operator- (const _Pointer_adapter &__lhs, long long __offset)
  • _Pointer_adapter operator- (const _Pointer_adapter &__lhs, short __offset)
  • _Pointer_adapter operator- (const _Pointer_adapter &__lhs, unsigned int __offset)
  • _Pointer_adapter operator- (const _Pointer_adapter &__lhs, unsigned long __offset)
  • _Pointer_adapter operator- (const _Pointer_adapter &__lhs, unsigned long long __offset)
  • _Pointer_adapter operator- (const _Pointer_adapter &__lhs, unsigned short __offset)
  • std::ptrdiff_t operator- (element_type *__lhs, const _Pointer_adapter &__rhs)
  • std::strong_ordering operator<=> (const _Pointer_adapter &__lhs, const _Pointer_adapter &__rhs) noexcept

πŸ‘‘ Detailed Description πŸ‘‘

template<typename _Storage_policy>
class __gnu_cxx::_Pointer_adapter< _Storage_policy >

so here's the whole vibe, fr fr. this class hands you an "alternative pointer" that plays nice with the containers when you set it as the pointer typedef of the allocator. that's the assignment. ✨

now, the pointer type your containers actually use does not have to be this class β€” but it has to support the implicit conversions, the pointer arithmetic, the comparison operators, etc. that this class supports, and it has to dodge raising compile-time ambiguities. that's non-negotiable bestie. 😭

and the way that creating a working pointer can be genuinely challenging? yeah, that's why this pointer template was designed to wrap an easier storage policy type, so it becomes reusable for creating other pointer types. it's a little factory for pointer girlies. πŸŽ€

a key point of this class is also that it lets container writers "assume" that Allocator::pointer is a typedef for a normal pointer. she supports most of the conventions of a true pointer, and can, for instance, handle implicit conversion to const and base class pointer types. the only impositions on container writers to support extended pointers are:

  1. use the Allocator::pointer typedef appropriately for pointer types.
  2. if you need pointer casting, use the __pointer_cast<> functions from ext/cast.h. this allows pointer cast operations to be overloaded as necessary by custom pointers.
πŸ’€ Note: the const qualifier works with this pointer adapter like this:
_Tp* == _Pointer_adapter<_Std_pointer_impl<_Tp> >; const _Tp* == _Pointer_adapter<_Std_pointer_impl<const _Tp> >; _Tp* const == const _Pointer_adapter<_Std_pointer_impl<_Tp> >; const _Tp* const == const _Pointer_adapter<_Std_pointer_impl<const _Tp> >;

like… read it twice. it slaps, but it slaps carefully. 🌈


🌟 Author 🌟

Generated automatically by Doxygen for libstdc++ from the source code. she didn't write herself, she was generated, and honestly? still main character energy. πŸ’…


okay that's the whole page bestie, mwah, go compile something beautiful 🫢

this was libstdc++, from the Library Functions Manual β€” the __gnu_cxx:...e_policy >(3) page, page 3 of the manual, no date on this one so we're just gonna say it's timeless. periodt. πŸ’–

πŸ“¦ 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.0.1-0.10.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
  • 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