#
The class template owner_less allows ownership-based mixed comparisons of shared and weak pointers.
namespace std { template<class T = void> struct owner_less; template<class T> struct owner_less<shared_ptr<T>> { constexpr bool operator()(const shared_ptr<T>&, const shared_ptr<T>&) const noexcept; constexpr bool operator()(const shared_ptr<T>&, const weak_ptr<T>&) const noexcept; constexpr bool operator()(const weak_ptr<T>&, const shared_ptr<T>&) const noexcept; }; template<class T> struct owner_less<weak_ptr<T>> { constexpr bool operator()(const weak_ptr<T>&, const weak_ptr<T>&) const noexcept; constexpr bool operator()(const shared_ptr<T>&, const weak_ptr<T>&) const noexcept; constexpr bool operator()(const weak_ptr<T>&, const shared_ptr<T>&) const noexcept; }; template<> struct owner_less<void> { template<class T, class U> constexpr bool operator()(const shared_ptr<T>&, const shared_ptr<U>&) const noexcept; template<class T, class U> constexpr bool operator()(const shared_ptr<T>&, const weak_ptr<U>&) const noexcept; template<class T, class U> constexpr bool operator()(const weak_ptr<T>&, const shared_ptr<U>&) const noexcept; template<class T, class U> constexpr bool operator()(const weak_ptr<T>&, const weak_ptr<U>&) 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]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant