|
|
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 bothstd::weak_ptr andstd::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 byget()
are different (e.g. because they point at different subobjects within the same object).
std::owner_equal
deduces the parameter types from the arguments.Contents |
Nested type | Definition |
is_transparent | unspecified |
operator() | compares its arguments using owner-based semantics (function) |
template<class T,class U> bool operator()(conststd::shared_ptr<T>& lhs, | (since C++26) | |
template<class T,class U> bool operator()(conststd::shared_ptr<T>& lhs, | (since C++26) | |
template<class T,class U> bool operator()(conststd::weak_ptr<T>& lhs, | (since C++26) | |
template<class T,class U> bool operator()(conststd::weak_ptr<T>& lhs, | (since C++26) | |
Compareslhs andrhs using owner-based semantics. Effectively callslhs.owner_equal(rhs).
The equal comparison is an equivalence relation.
lhs andrhs are equivalent only if they are both empty or share ownership.
lhs, rhs | - | shared-ownership pointers to compare |
true iflhs andrhs are both empty or share ownership as determined by the owner-based equal comparison,false otherwise.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_smart_ptr_owner_equality | 202306L | (C++26) | Enabling the use ofstd::shared_ptr andstd::weak_ptr as keys inunordered associative containers |
(C++26) | provides owner-based equal comparison of shared pointers (public member function of std::shared_ptr<T> )[edit] |
(C++26) | provides owner-based equal comparison of weak pointers (public member function of std::weak_ptr<T> )[edit] |