STD::SHARED_PTR(3cxx)

🌸 NAME 🌸

okay so this is the std::shared_ptr< _Tp >(3cxx) page, bestie πŸ’– and it's literally about std::shared_ptr< _Tp > β€” a smart pointer with reference-counted copy semantics. iconic behavior, no cap ✨


✨ SYNOPSIS ✨

#include <memory>

Inherits std::__shared_ptr< _Tp, _Lp >. 🫢

πŸŽ€ Public Types πŸŽ€

  • using element_type = typename __shared_ptr< _Tp >::element_type β€” the type pointed to by the stored pointer, remove_extent_t<_Tp> πŸ’…
  • using weak_type = weak_ptr< _Tp > β€” the corresponding weak_ptr type for this shared_ptr, periodt ✨

πŸ’… Public Member Functions πŸ’…

  • constexpr shared_ptr () noexcept β€” construct an empty shared_ptr 🫧
  • template<typename _Yp , typename = _Constructible<_Yp*>> shared_ptr (_Yp *__p) β€” construct a shared_ptr that owns the pointer __p πŸ”₯
  • template<typename _Yp , typename _Deleter , typename = _Constructible<_Yp*, _Deleter>> shared_ptr (_Yp *__p, _Deleter __d) β€” construct a shared_ptr that owns the pointer __p and the deleter __d πŸŽ€
  • template<typename _Yp , typename _Deleter , typename _Alloc , typename = _Constructible<_Yp*, _Deleter, _Alloc>> shared_ptr (_Yp *__p, _Deleter __d, _Alloc __a) β€” construct a shared_ptr that owns the pointer __p and the deleter __d (allocator __a is right there in the signature, iykyk) πŸ’œ
  • template<typename _Yp , typename = _Constructible<auto_ptr<_Yp>>> shared_ptr (auto_ptr< _Yp > &&__r) β€” this overload is literally listed with no extra description, bestie 🌈
  • shared_ptr (const shared_ptr &) noexcept=default β€” copy constructor πŸ’–
  • template<typename _Yp , typename = _Constructible<const shared_ptr<_Yp>&>> shared_ptr (const shared_ptr< _Yp > &__r) noexcept β€” if __r is empty, constructs an empty shared_ptr; otherwise constructs a shared_ptr that shares ownership with __r ✨
  • template<typename _Yp > shared_ptr (const shared_ptr< _Yp > &__r, element_type *__p) noexcept β€” constructs a shared_ptr instance that stores __p and shares ownership with __r πŸ‘‘
  • template<typename _Yp , typename = _Constructible<const weak_ptr<_Yp>&>> shared_ptr (const weak_ptr< _Yp > &__r) β€” constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r πŸ¦‹
  • template<typename _Deleter > shared_ptr (nullptr_t __p, _Deleter __d) β€” construct a shared_ptr that owns a null pointer and the deleter __d πŸ“
  • template<typename _Deleter , typename _Alloc > shared_ptr (nullptr_t __p, _Deleter __d, _Alloc __a) β€” construct a shared_ptr that owns a null pointer and the deleter __d πŸ’«
  • constexpr shared_ptr (nullptr_t) noexcept β€” construct an empty shared_ptr 🫢
  • shared_ptr (shared_ptr &&__r) noexcept β€” move-constructs a shared_ptr instance from __r πŸ”₯
  • template<typename _Yp , typename = _Constructible<shared_ptr<_Yp>>> shared_ptr (shared_ptr< _Yp > &&__r) noexcept β€” move-constructs a shared_ptr instance from __r πŸ’…
  • template<typename _Yp > shared_ptr (shared_ptr< _Yp > &&__r, element_type *__p) noexcept β€” constructs a shared_ptr instance that stores __p and shares ownership with __r 🌸
  • template<typename _Tp1 , typename > shared_ptr (std::auto_ptr< _Tp1 > &&__r) β€” this overload is listed with no extra description, periodt πŸ’œ
  • template<typename _Yp , typename _Del , typename = _Constructible<unique_ptr<_Yp, _Del>>> shared_ptr (unique_ptr< _Yp, _Del > &&__r) β€” this overload is also listed with no extra description, no cap 🌈
  • element_type * get () const noexcept β€” return the stored pointer πŸ‘€
  • operator bool () const noexcept β€” return true if the stored pointer is not null βœ…
  • element_type & operator* () const noexcept β€” dereference vibes, literally listed like this πŸ’–
  • element_type * operator-> () const noexcept β€” arrow access vibes, also literally listed like this ✨
  • template<typename _Yp > _Assignable< auto_ptr< _Yp > > operator= (auto_ptr< _Yp > &&__r) β€” assignment from auto_ptr rvalue πŸŽ€
  • shared_ptr & operator= (const shared_ptr &) noexcept=default β€” copy assignment, defaulted 🫢
  • template<typename _Yp > _Assignable< const shared_ptr< _Yp > & > operator= (const shared_ptr< _Yp > &__r) noexcept β€” assignment from const shared_ptr<_Yp>& πŸ¦‹
  • shared_ptr & operator= (shared_ptr &&__r) noexcept β€” move assignment πŸ“
  • template<class _Yp > _Assignable< shared_ptr< _Yp > > operator= (shared_ptr< _Yp > &&__r) noexcept β€” assignment from shared_ptr<_Yp>&& πŸ”₯
  • template<typename _Yp , typename _Del > _Assignable< unique_ptr< _Yp, _Del > > operator= (unique_ptr< _Yp, _Del > &&__r) β€” assignment from unique_ptr<_Yp, _Del>&& πŸ‘‘
  • void reset () noexcept β€” reset, no extra prose on this one πŸ’…
  • template<typename _Yp > _SafeConv< _Yp > reset (_Yp *__p) β€” reset with __p 🌸
  • template<typename _Yp , typename _Deleter > _SafeConv< _Yp > reset (_Yp *__p, _Deleter __d) β€” reset with __p and deleter __d πŸŽ€
  • template<typename _Yp , typename _Deleter , typename _Alloc > _SafeConv< _Yp > reset (_Yp *__p, _Deleter __d, _Alloc __a) β€” reset with __p, deleter __d, and allocator __a πŸ’œ
  • void swap (__shared_ptr< _Tp, _Lp > &__other) noexcept β€” exchange both the owned pointer and the stored pointer πŸ”
  • bool unique () const noexcept β€” return true if use_count() == 1 ☝️
  • long use_count () const noexcept β€” if *this owns a pointer, return the number of owners, otherwise zero πŸ”’
  • template<typename _Tp1 > bool owner_before (__shared_ptr< _Tp1, _Lp > const &__rhs) const noexcept β€” define an ordering based on ownership 🫢
  • template<typename _Tp1 > bool owner_before (__weak_ptr< _Tp1, _Lp > const &__rhs) const noexcept β€” define an ordering based on ownership 🫢

