std::owner_less

Header: <memory>

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).

# Declarations

template< class T >
struct owner_less; /* undefined */

(since C++11) (until C++17)

template< class T = void >
struct owner_less; /* undefined */

(since C++17)

template< class T >
struct owner_less<std::shared_ptr<T>>;

(since C++11)

template< class T >
struct owner_less<std::weak_ptr<T>>;

(since C++11)

template<>
struct owner_less<void>;

(since C++17)

# Parameters

# Return value

true if lhs is less than rhs as determined by the owner-based ordering, false otherwise.

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2873C++11operator() was not required to be noexceptrequired to be noexcept

# See also