std::weak_ptr<T>::owner_before (3) - Linux Manuals
std::weak_ptr<T>::owner_before: std::weak_ptr<T>::owner_before
NAME
std::weak_ptr<T>::owner_before - std::weak_ptr<T>::owner_before
Synopsis
template< class Y > (until C++17)
bool owner_before( const weak_ptr<Y>& other) const;
template< class Y > (since C++17)
bool owner_before( const weak_ptr<Y>& other) const noexcept;
template< class Y > (until C++17)
bool owner_before( const std::shared_ptr<Y>& other) const;
template< class Y > (since C++17)
bool owner_before( const std::shared_ptr<Y>& other) const noexcept;
Checks whether this weak_ptr precedes other in implementation defined owner-based (as opposed to value-based) order. The order 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)
This ordering is used to make shared and weak pointers usable as keys in associative containers, typically through std::owner_less.
Parameters
other - the std::shared_ptr or std::weak_ptr to be compared
Return value
true if *this precedes other, false otherwise. Common implementations compare the addresses of the control blocks.
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG_2942 C++17 weak_ptr::owner_before isn't noexcept while its shared_ptr counterpart is made noexcept
Example
// Run this code
Output:
See also
owner_less provides mixed-type owner-based ordering of shared and weak pointers
(C++11)