std::experi...al::weak_ptr(3)

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

πŸ’– NAME πŸ’–

std::experimental::weak_ptr β€” std::experimental::weak_ptr (yes bestie, that's the whole name section, the manpage said it twice and honestly? iconic of it) ✨


✨ SYNOPSIS ✨

okay so first things first, she lives here:

Defined in header <experimental/memory>
template< class T > class weak_ptr;      (library fundamentals TS)

And what is she? Okay so std::experimental::weak_ptr is a modified version of std::weak_ptr β€” like, the glow-up edition πŸ’… β€” and she does two things the original doesn't:

  • she interoperates with std::experimental::shared_ptr 🫢
  • she has support for arrays 🌈

That's it, that's the whole pitch, no cap. πŸŽ€


πŸ¦‹ MEMBER TYPES πŸ¦‹

One (1) member type, and she ate:

  • element_type β€” defined as std::remove_extent_t<T> ⭐

🌸 MEMBER FUNCTIONS 🌸

  • constructor β€” constructs new weak_ptr (public member function) 🧚

πŸ‘‘ MEMBERS AND NON-MEMBERS IDENTICAL TO std::weak_ptr πŸ‘‘

Everything under this heading is the same energy as std::weak_ptr β€” except the parts below have a little twist:

Heads up bestie: the following member functions work with std::experimental::shared_ptr instead of std::shared_ptr, and with std::experimental::weak_ptr instead of std::weak_ptr. The behavior is otherwise identical. So don't overthink it πŸ’€

πŸŽ€ Member functions πŸŽ€

  • destructor β€” destroys a weak_ptr (public member function of std::weak_ptr<T>)
  • operator= β€” assigns the weak_ptr (public member function of std::weak_ptr<T>)

πŸ”₯ Modifiers πŸ”₯

  • reset β€” releases the ownership of the managed object (public member function of std::weak_ptr<T>)
  • swap β€” swaps the managed objects (public member function of std::weak_ptr<T>)

⭐ Observers ⭐

  • use_count β€” returns the number of shared_ptr objects that manage the object (public member function of std::weak_ptr<T>)
  • expired β€” checks whether the referenced object was already deleted (public member function of std::weak_ptr<T>)
  • lock β€” creates a shared_ptr that manages the referenced object (public member function of std::weak_ptr<T>)
  • owner_before β€” provides owner-based ordering of weak pointers (public member function of std::weak_ptr<T>)

πŸ’œ Non-member functions πŸ’œ

Plot twist: this non-member function is declared in the std::experimental namespace, and works with std::experimental::weak_ptr rather than std::weak_ptr β€” but otherwise she behaves identically to the corresponding C++14 function. Same girl, different namespace 😌

  • std::swap(std::weak_ptr) β€” specializes the std::swap algorithm (C++11) (function template)

πŸ™ˆ EXAMPLE πŸ™ˆ

This section is incomplete.

Reason: no example 😭 (ngl we're all waiting on this one)


πŸ“ CATEGORIES πŸ“

  • Noindexed pages
  • Todo no example

Okay that's the whole page, bestie β€” you understood it, I'm so proud of you, mwah πŸ«ΆπŸ’–

Catch her at http://cppreference.com, dated 2024.06.10, filed under std::experi...al::weak_ptr(3) in the C++ Standard Library. Slay, go read some docs, periodt. βœ¨πŸ‘‘

πŸ“¦ where this page comes from