🌈 Friends 🌈

  • template<typename _Yp , typename _Alloc > shared_ptr< _BoundedArray< _Yp > > allocate_shared (const _Alloc &) β€” friend allocate_shared πŸŽ€
  • template<typename _Yp , typename _Alloc , typename... _Args> shared_ptr< _NonArray< _Yp > > allocate_shared (const _Alloc &, _Args &&...) β€” friend allocate_shared ✨
  • template<typename _Yp , typename _Alloc > shared_ptr< _BoundedArray< _Yp > > allocate_shared (const _Alloc &, const remove_extent_t< _Yp > &) β€” friend allocate_shared πŸ’–
  • template<typename _Yp , typename _Alloc > shared_ptr< _UnboundedArray< _Yp > > allocate_shared (const _Alloc &, size_t) β€” friend allocate_shared πŸ¦‹
  • template<typename _Yp , typename _Alloc > shared_ptr< _UnboundedArray< _Yp > > allocate_shared (const _Alloc &, size_t, const remove_extent_t< _Yp > &) β€” friend allocate_shared πŸ“
  • template<typename _Yp , typename _Alloc > shared_ptr< _NotUnboundedArray< _Yp > > allocate_shared_for_overwrite (const _Alloc &) β€” friend allocate_shared_for_overwrite πŸ”₯
  • template<typename _Yp , typename _Alloc > shared_ptr< _UnboundedArray< _Yp > > allocate_shared_for_overwrite (const _Alloc &, size_t) β€” friend allocate_shared_for_overwrite πŸ’…
  • template<typename _Yp > shared_ptr< _BoundedArray< _Yp > > make_shared () β€” friend make_shared 🌸
  • template<typename _Yp , typename... _Args> shared_ptr< _NonArray< _Yp > > make_shared (_Args &&...) β€” friend make_shared πŸ‘‘
  • template<typename _Yp > shared_ptr< _BoundedArray< _Yp > > make_shared (const remove_extent_t< _Yp > &) β€” friend make_shared πŸŽ€
  • template<typename _Yp > shared_ptr< _UnboundedArray< _Yp > > make_shared (size_t) β€” friend make_shared ✨
  • template<typename _Yp > shared_ptr< _UnboundedArray< _Yp > > make_shared (size_t, const remove_extent_t< _Yp > &) β€” friend make_shared πŸ’œ
  • template<typename _Yp > shared_ptr< _NotUnboundedArray< _Yp > > make_shared_for_overwrite () β€” friend make_shared_for_overwrite 🫢
  • template<typename _Yp > shared_ptr< _UnboundedArray< _Yp > > make_shared_for_overwrite (size_t) β€” friend make_shared_for_overwrite 🌈
  • class weak_ptr< _Tp > β€” friend class weak_ptr< _Tp > πŸ’–
