cpp/memory/owner less

This function object provides owner-based (as opposed to value-based) mixed-type ordering of both std and std. 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 are different (e.g. because they point at different subobjects within the same object).

This class template is the preferred comparison predicate when building associative containers with std or std as keys, that is,

or

.

The default is not defined for weak pointers, and may wrongly consider two shared pointers for the same object non-equivalent (see ).

Specializations
{{rrev|until=c++20|1=

Member types
}}

Member functions
{{member|{{small|std::owner_less::}}operator| {{dcl begin}} {{dcl h|member only of {{tt|owner_less>}} template specialization}} {{dcl|since=c++11| bool operator( const std::shared_ptr& lhs,                 const std::shared_ptr& rhs ) const noexcept; }} {{dcl h|member only of {{tt|owner_less>}} template specialization}} {{dcl|since=c++11| bool operator( const std::weak_ptr& lhs,                 const std::weak_ptr& rhs ) const noexcept; }} {{dcl h|member of both template specializations}} {{dcl|since=c++11| bool operator( const std::shared_ptr& lhs,                 const std::weak_ptr& rhs ) const noexcept; }} {{dcl|since=c++11| bool operator( const std::weak_ptr& lhs,                 const std::shared_ptr& rhs ) const noexcept; }} {{dcl end}}

Compares {{c|lhs}} and {{c|rhs}} using owner-based semantics. Effectively calls {{c|lhs.owner_before(rhs)}}.

The ordering is strict weak ordering relation.

{{c|lhs}} and {{c|rhs}} are equivalent only if they are both empty or share ownership.

Return value
if is less than  as determined by the owner-based ordering. }}