Files
2025-10-25 03:02:53 +03:00

2.2 KiB

[util.smartptr.ownerless]

20 Memory management library [mem]

20.3 Smart pointers [smartptr]

20.3.2 Shared-ownership pointers [util.sharedptr]

20.3.2.4 Class template owner_less [util.smartptr.ownerless]

1

#

The class template owner_less allows ownership-based mixed comparisons of shared and weak pointers.

🔗

namespace std {template struct owner_less; template struct owner_less<shared_ptr> {constexpr bool operator()(const shared_ptr&, const shared_ptr&) const noexcept; constexpr bool operator()(const shared_ptr&, const weak_ptr&) const noexcept; constexpr bool operator()(const weak_ptr&, const shared_ptr&) const noexcept; }; template struct owner_less<weak_ptr> {constexpr bool operator()(const weak_ptr&, const weak_ptr&) const noexcept; constexpr bool operator()(const shared_ptr&, const weak_ptr&) const noexcept; constexpr bool operator()(const weak_ptr&, const shared_ptr&) const noexcept; }; template<> struct owner_less {template<class T, class U>constexpr bool operator()(const shared_ptr&, const shared_ptr&) const noexcept; template<class T, class U>constexpr bool operator()(const shared_ptr&, const weak_ptr&) const noexcept; template<class T, class U>constexpr bool operator()(const weak_ptr&, const shared_ptr&) const noexcept; template<class T, class U>constexpr bool operator()(const weak_ptr&, const weak_ptr&) const noexcept; using is_transparent = unspecified; };}

2

#

operator()(x, y) returns x.owner_before(y).

[Note 1:

Note that

operator() defines a strict weak ordering as defined in [alg.sorting];

!operator()(a, b) && !operator()(b, a) is true if and only if a.owner_equal(b) is true.

— end note]