note: these are not member symbols, bestie β€” they just hang out in the same orbit πŸ’«
  • template<typename _Del , typename _Tp > _Del * get_deleter (const shared_ptr< _Tp > &__p) noexcept β€” 20.7.2.2.10 shared_ptr get_deleter πŸ‘€
  • template<typename _Ch , typename _Tr , typename _Tp , _Lock_policy _Lp> std::basic_ostream< _Ch, _Tr > & operator<< (std::basic_ostream< _Ch, _Tr > &__os, const __shared_ptr< _Tp, _Lp > &__p) β€” write the stored pointer to an ostream πŸ–¨οΈ
  • template<typename _Tp , typename _Up > bool operator== (const shared_ptr< _Tp > &__a, const shared_ptr< _Up > &__b) noexcept β€” equality comparison πŸ’…
  • template<typename _Tp > bool operator== (const shared_ptr< _Tp > &__a, nullptr_t) noexcept β€” shared_ptr comparison with nullptr 🫢
  • template<typename _Tp > void swap (shared_ptr< _Tp > &__a, shared_ptr< _Tp > &__b) noexcept β€” swap overload for shared_ptr πŸ”
  • template<typename _Tp , typename _Up > shared_ptr< _Tp > static_pointer_cast (const shared_ptr< _Up > &__r) noexcept β€” convert type of shared_ptr, via static_cast ✨
  • template<typename _Tp , typename _Up > shared_ptr< _Tp > const_pointer_cast (const shared_ptr< _Up > &__r) noexcept β€” convert type of shared_ptr, via const_cast πŸŽ€
  • template<typename _Tp , typename _Up > shared_ptr< _Tp > dynamic_pointer_cast (const shared_ptr< _Up > &__r) noexcept β€” convert type of shared_ptr, via dynamic_cast πŸ¦‹
  • template<typename _Tp , typename _Up > shared_ptr< _Tp > reinterpret_pointer_cast (const shared_ptr< _Up > &__r) noexcept β€” convert type of shared_ptr, via reinterpret_cast πŸ”₯
  • template<typename _Tp , typename _Up > shared_ptr< _Tp > static_pointer_cast (shared_ptr< _Up > &&__r) noexcept β€” convert type of shared_ptr rvalue, via static_cast 🌸
  • template<typename _Tp , typename _Up > shared_ptr< _Tp > const_pointer_cast (shared_ptr< _Up > &&__r) noexcept β€” convert type of shared_ptr rvalue, via const_cast πŸ’œ
  • template<typename _Tp , typename _Up > shared_ptr< _Tp > dynamic_pointer_cast (shared_ptr< _Up > &&__r) noexcept β€” convert type of shared_ptr rvalue, via dynamic_cast πŸ‘‘
  • template<typename _Tp , typename _Up > shared_ptr< _Tp > reinterpret_pointer_cast (shared_ptr< _Up > &&__r) noexcept β€” convert type of shared_ptr rvalue, via reinterpret_cast πŸ“
  • template<typename _Tp , typename _Alloc , typename... _Args> shared_ptr< _NonArray< _Tp > > allocate_shared (const _Alloc &__a, _Args &&... __args) β€” create an object that is owned by a shared_ptr 🫢
  • template<typename _Tp , typename... _Args> shared_ptr< _NonArray< _Tp > > make_shared (_Args &&... __args) β€” create an object that is owned by a shared_ptr πŸŽ€
  • template<typename _Tp , typename _Alloc > shared_ptr< _UnboundedArray< _Tp > > allocate_shared (const _Alloc &__a, size_t __n) β€” create an object that is owned by a shared_ptr πŸ’–
  • template<typename _Tp , typename _Alloc > shared_ptr< _BoundedArray< _Tp > > allocate_shared (const _Alloc &__a) β€” create an object that is owned by a shared_ptr 🌈

