Files
cppdraft_translate/cppdraft/util/smartptr/shared/cmp.md
2025-10-25 03:02:53 +03:00

2.0 KiB

[util.smartptr.shared.cmp]

20 Memory management library [mem]

20.3 Smart pointers [smartptr]

20.3.2 Shared-ownership pointers [util.sharedptr]

20.3.2.2 Class template shared_ptr [util.smartptr.shared]

20.3.2.2.8 Comparison [util.smartptr.shared.cmp]

🔗

template<class T, class U> constexpr bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;

1

#

Returns: a.get() == b.get().

🔗

template<class T> constexpr bool operator==(const shared_ptr<T>& a, nullptr_t) noexcept;

2

#

Returns: !a.

🔗

template<class T, class U> constexpr strong_ordering operator<=>(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;

3

#

Returns: compare_three_way()(a.get(), b.get()).

4

#

[Note 1:

Defining a comparison operator function allows shared_ptr objects to be used as keys in associative containers.

— end note]

🔗

template<class T> constexpr strong_ordering operator<=>(const shared_ptr<T>& a, nullptr_t) noexcept;

5

#

Returns: compare_three_way()(a.get(), static_cast<typename shared_ptr::element_type*>(nullptr))