std::owner_less
<memory>
struct owner_less; /* undefined */
(until C++17)
struct owner_less; /* undefined */
struct owner_less<std::shared_ptr <T>>;
struct owner_less<std::weak_ptr <T>>;
struct owner_less<void>;
This function object provides owner-based (as opposed to value-based) mixed-type ordering of both std::weak_ptr and std::shared_ptr . The order 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).
The default operator< is not defined for weak pointers, and may wrongly consider two shared pointers for the same object non-equivalent (see std::shared_ptr::owner_before).
Contents
Specializations
The standard library provides a specialization of std::owner_less
when T
is not specified. In this case, the parameter types are deduced from the arguments (each of which must still be either a std::shared_ptr or a std::weak_ptr ).
(class template specialization) [edit]
Nested types
result_type
(deprecated in C++17)
(2,3) bool
[edit] Member functions
(function)
std::owner_less::operator()
const std::shared_ptr <T>& rhs ) const noexcept;
const std::weak_ptr <T>& rhs ) const noexcept;
const std::weak_ptr <T>& rhs ) const noexcept;
const std::shared_ptr <T>& rhs ) const noexcept;
Compares lhs and rhs using owner-based semantics. Effectively calls lhs.owner_before(rhs).
The ordering is strict weak ordering relation.
lhs and rhs are equivalent only if they are both empty or share ownership.
Parameters
Return value
true if lhs is less than rhs as determined by the owner-based ordering, false otherwise.
[edit] 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 2873 | C++11 | operator() was not required to be noexcept | required to be noexcept |
[edit] See also
(public member function of
std::shared_ptr<T>
) [edit]