std::experi...observer_ptr(3)

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

πŸ’… std::experi...observer_ptr(3) πŸ’…

okay bestie, welcome to the C++ Standard Library manual page for std::experimental::observer_ptr β€” the original header spells it β€œLibary” and honestly? iconic typo energy πŸ’€. The full manual name is std::experi...observer_ptr(3), so if you see that truncated little gremlin, it's this page. ✨

✨ NAME ✨

std::experimental::observer_ptr - std::experimental::observer_ptr

🌸 Synopsis 🌸

Defined in header <experimental/memory>
template< class W >                      (library fundamentals TS v2)
class observer_ptr;

std::experimental::observer_ptr is a non-owning pointer, or observer. The observer stores a pointer to a second object, known as the watched object. An observer_ptr may also have no watched object.

An observer is not responsible in any way for the watched object; there is no inherent relationship between an observer and the object it watches. She's just watching, not parenting. πŸ‘€

It is intended as a near drop-in replacement for raw pointer types, with the advantage that, as a vocabulary type, it indicates its intended use without need for detailed analysis by code readers. So she's literally saying β€œhi, I'm an observer, read me and move on” β€” main character energy fr fr. πŸ’…

Specializations of observer_ptr satisfy the requirements of CopyConstructible and CopyAssignable. slay. ✨

πŸ¦‹ Type requirements πŸ¦‹

  • W shall not be a reference type, but may be an incomplete type.

πŸŽ€ Member types πŸŽ€

  • Member type: element_type β€” Definition: W, the type of the object watched by this observer_ptr

πŸ’– Member functions πŸ’–

  • constructor β€” constructs a new observer_ptr (public member function)
  • destructor β€” destructs an observer_ptr (implicitly declared) (public member function)
  • operator= β€” implicitly declared copy and move assignment operators that assign the stored pointer (implicitly declared) (public member function)

πŸ”₯ Modifiers πŸ”₯

  • release β€” returns a pointer to the watched object and stops watching the object (public member function)
  • reset β€” replaces the watched object (public member function)
  • swap β€” swaps the watched objects (public member function)

πŸ‘€ Observers πŸ‘€

  • get β€” returns a pointer to the watched object (public member function)
  • operator bool β€” checks if there is an associated watched object (public member function)
  • operator* β€” dereferences pointer to the watched object
  • operator-> β€” (public member function)

πŸ” Conversions πŸ”

  • operator element_type* β€” explicit conversion function to the stored pointer (public member function)

🌈 Non-member functions 🌈

  • make_observer β€” creates an observer_ptr that watches an object (function template)
  • operator==, operator!=, operator<, operator<=, operator>, operator>= β€” compares to another observer_ptr or with nullptr (function template)
  • std::experimental::swap(std::experimental::observer_ptr) β€” specializes the swap algorithm (function template)

🧚 Helper classes 🧚

  • std::hash<std::experimental::observer_ptr> β€” hash support for observer_ptr (class template specialization)

πŸ“ Example πŸ“

This section is incomplete
Reason: no example

πŸ—‚ Category πŸ—‚

  • Todo no example

okay bestie, that's the whole page πŸ’– source: http://cppreference.com, version/date: 2024.06.10, and the footer title is std::experi...observer_ptr(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from