πŸ’œ Detailed Description πŸ’œ

template<typename _Tp>
class std::shared_ptr< _Tp >

A smart pointer with reference-counted copy semantics. 🫢

Since: C++11 ✨

A shared_ptr object is either empty or owns a pointer passed to the constructor. Copies of a shared_ptr share ownership of the same pointer. When the last shared_ptr that owns the pointer is destroyed or reset, the owned pointer is freed β€” either by delete or by invoking a custom deleter that was passed to the constructor. πŸ’€πŸ”₯

A shared_ptr also stores another pointer, which is usually (but not always) the same pointer as it owns. The stored pointer can be retrieved by calling the get() member function. πŸ‘€

The equality and relational operators for shared_ptr only compare the stored pointer returned by get(), not the owned pointer. To test whether two shared_ptr objects share ownership of the same pointer, see std::shared_ptr::owner_before and std::owner_less. πŸ‘‘πŸ’…


part 2 has the rest, bestie β€” don't touch that dial 🌈

πŸ’– Member Typedef Documentation πŸ’–

Ok bestie, these are the little type aliases living inside shared_ptr β€” they're giving "shortcut names so you don't have to type the scary template soup" ✨

  • element_type β€” template<typename _Tp > using std::shared_ptr< _Tp >::element_type = typename __shared_ptr<_Tp>::element_type It's the type pointed to by the stored pointer, i.e. remove_extent_t<_Tp>. Literally the "what am I actually pointing at" type 🎯
  • weak_type β€” template<typename _Tp > using std::shared_ptr< _Tp >::weak_type = weak_ptr<_Tp> The corresponding weak_ptr type for this shared_ptr. So convenient, so cute.
    • Since β€” C++17 πŸ¦‹

πŸŽ€ Constructor & Destructor Documentation πŸŽ€

This is the main character section fr fr β€” every single way to build a shared_ptr. Buckle up, there are a LOT of them and every one matters πŸ‘‘

1. The empty one 🫧

template<typename _Tp > constexpr std::shared_ptr< _Tp >::shared_ptr ()
    [inline],  [constexpr],  [noexcept]

