Namespaces
Variants
Views
Actions

std::owner_equal

From cppreference.com
< cpp‎ | memory
 
 
Memory management library
(exposition only*)
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
(until C++20*)
(until C++20*)

Garbage collector support (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)
(C++11)(until C++23)
 
Defined in header <memory>
struct owner_equal;
(since C++26)

This function object provides owner-based (as opposed to value-based) mixed-type equal comparison of both std::weak_ptr and std::shared_ptr. The comparison is such that two smart pointers compare equivalent only if they are both empty or if they share ownership, even if the values of the raw pointers obtained by get() are different (e.g. because they point at different subobjects within the same object).

1) Owner-based mixed-type equal comparison is not provided for types other than std::shared_ptr and std::weak_ptr.
2) The owner-based mixed-type equal comparison of std::shared_ptr and std::weak_ptr.
It is the preferred comparison predicate when building unordered associative containers with std::shared_ptr and std::weak_ptr as keys together with std::owner_hash, that is, std::unordered_map<std::shared_ptr<T>, U, std::owner_hash, std::owner_equal> or std::unordered_map<std::weak_ptr<T>, U, std::owner_hash, std::owner_equal>.
3) std::owner_equal deduces the parameter types from the arguments.

Contents

[edit] Nested types

Nested type Definition
is_transparent unspecified

[edit] Member functions

operator()
compares its arguments using owner-based semantics
(function)

std::owner_equal::operator()

template< class T, class U >

bool operator()( const std::shared_ptr<T>& lhs,

                 const std::shared_ptr<U>& rhs ) const noexcept;
(since C++26)
template< class T, class U >

bool operator()( const std::shared_ptr<T>& lhs,

                 const std::weak_ptr<U>& rhs ) const noexcept;
(since C++26)
template< class T, class U >

bool operator()( const std::weak_ptr<T>& lhs,

                 const