[util.smartptr.shared.cmp]

# 20 Memory management library [[mem]](./#mem)

## 20.3 Smart pointers [[smartptr]](smartptr#util.smartptr.shared.cmp)

### 20.3.2 Shared-ownership pointers [[util.sharedptr]](util.sharedptr#util.smartptr.shared.cmp)

#### 20.3.2.2 Class template shared_ptr [[util.smartptr.shared]](util.smartptr.shared#cmp)

#### 20.3.2.2.8 Comparison [util.smartptr.shared.cmp]

[ð](#lib:operator==,shared_ptr)

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

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L4603)

*Returns*: a.get() == b.get()[.](#1.sentence-1)

[ð](#lib:operator==,shared_ptr_)

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

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L4615)

*Returns*: !a[.](#2.sentence-1)

[ð](#lib:operator%3c=%3e,shared_ptr)

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

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L4627)

*Returns*: compare_three_way()(a.get(), b.get())[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L4631)

[*Note [1](#note-1)*:

Defining a comparison operator function allows shared_ptr objects
to be used as keys in associative containers[.](#4.sentence-1)

â *end note*]

[ð](#lib:operator%3c=%3e,shared_ptr_)

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

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L4645)

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