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

228 lines
7.4 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[unique.ptr.special]
# 20 Memory management library [[mem]](./#mem)
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.special)
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#special)
#### 20.3.1.6 Specialized algorithms [unique.ptr.special]
[🔗](#lib:swap(unique_ptr&,_unique_ptr&))
`template<class T, class D> constexpr void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3225)
*Constraints*: is_swappable_v<D> is true[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3229)
*Effects*: Calls x.swap(y)[.](#2.sentence-1)
[🔗](#lib:operator==,unique_ptr)
`template<class T1, class D1, class T2, class D2>
constexpr bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3241)
*Returns*: x.get() == y.get()[.](#3.sentence-1)
[🔗](#lib:operator%3c,unique_ptr)
`template<class T1, class D1, class T2, class D2>
constexpr bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3253)
Let CT denotecommon_type_t<typename unique_ptr<T1, D1>::pointer, typename unique_ptr<T2, D2>::pointer>
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3260)
*Mandates*:
- [(5.1)](#5.1)
unique_ptr<T1, D1>::pointer is implicitly convertible to CT and
- [(5.2)](#5.2)
unique_ptr<T2, D2>::pointer is implicitly convertible to CT[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3267)
*Preconditions*: The specializationless<CT> is a function object type ([[function.objects]](function.objects "22.10Function objects")) that
induces a strict weak ordering ([[alg.sorting]](alg.sorting "26.8Sorting and related operations")) on the pointer values[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3273)
*Returns*: less<CT>()(x.get(), y.get())[.](#7.sentence-1)
[🔗](#lib:operator%3e,unique_ptr)
`template<class T1, class D1, class T2, class D2>
constexpr bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3285)
*Returns*: y < x[.](#8.sentence-1)
[🔗](#lib:operator%3c=,unique_ptr)
`template<class T1, class D1, class T2, class D2>
constexpr bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3297)
*Returns*: !(y < x)[.](#9.sentence-1)
[🔗](#lib:operator%3e=,unique_ptr)
`template<class T1, class D1, class T2, class D2>
constexpr bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3309)
*Returns*: !(x < y)[.](#10.sentence-1)
[🔗](#lib:operator%3c=%3e,unique_ptr)
`template<class T1, class D1, class T2, class D2>
requires [three_way_comparable_with](cmp.concept#concept:three_way_comparable_with "17.12.4Concept three_­way_­comparable[cmp.concept]")<typename unique_ptr<T1, D1>::pointer,
typename unique_ptr<T2, D2>::pointer>
constexpr compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer,
typename unique_ptr<T2, D2>::pointer>
operator<=>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3325)
*Returns*: compare_three_way()(x.get(), y.get())[.](#11.sentence-1)
[🔗](#lib:operator==,unique_ptr_)
`template<class T, class D>
constexpr bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3337)
*Returns*: !x[.](#12.sentence-1)
[🔗](#lib:operator%3c,unique_ptr_)
`template<class T, class D>
constexpr bool operator<(const unique_ptr<T, D>& x, nullptr_t);
template<class T, class D>
constexpr bool operator<(nullptr_t, const unique_ptr<T, D>& x);
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3351)
*Preconditions*: The specialization less<unique_ptr<T, D>::pointer> is
a function object type ([[function.objects]](function.objects "22.10Function objects")) that induces a strict weak
ordering ([[alg.sorting]](alg.sorting "26.8Sorting and related operations")) on the pointer values[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3357)
*Returns*: The first function template returnsless<unique_ptr<T, D>::pointer>()(x.get(), nullptr)
The second function template returnsless<unique_ptr<T, D>::pointer>()(nullptr, x.get())
[🔗](#lib:operator%3e,unique_ptr_)
`template<class T, class D>
constexpr bool operator>(const unique_ptr<T, D>& x, nullptr_t);
template<class T, class D>
constexpr bool operator>(nullptr_t, const unique_ptr<T, D>& x);
`
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3378)
*Returns*: The first function template returns nullptr < x[.](#15.sentence-1)
The second function template returns x < nullptr[.](#15.sentence-2)
[🔗](#lib:operator%3c=,unique_ptr_)
`template<class T, class D>
constexpr bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
template<class T, class D>
constexpr bool operator<=(nullptr_t, const unique_ptr<T, D>& x);
`
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3393)
*Returns*: The first function template returns !(nullptr < x)[.](#16.sentence-1)
The second function template returns !(x < nullptr)[.](#16.sentence-2)
[🔗](#lib:operator%3e=,unique_ptr_)
`template<class T, class D>
constexpr bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
template<class T, class D>
constexpr bool operator>=(nullptr_t, const unique_ptr<T, D>& x);
`
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3408)
*Returns*: The first function template returns !(x < nullptr)[.](#17.sentence-1)
The second function template returns !(nullptr < x)[.](#17.sentence-2)
[🔗](#lib:operator%3c=%3e,unique_ptr_)
`template<class T, class D>
requires [three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4Concept three_­way_­comparable[cmp.concept]")<typename unique_ptr<T, D>::pointer>
constexpr compare_three_way_result_t<typename unique_ptr<T, D>::pointer>
operator<=>(const unique_ptr<T, D>& x, nullptr_t);
`
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3423)
*Returns*: compare_three_way()(x.get(), static_cast<typename unique_ptr<T, D>::pointer>(nullptr)).