Construct an empty shared_ptr. Nothing owned, nothing stored, just vibes.

  • Postcondition β€” use_count()==0 && get()==0

2. The copy constructor πŸ“‹

template<typename _Tp > std::shared_ptr< _Tp >::shared_ptr (const
    shared_ptr< _Tp > &) [default],  [noexcept]

Copy constructor. Yes it's [default]ed and [noexcept], no drama. πŸ’…

3. The "take ownership of this raw pointer" one πŸ”₯

template<typename _Tp > template<typename _Yp , typename  =
    _Constructible<_Yp*>> std::shared_ptr< _Tp >::shared_ptr (_Yp * __p)
    [inline],  [explicit]

Construct a shared_ptr that owns the pointer __p.

  • Parameters
    • __p β€” A pointer that is convertible to element_type*.
  • Postcondition β€” use_count() == 1 && get() == __p
  • Exceptions β€” std::bad_alloc, in which case delete __p is called. 😭 (yep, it cleans up for you, iconic)

4. Pointer + custom deleter 🧚

template<typename _Tp > template<typename _Yp , typename _Deleter , typename
    = _Constructible<_Yp*, _Deleter>> std::shared_ptr< _Tp >::shared_ptr
    (_Yp * __p, _Deleter __d) [inline]

Construct a shared_ptr that owns the pointer __p and the deleter __d.

  • Parameters
    • __p β€” A pointer.
    • __d β€” A deleter.
  • Postcondition β€” use_count() == 1 && get() == __p
  • Exceptions β€” std::bad_alloc, in which case __d(__p) is called.
  • Requirements: _Deleter's copy constructor and destructor must not throw ⚠️

__shared_ptr will release __p by calling __d(__p)

5. Null pointer + custom deleter πŸ•³οΈ

template<typename _Tp > template<typename _Deleter > std::shared_ptr< _Tp
    >::shared_ptr (nullptr_t __p, _Deleter __d) [inline]

Construct a shared_ptr that owns a null pointer and the deleter __d.

  • Parameters
    • __p β€” A null pointer constant.
    • __d β€” A deleter.
  • Postcondition β€” use_count() == 1 && get() == __p
  • Exceptions β€” std::bad_alloc, in which case __d(__p) is called.
  • Requirements: _Deleter's copy constructor and destructor must not throw ⚠️

The last owner will call __d(__p)

6. Pointer + deleter + allocator πŸ‘‘

template<typename _Tp > template<typename _Yp , typename _Deleter , typename
    _Alloc , typename  = _Constructible<_Yp*, _Deleter, _Alloc>>
    std::shared_ptr< _Tp >::shared_ptr (_Yp * __p, _Deleter __d, _Alloc __a)
    [inline]

Construct a shared_ptr that owns the pointer __p and the deleter __d.

  • Parameters
    • __p β€” A pointer.
    • __d β€” A deleter.
    • __a β€” An allocator.
  • Postcondition β€” use_count() == 1 && get() == __p
  • Exceptions β€” std::bad_alloc, in which case __d(__p) is called.
  • Requirements: _Deleter's copy constructor and destructor must not throw. _Alloc's copy constructor and destructor must not throw. ⚠️

__shared_ptr will release __p by calling __d(__p)

7. Null pointer + deleter + allocator 🫢

template<typename _Tp > template<typename _Deleter , typename _Alloc >
    std::shared_ptr< _Tp >::shared_ptr (nullptr_t __p, _Deleter __d, _Alloc
    __a) [inline]

Construct a shared_ptr that owns a null pointer and the deleter __d.

  • Parameters
    • __p β€” A null pointer constant.
    • __d β€” A deleter.
    • __a β€” An allocator.
  • Postcondition β€” use_count() == 1 && get() == __p
  • Exceptions β€” std::bad_alloc, in which case __d(__p) is called.
  • Requirements: _Deleter's copy constructor and destructor must not throw. _Alloc's copy constructor and destructor must not throw. ⚠️

