std::shared...owner_equal(3)
π 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β thestd::shared_ptrorstd::weak_ptrto 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_ptras 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms