std::experi...::shared_ptr(3)

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

okay so bestie, welcome to std::experi...::shared_ptr(3) from the C++ Standard Libary β€” yes, that’s the manual name, typo and all, and we’re obsessed πŸ’–. This is the std::experimental::shared_ptr moment: same energy as std::shared_ptr, but with array support added. Let’s get into it ✨

🌸 NAME 🌸

std::experimental::shared_ptr β€” std::experimental::shared_ptr. that’s literally the whole NAME line, bestie πŸ’…

✨ Synopsis ✨

Defined in header <experimental/memory> 🌈

template< class T > class shared_ptr;    (library fundamentals TS)

std::experimental::shared_ptr is a modified version of std::shared_ptr that adds support for arrays. 🫢

🧬 Member types 🧬

  • element_type β€” std::remove_extent_t<T> πŸ’œ

πŸ’… Member functions πŸ’…

  • constructor β€” constructs new shared_ptr (public member function) ✨

πŸ”­ Observers πŸ”­

  • get β€” returns the stored pointer (public member function) πŸ‘€
  • operator* β€” dereferences the stored pointer ⭐
  • operator-> β€” public member function (the page gives it the (public member function) tag here without a separate one-line description, bestie) πŸ’…
  • operator[] β€” provides index access to the array (public member function) πŸ“

🌈 Non-member functions 🌈

  • static_pointer_cast, dynamic_pointer_cast, const_pointer_cast, reinterpret_pointer_cast β€” these function templates apply static_cast, dynamic_cast, const_cast, or reinterpret_cast to the stored pointer ✨

πŸŽ€ Helper classes πŸŽ€

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

🫢 Members and non-members identical to std::shared_ptr 🫢

🌸 Member functions 🌸

The following member functions work with std::experimental::shared_ptr instead of std::shared_ptr and std::experimental::weak_ptr instead of std::weak_ptr. The behavior is otherwise identical. πŸ’–

  • destructor β€” destructs the owned object if no more shared_ptrs link to it (public member function of std::shared_ptr<T>) πŸ’€
  • operator= β€” assigns the shared_ptr (public member function of std::shared_ptr<T>) 🫢

πŸ› οΈ Modifiers πŸ› οΈ

  • reset β€” replaces the managed object (public member function of std::shared_ptr<T>) πŸ”
  • swap β€” swaps the managed objects (public member function of std::shared_ptr<T>) πŸ”„

πŸ”­ Observers πŸ”­

  • use_count β€” returns the number of shared_ptr objects referring to the same managed object (public member function of std::shared_ptr<T>) πŸ”’
  • unique β€” (until C++20) checks whether the managed object is managed only by the current shared_ptr object (public member function of std::shared_ptr<T>) πŸ¦‹
  • operator bool β€” checks if the stored pointer is not null (public member function of std::shared_ptr<T>) βœ…
  • owner_before β€” provides owner-based ordering of shared pointers (public member function of std::shared_ptr<T>) πŸ‘‘

🌈 Non-member functions 🌈

These non-member functions are declared in the std::experimental namespace, and work with std::experimental::shared_ptr rather than std::shared_ptr, but otherwise they behave identically to the corresponding C++14 function. πŸ’«

  • make_shared, make_shared_for_overwrite (C++20) β€” creates a shared pointer that manages a new object (function template) 🌱
  • allocate_shared, allocate_shared_for_overwrite (C++20) β€” creates a shared pointer that manages a new object allocated using an allocator (function template) 🧺
  • get_deleter β€” returns the deleter of specified type, if owned (function template) πŸ—οΈ
  • operator==, operator!=, operator<, operator<=, operator>, operator>= β€” compares with another shared_ptr or with nullptr (function template) βš–οΈ

Version tags in this group: (removed in C++20), (removed in C++20), (removed in C++20), (removed in C++20), (removed in C++20) β€” yes, five of them, exactly as listed πŸ’€

  • operator<=> β€” (C++20) function template πŸš€
  • operator<<(std::shared_ptr) β€” outputs the value of the stored pointer to an output stream (function template) πŸ–¨οΈ
  • std::swap(std::shared_ptr) β€” specializes the std::swap algorithm (C++11) (function template) πŸ”

These are function templates that specialize atomic operations for std::shared_ptr, and the page tags them (deprecated in C++20), (removed in C++26): βš›οΈ

  • std::atomic_is_lock_free(std::shared_ptr)
  • std::atomic_load(std::shared_ptr)
  • std::atomic_load_explicit(std::shared_ptr)
  • std::atomic_store(std::shared_ptr)
  • std::atomic_store_explicit(std::shared_ptr)
  • std::atomic_exchange(std::shared_ptr)
  • std::atomic_exchange_explicit(std::shared_ptr)
  • std::atomic_compare_exchange_weak(std::shared_ptr)
  • std::atomic_compare_exchange_strong(std::shared_ptr)
  • std::atomic_compare_exchange_weak_explicit(std::shared_ptr)
  • std::atomic_compare_exchange_strong_explicit(std::shared_ptr)

🧚 Helper class templates 🧚

These class templates are declared in the std::experimental namespace, and work with std::experimental::shared_ptr and std::experimental::weak_ptr rather than std::shared_ptr and std::weak_ptr, but otherwise behave identically to the corresponding C++14 class template. πŸ’œ

  • owner_less (C++11) β€” provides mixed-type owner-based ordering of shared and weak pointers (class template) πŸ‘‘
  • enable_shared_from_this (C++11) β€” allows an object to create a shared_ptr referring to itself (class template) πŸͺž

πŸ§ͺ Example πŸ§ͺ

This section is incomplete Reason: no example

no example yet, bestie β€” we’re leaving that one on read πŸ™ˆ

🏷️ Categories: 🏷️

  • Noindexed pages
  • Todo no example

mwah πŸ’‹ source/version line: http://cppreference.com; date: 2024.06.10; page: std::experi...::shared_ptr(3). that’s the whole page, bestie β€” go be iconic with your arrays ✨

πŸ“¦ where this page comes from