The last owner will call __d(__p)

8. The aliasing constructor (lvalue edition) πŸͺž

template<typename _Tp > template<typename _Yp > std::shared_ptr< _Tp
    >::shared_ptr (const shared_ptr< _Yp > & __r, element_type * __p)
    [inline],  [noexcept]

Constructs a shared_ptr instance that stores __p and shares ownership with __r. So you get a pointer to a piece, but the ownership count is shared with the whole β€” lowkey genius.

  • Parameters
    • __r β€” A shared_ptr.
    • __p β€” A pointer that will remain valid while *__r is valid.
  • Postcondition β€” get() == __p && use_count() == __r.use_count()

This can be used to construct a shared_ptr to a sub-object of an object managed by an existing shared_ptr. The complete object will remain valid while any shared_ptr owns it, even if they don't store a pointer to the complete object. 🌈

shared_ptr<pair<int,int>> pii(new pair<int,int>());
shared_ptr<int> pi(pii, &pii->first);
assert(pii.use_count() == 2);

9. The aliasing constructor (rvalue edition) πŸŒ€

template<typename _Tp > template<typename _Yp > std::shared_ptr< _Tp
    >::shared_ptr (shared_ptr< _Yp > && __r, element_type * __p) [inline],
    [noexcept]

Constructs a shared_ptr instance that stores __p and shares ownership with __r.

  • Parameters
    • __r β€” A shared_ptr.
    • __p β€” A pointer that will remain valid while *__r is valid.
  • Postcondition β€” get() == __p && !__r.use_count() && !__r.get()
  • Since β€” C++17 πŸ¦‹

This can be used to construct a shared_ptr to a sub-object of an object managed by an existing shared_ptr. The complete object will remain valid while any shared_ptr owns it, even if they don't store a pointer to the complete object.

shared_ptr<pair<int,int>> pii(new pair<int,int>());
shared_ptr<int> pi1(pii, &pii->first);
assert(pii.use_count() == 2);
shared_ptr<int> pi2(std::move(pii), &pii->second);
assert(pii.use_count() == 0);

10. Converting copy constructor πŸ’«

template<typename _Tp > template<typename _Yp , typename  =
    _Constructible<const shared_ptr<_Yp>&>> std::shared_ptr< _Tp
    >::shared_ptr (const shared_ptr< _Yp > & __r) [inline],  [noexcept]

If __r is empty, constructs an empty shared_ptr; otherwise constructs a shared_ptr that shares ownership with __r.

  • Parameters
    • __r β€” A shared_ptr.
  • Postcondition β€” get() == __r.get() && use_count() == __r.use_count()

11. Move constructor (same type) πŸƒβ€β™€οΈ

template<typename _Tp > std::shared_ptr< _Tp >::shared_ptr (shared_ptr< _Tp
    > && __r) [inline],  [noexcept]

Move-constructs a shared_ptr instance from __r.

  • Parameters
    • __r β€” A shared_ptr rvalue.
  • Postcondition β€” *this contains the old value of __r, __r is empty.

12. Move constructor (converting) πŸƒβ€β™€οΈπŸ’¨

template<typename _Tp > template<typename _Yp , typename  =
    _Constructible<shared_ptr<_Yp>>> std::shared_ptr< _Tp >::shared_ptr
    (shared_ptr< _Yp > && __r) [inline],  [noexcept]

Move-constructs a shared_ptr instance from __r.

  • Parameters
    • __r β€” A shared_ptr rvalue.
  • Postcondition β€” *this contains the old value of __r, __r is empty.

13. From a weak_ptr 🧡

template<typename _Tp > template<typename _Yp , typename  =
    _Constructible<const weak_ptr<_Yp>&>> std::shared_ptr< _Tp >::shared_ptr
    (const weak_ptr< _Yp > & __r) [inline],  [explicit]

Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r.

  • Parameters
    • __r β€” A weak_ptr.
  • Postcondition β€” use_count() == __r.use_count()
  • Exceptions β€” bad_weak_ptr when __r.expired(), in which case the constructor has no effect.
