Difference between revisions of "cpp/memory/owner equal"
(added c++26 std::owner_equal) |
(Link update.) |
||
Line 17: | Line 17: | ||
@3@ {{tt|std::owner_equal}} deduces the parameter types from the arguments. | @3@ {{tt|std::owner_equal}} deduces the parameter types from the arguments. | ||
− | === | + | ===Nested types=== |
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc hitem| | + | {{dsc hitem|Nested type|Definition}} |
− | {{dsc|{{tt|is_transparent}}|unspecified}} | + | {{dsc|{{tt|is_transparent}}|[[cpp/utility/functional#Transparent function objects|unspecified]]}} |
{{dsc end}} | {{dsc end}} | ||
Latest revision as of 21:57, 2 January 2024
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).
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, |
(since C++26) | |
template< class T, class U > bool operator()( const std::shared_ptr<T>& lhs, |
(since C++26) | |
template< class T, class U > bool operator()( const std::weak_ptr<T>& lhs, |
(since C++26) | |
template< class T, class U > bool operator()( const std::weak_ptr<T>& lhs, |
(since C++26) | |
Compares lhs and rhs using owner-based semantics. Effectively calls lhs.owner_equal(rhs).
The equal comparison is an equivalence relation.
lhs and rhs are equivalent only if they are both empty or share ownership.
Parameters
lhs, rhs | - | shared-ownership pointers to compare |
Return value
true if lhs and rhs are both empty or share ownership as determined by the owner-based equal comparison, false otherwise.
[edit] Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_smart_ptr_owner_equality |
202306L | (C++26) | Enabling the use of std::shared_ptr and std::weak_ptr as keys in unordered associative containers
|
[edit] See also
(C++26) |
provides owner-based equal comparison of shared pointers (public member function of std::shared_ptr<T> )
|
(C++26) |
provides owner-based equal comparison of weak pointers (public member function of std::weak_ptr<T> )
|