Namespaces
Variants
Views
Actions

std::weak_ptr<T>::owner_equal

From cppreference.com
< cpp‎ | memory‎ | weak ptr
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions
Debugging support
(C++26)
Three-way comparison
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)

 
Dynamic memory management
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Allocators
Garbage collection support
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)



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

Checks whether this weak_ptr and other share ownership or are both empty. The comparison is such that two smart pointers compare equivalent only if they are both empty or if they both own the same object, even if the values of the pointers obtained by get() are different (e.g. because they point at different subobjects within the same object).

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.

This ordering is used to make shared and weak pointers usable as keys in unordered associative containers, typically through std::owner_equal.

Contents

[edit] Parameters

other - the std::shared_ptr or std::weak_ptr to be compared

[edit] Return value

true if *this and other share ownership or are both empty. Otherwise, returns false.

[edit] Notes

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

[edit] Example

[edit] See also

provides mixed-type owner-based equal comparisons of shared and weak pointers
(class) [edit]