Heads up bestie: if the weak_ptr already expired, this throws bad_weak_ptr and the constructor does literally nothing. No half-built object, no mess. πŸ’€

14. The nullptr_t one πŸŒ™

template<typename _Tp > constexpr std::shared_ptr< _Tp >::shared_ptr
    (nullptr_t) [inline],  [constexpr],  [noexcept]

Construct an empty shared_ptr.

  • Postcondition β€” use_count() == 0 && get() == nullptr

⭐ Member Function Documentation ⭐

Real talk β€” these are marked [inherited], so they come down from std::__shared_ptr< _Tp, _Lp > like a family heirloom πŸ‘‘

get() πŸ‘€

template<typename _Tp , _Lock_policy _Lp> element_type * std::__shared_ptr<
    _Tp, _Lp >::get () const [inline],  [noexcept],  [inherited]

Return the stored pointer. That's it, that's the function. Simple, clean, iconic ✨

operator bool() βœ…

template<typename _Tp , _Lock_policy _Lp> std::__shared_ptr< _Tp, _Lp
    >::operator bool () const [inline],  [explicit],  [noexcept],
    [inherited]

Return true if the stored pointer is not null. So if (ptr) actually does something sensible, thank goodness πŸ™

owner_before() β€” the __shared_ptr overload πŸ”€

template<typename _Tp , _Lock_policy _Lp> template<typename _Tp1 > bool
    std::__shared_ptr< _Tp, _Lp >::owner_before (__shared_ptr< _Tp1, _Lp >
    const & __rhs) const [inline],  [noexcept],  [inherited]

Define an ordering based on ownership. This function defines a strict weak ordering between two shared_ptr or weak_ptr objects, such that one object is less than the other unless they share ownership of the same pointer, or are both empty. 🧠 (yes, it's the thing you need for ordering them in sets and maps, iykyk)

owner_before() β€” the __weak_ptr overload πŸ”€

template<typename _Tp , _Lock_policy _Lp> template<typename _Tp1 > bool
    std::__shared_ptr< _Tp, _Lp >::owner_before (__weak_ptr< _Tp1, _Lp >
    const & __rhs) const [inline],  [noexcept],  [inherited]

Define an ordering based on ownership. This function defines a strict weak ordering between two shared_ptr or weak_ptr objects, such that one object is less than the other unless they share ownership of the same pointer, or are both empty. 🧠

swap() πŸ”„

template<typename _Tp , _Lock_policy _Lp> void std::__shared_ptr< _Tp, _Lp
    >::swap (__shared_ptr< _Tp, _Lp > & __other) [inline],  [noexcept],
    [inherited]

Exchange both the owned pointer and the stored pointer. Both. Not one. Both. 🫢

unique() 1️⃣

template<typename _Tp , _Lock_policy _Lp> bool std::__shared_ptr< _Tp, _Lp
    >::unique () const [inline],  [noexcept],  [inherited]

Return true if use_count() == 1. You're the only owner, main character energy πŸ‘‘

use_count() πŸ”’

template<typename _Tp , _Lock_policy _Lp> long std::__shared_ptr< _Tp, _Lp
    >::use_count () const [inline],  [noexcept],  [inherited]

If *this owns a pointer, return the number of owners, otherwise zero.


🌸 Author 🌸

Generated automatically by Doxygen for libstdc++ from the source code. (Not a human, just a very diligent robot 🧚)


And that's the whole page bestie!! πŸŽ€ You made it to the end, I'm so proud of you 🫢

This gem is from libstdc++, and the footer beeps out std::shared_ptr< _Tp >(3cxx) β€” that's the section 3 C++ library page name, no date attached to this one, ngl. Go forth and share your ownership responsibly πŸ’œβœ¨

πŸ“¦ where this page comes from