std::shared...owner_equal(3)

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

πŸ’– std::shared_ptr::owner_equal πŸ’–

okay so bestie, we're in the C++ Standard Libary manual (yes, that's the spelling on the page πŸ‘€), and this is the page for std::shared_ptr::owner_equal β€” the header does that truncated std::shared...owner_equal(3) thing, which is very mysterious of it. But lowkey this is just a slay little equality check. Let's get into it πŸ’…


✨ NAME ✨

std::shared_ptr::owner_equal β€” std::shared_ptr::owner_equal

🌸 Synopsis 🌸

here's the whole synopsis exactly as it appears, markers and all β€” do not @ me about the line breaks 😭

template< class Y >
bool owner_equal( const std::shared_ptr<Y>& other ) const
(1) (since C++26)
noexcept;
template< class Y >
(2) (since C++26)
bool owner_equal( const std::weak_ptr<Y>& other ) const noexcept;

okay so what it actually does: it checks whether this shared_ptr and other share ownership, or whether they're both empty. The comparison is set up so two smart pointers compare equivalent only if they're both empty or both own the same object β€” even if the values of the pointers you get from get() are different (e.g. because they point at different subobjects within the same object). no cap 🫢

The member function owner_equal is an equivalence relation such that !owner_before(other) && !other.owner_before(*this) is true if and only if owner_equal(other) is true. iconic behavior honestly ✨

This ordering is used to make shared and weak pointers usable as keys in unordered associative containers, typically through std::owner_equal. yep, it's giving "container key main character energy" πŸ‘‘

🫢 Parameters 🫢

  • other β€” the std::shared_ptr or std::weak_ptr to be compared

πŸ”₯ Return value πŸ”₯

true if *this and other share ownership or are both empty. Otherwise, returns false. simple as that, bestie πŸ’…

🧠 Notes 🧠

the feature-test macro situation is:

  • Feature-test macro: __cpp_lib_smart_ptr_owner_equality
  • Value: 202306L
  • Std: (C++26)
  • Feature: Enabling the use of std::shared_ptr as keys in unordered associative containers

🌈 Example 🌈

This section is incomplete 😭

Reason: example

πŸ‘‘ See also πŸ‘‘

  • owner_equal (C++26) β€” provides mixed-type owner-based equal comparisons of shared and weak pointers (class)

πŸ—‚οΈ Category

  • Todo with reason

mwah πŸ’‹ that's the whole page. source: http://cppreference.com Β· version/date: 2024.06.10 Β· footer title: std::shared...owner_equal(3). stay hydrated and may your pointers always share ownership correctly 🫢✨🌸

πŸ“¦ where this page comes from