Init
This commit is contained in:
1376
cppdraft/unique/ptr.md
Normal file
1376
cppdraft/unique/ptr.md
Normal file
File diff suppressed because it is too large
Load Diff
99
cppdraft/unique/ptr/create.md
Normal file
99
cppdraft/unique/ptr/create.md
Normal file
@@ -0,0 +1,99 @@
|
||||
[unique.ptr.create]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.create)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#create)
|
||||
|
||||
#### 20.3.1.5 Creation [unique.ptr.create]
|
||||
|
||||
[ð](#lib:make_unique)
|
||||
|
||||
`template<class T, class... Args> constexpr unique_ptr<T> make_unique(Args&&... args);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3138)
|
||||
|
||||
*Constraints*: T is not an array type[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3142)
|
||||
|
||||
*Returns*: unique_ptr<T>(new T(std::forward<Args>(args)...))[.](#2.sentence-1)
|
||||
|
||||
[ð](#lib:make_unique_)
|
||||
|
||||
`template<class T> constexpr unique_ptr<T> make_unique(size_t n);
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3154)
|
||||
|
||||
*Constraints*: T is an array of unknown bound[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3158)
|
||||
|
||||
*Returns*: unique_ptr<T>(new remove_extent_t<T>[n]())[.](#4.sentence-1)
|
||||
|
||||
[ð](#lib:make_unique__)
|
||||
|
||||
`template<class T, class... Args> unspecified make_unique(Args&&...) = delete;
|
||||
`
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3170)
|
||||
|
||||
*Constraints*: T is an array of known bound[.](#5.sentence-1)
|
||||
|
||||
[ð](#lib:make_unique___)
|
||||
|
||||
`template<class T> constexpr unique_ptr<T> make_unique_for_overwrite();
|
||||
`
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3182)
|
||||
|
||||
*Constraints*: T is not an array type[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3186)
|
||||
|
||||
*Returns*: unique_ptr<T>(new T)[.](#7.sentence-1)
|
||||
|
||||
[ð](#lib:make_unique____)
|
||||
|
||||
`template<class T> constexpr unique_ptr<T> make_unique_for_overwrite(size_t n);
|
||||
`
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3197)
|
||||
|
||||
*Constraints*: T is an array of unknown bound[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3201)
|
||||
|
||||
*Returns*: unique_ptr<T>(new remove_extent_t<T>[n])[.](#9.sentence-1)
|
||||
|
||||
[ð](#lib:make_unique_____)
|
||||
|
||||
`template<class T, class... Args> unspecified make_unique_for_overwrite(Args&&...) = delete;
|
||||
`
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3212)
|
||||
|
||||
*Constraints*: T is an array of known bound[.](#10.sentence-1)
|
||||
108
cppdraft/unique/ptr/dltr.md
Normal file
108
cppdraft/unique/ptr/dltr.md
Normal file
@@ -0,0 +1,108 @@
|
||||
[unique.ptr.dltr]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.dltr)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#dltr)
|
||||
|
||||
#### 20.3.1.2 Default deleters [unique.ptr.dltr]
|
||||
|
||||
#### [20.3.1.2.1](#general) General [[unique.ptr.dltr.general]](unique.ptr.dltr.general)
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2258)
|
||||
|
||||
The class template default_delete serves as the default deleter (destruction policy)
|
||||
for the class template unique_ptr[.](#general-1.sentence-1)
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2262)
|
||||
|
||||
The template parameter T of default_delete may be
|
||||
an incomplete type[.](#general-2.sentence-1)
|
||||
|
||||
#### [20.3.1.2.2](#dflt) default_delete [[unique.ptr.dltr.dflt]](unique.ptr.dltr.dflt)
|
||||
|
||||
namespace std {template<class T> struct default_delete {constexpr default_delete() noexcept = default; template<class U> constexpr default_delete(const default_delete<U>&) noexcept; constexpr void operator()(T*) const; };}
|
||||
|
||||
[ð](#lib:default_delete,constructor)
|
||||
|
||||
`template<class U> constexpr default_delete(const default_delete<U>& other) noexcept;
|
||||
`
|
||||
|
||||
[1](#dflt-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2284)
|
||||
|
||||
*Constraints*: U* is implicitly convertible to T*[.](#dflt-1.sentence-1)
|
||||
|
||||
[2](#dflt-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2288)
|
||||
|
||||
*Effects*: Constructs a default_delete object
|
||||
from another default_delete<U> object[.](#dflt-2.sentence-1)
|
||||
|
||||
[ð](#lib:operator(),default_delete)
|
||||
|
||||
`constexpr void operator()(T* ptr) const;
|
||||
`
|
||||
|
||||
[3](#dflt-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2300)
|
||||
|
||||
*Mandates*: T is a complete type[.](#dflt-3.sentence-1)
|
||||
|
||||
[4](#dflt-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2304)
|
||||
|
||||
*Effects*: Calls delete on ptr[.](#dflt-4.sentence-1)
|
||||
|
||||
#### [20.3.1.2.3](#dflt1) default_delete<T[]> [[unique.ptr.dltr.dflt1]](unique.ptr.dltr.dflt1)
|
||||
|
||||
namespace std {template<class T> struct default_delete<T[]> {constexpr default_delete() noexcept = default; template<class U> constexpr default_delete(const default_delete<U[]>&) noexcept; template<class U> constexpr void operator()(U* ptr) const; };}
|
||||
|
||||
[ð](#lib:default_delete,constructor_)
|
||||
|
||||
`template<class U> constexpr default_delete(const default_delete<U[]>& other) noexcept;
|
||||
`
|
||||
|
||||
[1](#dflt1-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2327)
|
||||
|
||||
*Constraints*: U(*)[] is convertible to T(*)[][.](#dflt1-1.sentence-1)
|
||||
|
||||
[2](#dflt1-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2331)
|
||||
|
||||
*Effects*: Constructs a default_delete object from another default_delete<U[]> object[.](#dflt1-2.sentence-1)
|
||||
|
||||
[ð](#lib:operator(),default_delete_)
|
||||
|
||||
`template<class U> constexpr void operator()(U* ptr) const;
|
||||
`
|
||||
|
||||
[3](#dflt1-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2342)
|
||||
|
||||
*Constraints*: U(*)[] is convertible to T(*)[][.](#dflt1-3.sentence-1)
|
||||
|
||||
[4](#dflt1-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2346)
|
||||
|
||||
*Mandates*: U is a complete type[.](#dflt1-4.sentence-1)
|
||||
|
||||
[5](#dflt1-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2350)
|
||||
|
||||
*Effects*: Calls delete[] on ptr[.](#dflt1-5.sentence-1)
|
||||
48
cppdraft/unique/ptr/dltr/dflt.md
Normal file
48
cppdraft/unique/ptr/dltr/dflt.md
Normal file
@@ -0,0 +1,48 @@
|
||||
[unique.ptr.dltr.dflt]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.dltr.dflt)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#dltr.dflt)
|
||||
|
||||
#### 20.3.1.2 Default deleters [[unique.ptr.dltr]](unique.ptr.dltr#dflt)
|
||||
|
||||
#### 20.3.1.2.2 default_delete [unique.ptr.dltr.dflt]
|
||||
|
||||
namespace std {template<class T> struct default_delete {constexpr default_delete() noexcept = default; template<class U> constexpr default_delete(const default_delete<U>&) noexcept; constexpr void operator()(T*) const; };}
|
||||
|
||||
[ð](#lib:default_delete,constructor)
|
||||
|
||||
`template<class U> constexpr default_delete(const default_delete<U>& other) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2284)
|
||||
|
||||
*Constraints*: U* is implicitly convertible to T*[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2288)
|
||||
|
||||
*Effects*: Constructs a default_delete object
|
||||
from another default_delete<U> object[.](#2.sentence-1)
|
||||
|
||||
[ð](#lib:operator(),default_delete)
|
||||
|
||||
`constexpr void operator()(T* ptr) const;
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2300)
|
||||
|
||||
*Mandates*: T is a complete type[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2304)
|
||||
|
||||
*Effects*: Calls delete on ptr[.](#4.sentence-1)
|
||||
53
cppdraft/unique/ptr/dltr/dflt1.md
Normal file
53
cppdraft/unique/ptr/dltr/dflt1.md
Normal file
@@ -0,0 +1,53 @@
|
||||
[unique.ptr.dltr.dflt1]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.dltr.dflt1)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#dltr.dflt1)
|
||||
|
||||
#### 20.3.1.2 Default deleters [[unique.ptr.dltr]](unique.ptr.dltr#dflt1)
|
||||
|
||||
#### 20.3.1.2.3 default_delete<T[]> [unique.ptr.dltr.dflt1]
|
||||
|
||||
namespace std {template<class T> struct default_delete<T[]> {constexpr default_delete() noexcept = default; template<class U> constexpr default_delete(const default_delete<U[]>&) noexcept; template<class U> constexpr void operator()(U* ptr) const; };}
|
||||
|
||||
[ð](#lib:default_delete,constructor)
|
||||
|
||||
`template<class U> constexpr default_delete(const default_delete<U[]>& other) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2327)
|
||||
|
||||
*Constraints*: U(*)[] is convertible to T(*)[][.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2331)
|
||||
|
||||
*Effects*: Constructs a default_delete object from another default_delete<U[]> object[.](#2.sentence-1)
|
||||
|
||||
[ð](#lib:operator(),default_delete)
|
||||
|
||||
`template<class U> constexpr void operator()(U* ptr) const;
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2342)
|
||||
|
||||
*Constraints*: U(*)[] is convertible to T(*)[][.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2346)
|
||||
|
||||
*Mandates*: U is a complete type[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2350)
|
||||
|
||||
*Effects*: Calls delete[] on ptr[.](#5.sentence-1)
|
||||
25
cppdraft/unique/ptr/dltr/general.md
Normal file
25
cppdraft/unique/ptr/dltr/general.md
Normal file
@@ -0,0 +1,25 @@
|
||||
[unique.ptr.dltr.general]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.dltr.general)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#dltr.general)
|
||||
|
||||
#### 20.3.1.2 Default deleters [[unique.ptr.dltr]](unique.ptr.dltr#general)
|
||||
|
||||
#### 20.3.1.2.1 General [unique.ptr.dltr.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2258)
|
||||
|
||||
The class template default_delete serves as the default deleter (destruction policy)
|
||||
for the class template unique_ptr[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2262)
|
||||
|
||||
The template parameter T of default_delete may be
|
||||
an incomplete type[.](#2.sentence-1)
|
||||
68
cppdraft/unique/ptr/general.md
Normal file
68
cppdraft/unique/ptr/general.md
Normal file
@@ -0,0 +1,68 @@
|
||||
[unique.ptr.general]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.general)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#general)
|
||||
|
||||
#### 20.3.1.1 General [unique.ptr.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2217)
|
||||
|
||||
A [*unique pointer*](#def:unique_pointer "20.3.1.1 General [unique.ptr.general]") is an object that owns another object and
|
||||
manages that other object through a pointer[.](#1.sentence-1)
|
||||
|
||||
More precisely, a unique pointer
|
||||
is an object *u* that stores a pointer to a second object *p* and
|
||||
will dispose of *p* when *u* is itself destroyed (e.g., when
|
||||
leaving block scope ([[stmt.dcl]](stmt.dcl "8.10 Declaration statement")))[.](#1.sentence-2)
|
||||
|
||||
In this context, *u* is said
|
||||
to [*own*](#def:own "20.3.1.1 General [unique.ptr.general]") p[.](#1.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2225)
|
||||
|
||||
The mechanism by which *u* disposes of *p* is known as*p*'s associated [*deleter*](#def:deleter "20.3.1.1 General [unique.ptr.general]"), a function object whose correct
|
||||
invocation results in *p*'s appropriate disposition (typically its deletion)[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2230)
|
||||
|
||||
Let the notation *u.p* denote the pointer stored by *u*, and
|
||||
let *u.d* denote the associated deleter[.](#3.sentence-1)
|
||||
|
||||
Upon request, *u* can[*reset*](#def:reset "20.3.1.1 General [unique.ptr.general]") (replace) *u.p* and *u.d* with another pointer and
|
||||
deleter, but properly disposes of its owned object via the associated
|
||||
deleter before such replacement is considered completed[.](#3.sentence-2)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2237)
|
||||
|
||||
Each object of a type U instantiated from the unique_ptr template
|
||||
specified in [[unique.ptr]](unique.ptr "20.3.1 Unique-ownership pointers") has the strict ownership semantics, specified above,
|
||||
of a unique pointer[.](#4.sentence-1)
|
||||
|
||||
In partial satisfaction of these semantics, each such U is [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") and [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]"), but is not[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") nor [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]")[.](#4.sentence-2)
|
||||
|
||||
The template parameter T of unique_ptr may be an incomplete type[.](#4.sentence-3)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2245)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The uses
|
||||
of unique_ptr include providing exception safety for
|
||||
dynamically allocated memory, passing ownership of dynamically allocated
|
||||
memory to a function, and returning dynamically allocated memory from a
|
||||
function[.](#5.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
33
cppdraft/unique/ptr/io.md
Normal file
33
cppdraft/unique/ptr/io.md
Normal file
@@ -0,0 +1,33 @@
|
||||
[unique.ptr.io]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.io)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#io)
|
||||
|
||||
#### 20.3.1.7 I/O [unique.ptr.io]
|
||||
|
||||
[ð](#lib:operator%3c%3c,unique_ptr)
|
||||
|
||||
`template<class E, class T, class Y, class D>
|
||||
basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os, const unique_ptr<Y, D>& p);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3439)
|
||||
|
||||
*Constraints*: os << p.get() is a valid expression[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3443)
|
||||
|
||||
*Effects*: Equivalent to: os << p.get();
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3447)
|
||||
|
||||
*Returns*: os[.](#3.sentence-1)
|
||||
268
cppdraft/unique/ptr/runtime.md
Normal file
268
cppdraft/unique/ptr/runtime.md
Normal file
@@ -0,0 +1,268 @@
|
||||
[unique.ptr.runtime]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.runtime)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#runtime)
|
||||
|
||||
#### 20.3.1.4 unique_ptr for array objects with a runtime length [unique.ptr.runtime]
|
||||
|
||||
#### [20.3.1.4.1](#general) General [[unique.ptr.runtime.general]](unique.ptr.runtime.general)
|
||||
|
||||
[ð](#lib:unique_ptr)
|
||||
|
||||
namespace std {template<class T, class D> class unique_ptr<T[], D> {public:using pointer = *see below*; using element_type = T; using deleter_type = D; // [[unique.ptr.runtime.ctor]](#ctor "20.3.1.4.2 Constructors"), constructorsconstexpr unique_ptr() noexcept; template<class U> constexpr explicit unique_ptr(U p) noexcept; template<class U> constexpr unique_ptr(U p, *see below* d) noexcept; template<class U> constexpr unique_ptr(U p, *see below* d) noexcept; constexpr unique_ptr(unique_ptr&& u) noexcept; template<class U, class E>constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept; constexpr unique_ptr(nullptr_t) noexcept; // destructorconstexpr ~unique_ptr(); // assignmentconstexpr unique_ptr& operator=(unique_ptr&& u) noexcept; template<class U, class E>constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; constexpr unique_ptr& operator=(nullptr_t) noexcept; // [[unique.ptr.runtime.observers]](#observers "20.3.1.4.4 Observers"), observersconstexpr T& operator[](size_t i) const; constexpr pointer get() const noexcept; constexpr deleter_type& get_deleter() noexcept; constexpr const deleter_type& get_deleter() const noexcept; constexpr explicit operator bool() const noexcept; // [[unique.ptr.runtime.modifiers]](#modifiers "20.3.1.4.5 Modifiers"), modifiersconstexpr pointer release() noexcept; template<class U> constexpr void reset(U p) noexcept; constexpr void reset(nullptr_t = nullptr) noexcept; constexpr void swap(unique_ptr& u) noexcept; // disable copy from lvalue unique_ptr(const unique_ptr&) = delete;
|
||||
unique_ptr& operator=(const unique_ptr&) = delete; };}
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2950)
|
||||
|
||||
A specialization for array types is provided with a slightly altered
|
||||
interface[.](#general-1.sentence-1)
|
||||
|
||||
- [(1.1)](#general-1.1)
|
||||
|
||||
Conversions between different types ofunique_ptr<T[], D> that would be disallowed for the corresponding pointer-to-array types,
|
||||
and conversions to or from the non-array forms ofunique_ptr, produce an ill-formed program[.](#general-1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#general-1.2)
|
||||
|
||||
Pointers to types derived from T are
|
||||
rejected by the constructors, and by reset[.](#general-1.2.sentence-1)
|
||||
|
||||
- [(1.3)](#general-1.3)
|
||||
|
||||
The observers operator* andoperator-> are not provided[.](#general-1.3.sentence-1)
|
||||
|
||||
- [(1.4)](#general-1.4)
|
||||
|
||||
The indexing observer operator[] is provided[.](#general-1.4.sentence-1)
|
||||
|
||||
- [(1.5)](#general-1.5)
|
||||
|
||||
The default deleter will call delete[][.](#general-1.5.sentence-1)
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2972)
|
||||
|
||||
Descriptions are provided below only for members that
|
||||
differ from the primary template[.](#general-2.sentence-1)
|
||||
|
||||
[3](#general-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2976)
|
||||
|
||||
The template argument T shall be a complete type[.](#general-3.sentence-1)
|
||||
|
||||
#### [20.3.1.4.2](#ctor) Constructors [[unique.ptr.runtime.ctor]](unique.ptr.runtime.ctor)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor)
|
||||
|
||||
`template<class U> constexpr explicit unique_ptr(U p) noexcept;
|
||||
`
|
||||
|
||||
[1](#ctor-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2987)
|
||||
|
||||
This constructor behaves the same as
|
||||
the constructor in the primary template that
|
||||
takes a single parameter of type pointer[.](#ctor-1.sentence-1)
|
||||
|
||||
[2](#ctor-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2992)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(2.1)](#ctor-2.1)
|
||||
|
||||
U is the same type as pointer, or
|
||||
|
||||
- [(2.2)](#ctor-2.2)
|
||||
|
||||
pointer is the same type as element_type*,U is a pointer type V*, andV(*)[] is convertible to element_type(*)[][.](#ctor-2.sentence-1)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor_)
|
||||
|
||||
`template<class U> constexpr unique_ptr(U p, see below d) noexcept;
|
||||
template<class U> constexpr unique_ptr(U p, see below d) noexcept;
|
||||
`
|
||||
|
||||
[3](#ctor-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3009)
|
||||
|
||||
These constructors behave the same as
|
||||
the constructors in the primary template that
|
||||
take a parameter of type pointer and a second parameter[.](#ctor-3.sentence-1)
|
||||
|
||||
[4](#ctor-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3014)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(4.1)](#ctor-4.1)
|
||||
|
||||
U is the same type as pointer,
|
||||
|
||||
- [(4.2)](#ctor-4.2)
|
||||
|
||||
U is nullptr_t, or
|
||||
|
||||
- [(4.3)](#ctor-4.3)
|
||||
|
||||
pointer is the same type as element_type*, U is a pointer type V*, and V(*)[] is convertible to element_type(*)[][.](#ctor-4.sentence-1)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor__)
|
||||
|
||||
`template<class U, class E> constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
||||
`
|
||||
|
||||
[5](#ctor-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3031)
|
||||
|
||||
This constructor behaves the same as in the primary template[.](#ctor-5.sentence-1)
|
||||
|
||||
[6](#ctor-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3034)
|
||||
|
||||
*Constraints*: Where UP is unique_ptr<U, E>:
|
||||
|
||||
- [(6.1)](#ctor-6.1)
|
||||
|
||||
U is an array type, and
|
||||
|
||||
- [(6.2)](#ctor-6.2)
|
||||
|
||||
pointer is the same type as element_type*, and
|
||||
|
||||
- [(6.3)](#ctor-6.3)
|
||||
|
||||
UP::pointer is the same type as UP::element_type*, and
|
||||
|
||||
- [(6.4)](#ctor-6.4)
|
||||
|
||||
UP::element_type(*)[] is convertible to element_type(*)[], and
|
||||
|
||||
- [(6.5)](#ctor-6.5)
|
||||
|
||||
either D is a reference type and E is the same type as D,
|
||||
or D is not a reference type and E is implicitly convertible to D[.](#ctor-6.sentence-1)
|
||||
|
||||
[*Note [1](#ctor-note-1)*:
|
||||
|
||||
This replaces the *Constraints*: specification of the primary template[.](#ctor-6.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
#### [20.3.1.4.3](#asgn) Assignment [[unique.ptr.runtime.asgn]](unique.ptr.runtime.asgn)
|
||||
|
||||
[ð](#lib:operator=,unique_ptr)
|
||||
|
||||
`template<class U, class E> constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
||||
`
|
||||
|
||||
[1](#asgn-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3059)
|
||||
|
||||
This operator behaves the same as in the primary template[.](#asgn-1.sentence-1)
|
||||
|
||||
[2](#asgn-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3062)
|
||||
|
||||
*Constraints*: Where UP is unique_ptr<U, E>:
|
||||
|
||||
- [(2.1)](#asgn-2.1)
|
||||
|
||||
U is an array type, and
|
||||
|
||||
- [(2.2)](#asgn-2.2)
|
||||
|
||||
pointer is the same type as element_type*, and
|
||||
|
||||
- [(2.3)](#asgn-2.3)
|
||||
|
||||
UP::pointer is the same type as UP::element_type*, and
|
||||
|
||||
- [(2.4)](#asgn-2.4)
|
||||
|
||||
UP::element_type(*)[] is convertible to element_type(*)[], and
|
||||
|
||||
- [(2.5)](#asgn-2.5)
|
||||
|
||||
is_assignable_v<D&, E&&> is true[.](#asgn-2.sentence-1)
|
||||
|
||||
[*Note [1](#asgn-note-1)*:
|
||||
|
||||
This replaces the *Constraints*: specification of the primary template[.](#asgn-2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
#### [20.3.1.4.4](#observers) Observers [[unique.ptr.runtime.observers]](unique.ptr.runtime.observers)
|
||||
|
||||
[ð](#lib:operator%5b%5d,unique_ptr)
|
||||
|
||||
`constexpr T& operator[](size_t i) const;
|
||||
`
|
||||
|
||||
[1](#observers-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3086)
|
||||
|
||||
*Preconditions*: i < the
|
||||
number of elements in the array to which
|
||||
the stored pointer points[.](#observers-1.sentence-1)
|
||||
|
||||
[2](#observers-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3092)
|
||||
|
||||
*Returns*: get()[i][.](#observers-2.sentence-1)
|
||||
|
||||
#### [20.3.1.4.5](#modifiers) Modifiers [[unique.ptr.runtime.modifiers]](unique.ptr.runtime.modifiers)
|
||||
|
||||
[ð](#lib:reset,unique_ptr)
|
||||
|
||||
`constexpr void reset(nullptr_t p = nullptr) noexcept;
|
||||
`
|
||||
|
||||
[1](#modifiers-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3105)
|
||||
|
||||
*Effects*: Equivalent to reset(pointer())[.](#modifiers-1.sentence-1)
|
||||
|
||||
[ð](#lib:reset,unique_ptr_)
|
||||
|
||||
`template<class U> constexpr void reset(U p) noexcept;
|
||||
`
|
||||
|
||||
[2](#modifiers-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3116)
|
||||
|
||||
This function behaves the same as
|
||||
the reset member of the primary template[.](#modifiers-2.sentence-1)
|
||||
|
||||
[3](#modifiers-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3120)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(3.1)](#modifiers-3.1)
|
||||
|
||||
U is the same type as pointer, or
|
||||
|
||||
- [(3.2)](#modifiers-3.2)
|
||||
|
||||
pointer is the same type as element_type*, U is a pointer type V*, and V(*)[] is convertible to element_type(*)[][.](#modifiers-3.sentence-1)
|
||||
54
cppdraft/unique/ptr/runtime/asgn.md
Normal file
54
cppdraft/unique/ptr/runtime/asgn.md
Normal file
@@ -0,0 +1,54 @@
|
||||
[unique.ptr.runtime.asgn]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.runtime.asgn)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#runtime.asgn)
|
||||
|
||||
#### 20.3.1.4 unique_ptr for array objects with a runtime length [[unique.ptr.runtime]](unique.ptr.runtime#asgn)
|
||||
|
||||
#### 20.3.1.4.3 Assignment [unique.ptr.runtime.asgn]
|
||||
|
||||
[ð](#lib:operator=,unique_ptr)
|
||||
|
||||
`template<class U, class E> constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3059)
|
||||
|
||||
This operator behaves the same as in the primary template[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3062)
|
||||
|
||||
*Constraints*: Where UP is unique_ptr<U, E>:
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
U is an array type, and
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
pointer is the same type as element_type*, and
|
||||
|
||||
- [(2.3)](#2.3)
|
||||
|
||||
UP::pointer is the same type as UP::element_type*, and
|
||||
|
||||
- [(2.4)](#2.4)
|
||||
|
||||
UP::element_type(*)[] is convertible to element_type(*)[], and
|
||||
|
||||
- [(2.5)](#2.5)
|
||||
|
||||
is_assignable_v<D&, E&&> is true[.](#2.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
This replaces the *Constraints*: specification of the primary template[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
114
cppdraft/unique/ptr/runtime/ctor.md
Normal file
114
cppdraft/unique/ptr/runtime/ctor.md
Normal file
@@ -0,0 +1,114 @@
|
||||
[unique.ptr.runtime.ctor]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.runtime.ctor)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#runtime.ctor)
|
||||
|
||||
#### 20.3.1.4 unique_ptr for array objects with a runtime length [[unique.ptr.runtime]](unique.ptr.runtime#ctor)
|
||||
|
||||
#### 20.3.1.4.2 Constructors [unique.ptr.runtime.ctor]
|
||||
|
||||
[ð](#lib:unique_ptr,constructor)
|
||||
|
||||
`template<class U> constexpr explicit unique_ptr(U p) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2987)
|
||||
|
||||
This constructor behaves the same as
|
||||
the constructor in the primary template that
|
||||
takes a single parameter of type pointer[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2992)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
U is the same type as pointer, or
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
pointer is the same type as element_type*,U is a pointer type V*, andV(*)[] is convertible to element_type(*)[][.](#2.sentence-1)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor_)
|
||||
|
||||
`template<class U> constexpr unique_ptr(U p, see below d) noexcept;
|
||||
template<class U> constexpr unique_ptr(U p, see below d) noexcept;
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3009)
|
||||
|
||||
These constructors behave the same as
|
||||
the constructors in the primary template that
|
||||
take a parameter of type pointer and a second parameter[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3014)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
U is the same type as pointer,
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
U is nullptr_t, or
|
||||
|
||||
- [(4.3)](#4.3)
|
||||
|
||||
pointer is the same type as element_type*, U is a pointer type V*, and V(*)[] is convertible to element_type(*)[][.](#4.sentence-1)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor__)
|
||||
|
||||
`template<class U, class E> constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
||||
`
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3031)
|
||||
|
||||
This constructor behaves the same as in the primary template[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3034)
|
||||
|
||||
*Constraints*: Where UP is unique_ptr<U, E>:
|
||||
|
||||
- [(6.1)](#6.1)
|
||||
|
||||
U is an array type, and
|
||||
|
||||
- [(6.2)](#6.2)
|
||||
|
||||
pointer is the same type as element_type*, and
|
||||
|
||||
- [(6.3)](#6.3)
|
||||
|
||||
UP::pointer is the same type as UP::element_type*, and
|
||||
|
||||
- [(6.4)](#6.4)
|
||||
|
||||
UP::element_type(*)[] is convertible to element_type(*)[], and
|
||||
|
||||
- [(6.5)](#6.5)
|
||||
|
||||
either D is a reference type and E is the same type as D,
|
||||
or D is not a reference type and E is implicitly convertible to D[.](#6.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
This replaces the *Constraints*: specification of the primary template[.](#6.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
58
cppdraft/unique/ptr/runtime/general.md
Normal file
58
cppdraft/unique/ptr/runtime/general.md
Normal file
@@ -0,0 +1,58 @@
|
||||
[unique.ptr.runtime.general]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.runtime.general)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#runtime.general)
|
||||
|
||||
#### 20.3.1.4 unique_ptr for array objects with a runtime length [[unique.ptr.runtime]](unique.ptr.runtime#general)
|
||||
|
||||
#### 20.3.1.4.1 General [unique.ptr.runtime.general]
|
||||
|
||||
[ð](#lib:unique_ptr)
|
||||
|
||||
namespace std {template<class T, class D> class unique_ptr<T[], D> {public:using pointer = *see below*; using element_type = T; using deleter_type = D; // [[unique.ptr.runtime.ctor]](unique.ptr.runtime.ctor "20.3.1.4.2 Constructors"), constructorsconstexpr unique_ptr() noexcept; template<class U> constexpr explicit unique_ptr(U p) noexcept; template<class U> constexpr unique_ptr(U p, *see below* d) noexcept; template<class U> constexpr unique_ptr(U p, *see below* d) noexcept; constexpr unique_ptr(unique_ptr&& u) noexcept; template<class U, class E>constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept; constexpr unique_ptr(nullptr_t) noexcept; // destructorconstexpr ~unique_ptr(); // assignmentconstexpr unique_ptr& operator=(unique_ptr&& u) noexcept; template<class U, class E>constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; constexpr unique_ptr& operator=(nullptr_t) noexcept; // [[unique.ptr.runtime.observers]](unique.ptr.runtime.observers "20.3.1.4.4 Observers"), observersconstexpr T& operator[](size_t i) const; constexpr pointer get() const noexcept; constexpr deleter_type& get_deleter() noexcept; constexpr const deleter_type& get_deleter() const noexcept; constexpr explicit operator bool() const noexcept; // [[unique.ptr.runtime.modifiers]](unique.ptr.runtime.modifiers "20.3.1.4.5 Modifiers"), modifiersconstexpr pointer release() noexcept; template<class U> constexpr void reset(U p) noexcept; constexpr void reset(nullptr_t = nullptr) noexcept; constexpr void swap(unique_ptr& u) noexcept; // disable copy from lvalue unique_ptr(const unique_ptr&) = delete;
|
||||
unique_ptr& operator=(const unique_ptr&) = delete; };}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2950)
|
||||
|
||||
A specialization for array types is provided with a slightly altered
|
||||
interface[.](#1.sentence-1)
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
Conversions between different types ofunique_ptr<T[], D> that would be disallowed for the corresponding pointer-to-array types,
|
||||
and conversions to or from the non-array forms ofunique_ptr, produce an ill-formed program[.](#1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
Pointers to types derived from T are
|
||||
rejected by the constructors, and by reset[.](#1.2.sentence-1)
|
||||
|
||||
- [(1.3)](#1.3)
|
||||
|
||||
The observers operator* andoperator-> are not provided[.](#1.3.sentence-1)
|
||||
|
||||
- [(1.4)](#1.4)
|
||||
|
||||
The indexing observer operator[] is provided[.](#1.4.sentence-1)
|
||||
|
||||
- [(1.5)](#1.5)
|
||||
|
||||
The default deleter will call delete[][.](#1.5.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2972)
|
||||
|
||||
Descriptions are provided below only for members that
|
||||
differ from the primary template[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2976)
|
||||
|
||||
The template argument T shall be a complete type[.](#3.sentence-1)
|
||||
48
cppdraft/unique/ptr/runtime/modifiers.md
Normal file
48
cppdraft/unique/ptr/runtime/modifiers.md
Normal file
@@ -0,0 +1,48 @@
|
||||
[unique.ptr.runtime.modifiers]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.runtime.modifiers)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#runtime.modifiers)
|
||||
|
||||
#### 20.3.1.4 unique_ptr for array objects with a runtime length [[unique.ptr.runtime]](unique.ptr.runtime#modifiers)
|
||||
|
||||
#### 20.3.1.4.5 Modifiers [unique.ptr.runtime.modifiers]
|
||||
|
||||
[ð](#lib:reset,unique_ptr)
|
||||
|
||||
`constexpr void reset(nullptr_t p = nullptr) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3105)
|
||||
|
||||
*Effects*: Equivalent to reset(pointer())[.](#1.sentence-1)
|
||||
|
||||
[ð](#lib:reset,unique_ptr_)
|
||||
|
||||
`template<class U> constexpr void reset(U p) noexcept;
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3116)
|
||||
|
||||
This function behaves the same as
|
||||
the reset member of the primary template[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3120)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
U is the same type as pointer, or
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
pointer is the same type as element_type*, U is a pointer type V*, and V(*)[] is convertible to element_type(*)[][.](#3.sentence-1)
|
||||
30
cppdraft/unique/ptr/runtime/observers.md
Normal file
30
cppdraft/unique/ptr/runtime/observers.md
Normal file
@@ -0,0 +1,30 @@
|
||||
[unique.ptr.runtime.observers]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.runtime.observers)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#runtime.observers)
|
||||
|
||||
#### 20.3.1.4 unique_ptr for array objects with a runtime length [[unique.ptr.runtime]](unique.ptr.runtime#observers)
|
||||
|
||||
#### 20.3.1.4.4 Observers [unique.ptr.runtime.observers]
|
||||
|
||||
[ð](#lib:operator%5b%5d,unique_ptr)
|
||||
|
||||
`constexpr T& operator[](size_t i) const;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3086)
|
||||
|
||||
*Preconditions*: i < the
|
||||
number of elements in the array to which
|
||||
the stored pointer points[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L3092)
|
||||
|
||||
*Returns*: get()[i][.](#2.sentence-1)
|
||||
615
cppdraft/unique/ptr/single.md
Normal file
615
cppdraft/unique/ptr/single.md
Normal file
@@ -0,0 +1,615 @@
|
||||
[unique.ptr.single]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.single)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#single)
|
||||
|
||||
#### 20.3.1.3 unique_ptr for single objects [unique.ptr.single]
|
||||
|
||||
#### [20.3.1.3.1](#general) General [[unique.ptr.single.general]](unique.ptr.single.general)
|
||||
|
||||
[ð](#lib:unique_ptr)
|
||||
|
||||
namespace std {template<class T, class D = default_delete<T>> class unique_ptr {public:using pointer = *see below*; using element_type = T; using deleter_type = D; // [[unique.ptr.single.ctor]](#ctor "20.3.1.3.2 Constructors"), constructorsconstexpr unique_ptr() noexcept; constexpr explicit unique_ptr(type_identity_t<pointer> p) noexcept; constexpr unique_ptr(type_identity_t<pointer> p, *see below* d1) noexcept; constexpr unique_ptr(type_identity_t<pointer> p, *see below* d2) noexcept; constexpr unique_ptr(unique_ptr&& u) noexcept; constexpr unique_ptr(nullptr_t) noexcept; template<class U, class E>constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept; // [[unique.ptr.single.dtor]](#dtor "20.3.1.3.3 Destructor"), destructorconstexpr ~unique_ptr(); // [[unique.ptr.single.asgn]](#asgn "20.3.1.3.4 Assignment"), assignmentconstexpr unique_ptr& operator=(unique_ptr&& u) noexcept; template<class U, class E>constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; constexpr unique_ptr& operator=(nullptr_t) noexcept; // [[unique.ptr.single.observers]](#observers "20.3.1.3.5 Observers"), observersconstexpr add_lvalue_reference_t<T> operator*() const noexcept(*see below*); constexpr pointer operator->() const noexcept; constexpr pointer get() const noexcept; constexpr deleter_type& get_deleter() noexcept; constexpr const deleter_type& get_deleter() const noexcept; constexpr explicit operator bool() const noexcept; // [[unique.ptr.single.modifiers]](#modifiers "20.3.1.3.6 Modifiers"), modifiersconstexpr pointer release() noexcept; constexpr void reset(pointer p = pointer()) noexcept; constexpr void swap(unique_ptr& u) noexcept; // disable copy from lvalue unique_ptr(const unique_ptr&) = delete;
|
||||
unique_ptr& operator=(const unique_ptr&) = delete; };}
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2407)
|
||||
|
||||
A program that instantiates the definition of unique_ptr<T, D> is ill-formed if T* is an invalid type[.](#general-1.sentence-1)
|
||||
|
||||
[*Note [1](#general-note-1)*:
|
||||
|
||||
This prevents the instantiation of specializations such asunique_ptr<T&, D> and unique_ptr<int() const, D>[.](#general-1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2415)
|
||||
|
||||
The default type for the template parameter D isdefault_delete[.](#general-2.sentence-1)
|
||||
|
||||
A client-supplied template argumentD shall be a function
|
||||
object type ([[function.objects]](function.objects "22.10 Function objects")), lvalue reference to function, or
|
||||
lvalue reference to function object type
|
||||
for which, given
|
||||
a value d of type D and a valueptr of type unique_ptr<T, D>::pointer, the expressiond(ptr) is valid and has the effect of disposing of the
|
||||
pointer as appropriate for that deleter[.](#general-2.sentence-2)
|
||||
|
||||
[3](#general-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2427)
|
||||
|
||||
If the deleter's type D is not a reference type, D shall meet
|
||||
the [*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [35](utility.arg.requirements#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements"))[.](#general-3.sentence-1)
|
||||
|
||||
[4](#general-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2431)
|
||||
|
||||
If the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") remove_reference_t<D>::pointer is valid and denotes a
|
||||
type ([[temp.deduct]](temp.deduct "13.10.3 Template argument deduction")), then unique_ptr<T,
|
||||
D>::pointer shall be a synonym for remove_reference_t<D>::pointer[.](#general-4.sentence-1)
|
||||
|
||||
Otherwiseunique_ptr<T, D>::pointer shall be a synonym for element_type*[.](#general-4.sentence-2)
|
||||
|
||||
The type unique_ptr<T,
|
||||
D>::pointer shall
|
||||
meet the [*Cpp17NullablePointer*](nullablepointer.requirements#:Cpp17NullablePointer "16.4.4.4 Cpp17NullablePointer requirements [nullablepointer.requirements]") requirements (Table [36](nullablepointer.requirements#tab:cpp17.nullablepointer "Table 36: Cpp17NullablePointer requirements"))[.](#general-4.sentence-3)
|
||||
|
||||
[5](#general-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2439)
|
||||
|
||||
[*Example [1](#general-example-1)*:
|
||||
|
||||
Given an allocator type X ([[allocator.requirements.general]](allocator.requirements.general "16.4.4.6.1 General")) and
|
||||
letting A be a synonym for allocator_traits<X>, the types A::pointer,A::const_pointer, A::void_pointer, and A::const_void_pointer may be used as unique_ptr<T, D>::pointer[.](#general-5.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
|
||||
#### [20.3.1.3.2](#ctor) Constructors [[unique.ptr.single.ctor]](unique.ptr.single.ctor)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor)
|
||||
|
||||
`constexpr unique_ptr() noexcept;
|
||||
constexpr unique_ptr(nullptr_t) noexcept;
|
||||
`
|
||||
|
||||
[1](#ctor-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2456)
|
||||
|
||||
*Constraints*: is_pointer_v<deleter_type> is false andis_default_constructible_v<deleter_type> is true[.](#ctor-1.sentence-1)
|
||||
|
||||
[2](#ctor-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2461)
|
||||
|
||||
*Preconditions*: D meets the [*Cpp17DefaultConstructible*](utility.arg.requirements#:Cpp17DefaultConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [30](utility.arg.requirements#tab:cpp17.defaultconstructible "Table 30: Cpp17DefaultConstructible requirements")),
|
||||
and that construction does not throw an exception[.](#ctor-2.sentence-1)
|
||||
|
||||
[3](#ctor-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2466)
|
||||
|
||||
*Effects*: Constructs a unique_ptr object that owns
|
||||
nothing, value-initializing the stored pointer and the stored deleter[.](#ctor-3.sentence-1)
|
||||
|
||||
[4](#ctor-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2471)
|
||||
|
||||
*Postconditions*: get() == nullptr[.](#ctor-4.sentence-1)
|
||||
|
||||
get_deleter() returns a reference to the stored deleter[.](#ctor-4.sentence-2)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor_)
|
||||
|
||||
`constexpr explicit unique_ptr(type_identity_t<pointer> p) noexcept;
|
||||
`
|
||||
|
||||
[5](#ctor-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2483)
|
||||
|
||||
*Constraints*: is_pointer_v<deleter_type> is false andis_default_constructible_v<deleter_type> is true[.](#ctor-5.sentence-1)
|
||||
|
||||
[6](#ctor-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2488)
|
||||
|
||||
*Preconditions*: D meets the [*Cpp17DefaultConstructible*](utility.arg.requirements#:Cpp17DefaultConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [30](utility.arg.requirements#tab:cpp17.defaultconstructible "Table 30: Cpp17DefaultConstructible requirements")),
|
||||
and that construction does not throw an exception[.](#ctor-6.sentence-1)
|
||||
|
||||
[7](#ctor-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2493)
|
||||
|
||||
*Effects*: Constructs a unique_ptr which ownsp, initializing the stored pointer with p and
|
||||
value-initializing the stored deleter[.](#ctor-7.sentence-1)
|
||||
|
||||
[8](#ctor-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2499)
|
||||
|
||||
*Postconditions*: get() == p[.](#ctor-8.sentence-1)
|
||||
|
||||
get_deleter() returns a reference to the stored deleter[.](#ctor-8.sentence-2)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor__)
|
||||
|
||||
`constexpr unique_ptr(type_identity_t<pointer> p, const D& d) noexcept;
|
||||
constexpr unique_ptr(type_identity_t<pointer> p, remove_reference_t<D>&& d) noexcept;
|
||||
`
|
||||
|
||||
[9](#ctor-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2512)
|
||||
|
||||
*Constraints*: is_constructible_v<D, decltype(d)> is true[.](#ctor-9.sentence-1)
|
||||
|
||||
[10](#ctor-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2516)
|
||||
|
||||
*Preconditions*: For the first constructor, if D is not a reference type,D meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements and
|
||||
such construction does not exit via an exception[.](#ctor-10.sentence-1)
|
||||
|
||||
For the second constructor, if D is not a reference type,D meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements and
|
||||
such construction does not exit via an exception[.](#ctor-10.sentence-2)
|
||||
|
||||
[11](#ctor-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2525)
|
||||
|
||||
*Effects*: Constructs a unique_ptr object which owns p, initializing
|
||||
the stored pointer with p and initializing the deleter
|
||||
from std::forward<decltype(d)>(d)[.](#ctor-11.sentence-1)
|
||||
|
||||
[12](#ctor-12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2531)
|
||||
|
||||
*Postconditions*: get() == p[.](#ctor-12.sentence-1)
|
||||
|
||||
get_deleter() returns a reference to the stored
|
||||
deleter[.](#ctor-12.sentence-2)
|
||||
|
||||
If D is a reference type then get_deleter() returns a reference to the lvalue d[.](#ctor-12.sentence-3)
|
||||
|
||||
[13](#ctor-13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2538)
|
||||
|
||||
*Remarks*: If D is a reference type,
|
||||
the second constructor is defined as deleted[.](#ctor-13.sentence-1)
|
||||
|
||||
[14](#ctor-14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2543)
|
||||
|
||||
[*Example [1](#ctor-example-1)*: D d;
|
||||
unique_ptr<int, D> p1(new int, D()); // D must be [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") unique_ptr<int, D> p2(new int, d); // D must be [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined// with reference deleter type â *end example*]
|
||||
|
||||
[ð](#lib:unique_ptr,constructor___)
|
||||
|
||||
`constexpr unique_ptr(unique_ptr&& u) noexcept;
|
||||
`
|
||||
|
||||
[15](#ctor-15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2562)
|
||||
|
||||
*Constraints*: is_move_constructible_v<D> is true[.](#ctor-15.sentence-1)
|
||||
|
||||
[16](#ctor-16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2566)
|
||||
|
||||
*Preconditions*: If D is not a reference type,D meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements"))[.](#ctor-16.sentence-1)
|
||||
|
||||
Construction
|
||||
of the deleter from an rvalue of type D does not
|
||||
throw an exception[.](#ctor-16.sentence-2)
|
||||
|
||||
[17](#ctor-17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2575)
|
||||
|
||||
*Effects*: Constructs a unique_ptr fromu[.](#ctor-17.sentence-1)
|
||||
|
||||
If D is a reference type, this
|
||||
deleter is copy constructed from u's deleter; otherwise, this
|
||||
deleter is move constructed from u's deleter[.](#ctor-17.sentence-2)
|
||||
|
||||
[*Note [1](#ctor-note-1)*:
|
||||
|
||||
The
|
||||
construction of the deleter can be implemented with std::forward<D>[.](#ctor-17.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[18](#ctor-18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2586)
|
||||
|
||||
*Postconditions*: get() yields the value u.get() yielded before the construction[.](#ctor-18.sentence-1)
|
||||
|
||||
u.get() == nullptr[.](#ctor-18.sentence-2)
|
||||
|
||||
get_deleter() returns a reference
|
||||
to the stored deleter that was constructed fromu.get_deleter()[.](#ctor-18.sentence-3)
|
||||
|
||||
If D is a reference type thenget_deleter() and u.get_deleter() both reference
|
||||
the same lvalue deleter[.](#ctor-18.sentence-4)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor____)
|
||||
|
||||
`template<class U, class E> constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
||||
`
|
||||
|
||||
[19](#ctor-19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2603)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(19.1)](#ctor-19.1)
|
||||
|
||||
unique_ptr<U, E>::pointer is implicitly convertible to pointer,
|
||||
|
||||
- [(19.2)](#ctor-19.2)
|
||||
|
||||
U is not an array type, and
|
||||
|
||||
- [(19.3)](#ctor-19.3)
|
||||
|
||||
either D is a reference type and E is the same type as D, orD is not a reference type and E is implicitly convertible to D[.](#ctor-19.sentence-1)
|
||||
|
||||
[20](#ctor-20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2612)
|
||||
|
||||
*Preconditions*: If E is not a reference type,
|
||||
construction of the deleter from an rvalue of type E is well-formed and does not throw an exception[.](#ctor-20.sentence-1)
|
||||
|
||||
Otherwise, E is a reference type and
|
||||
construction of the deleter from an lvalue of type E is well-formed and does not throw an exception[.](#ctor-20.sentence-2)
|
||||
|
||||
[21](#ctor-21)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2621)
|
||||
|
||||
*Effects*: Constructs a unique_ptr from u[.](#ctor-21.sentence-1)
|
||||
|
||||
If E is a reference type, this deleter is copy constructed fromu's deleter; otherwise, this deleter is move constructed from u's
|
||||
deleter[.](#ctor-21.sentence-2)
|
||||
|
||||
[*Note [2](#ctor-note-2)*:
|
||||
|
||||
The deleter constructor can be implemented withstd::forward<E>[.](#ctor-21.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[22](#ctor-22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2632)
|
||||
|
||||
*Postconditions*: get() yields the value u.get() yielded before the construction[.](#ctor-22.sentence-1)
|
||||
|
||||
u.get() == nullptr[.](#ctor-22.sentence-2)
|
||||
|
||||
get_deleter() returns a reference
|
||||
to the stored deleter that was constructed fromu.get_deleter()[.](#ctor-22.sentence-3)
|
||||
|
||||
#### [20.3.1.3.3](#dtor) Destructor [[unique.ptr.single.dtor]](unique.ptr.single.dtor)
|
||||
|
||||
[ð](#lib:unique_ptr,destructor)
|
||||
|
||||
`constexpr ~unique_ptr();
|
||||
`
|
||||
|
||||
[1](#dtor-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2649)
|
||||
|
||||
*Effects*: Equivalent to:if (get()) get_deleter()(get());
|
||||
|
||||
[*Note [1](#dtor-note-1)*:
|
||||
|
||||
The use of default_delete requires T to be a complete type[.](#dtor-1.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#dtor-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2657)
|
||||
|
||||
*Remarks*: The behavior is undefined
|
||||
if the evaluation of get_deleter()(get()) throws an exception[.](#dtor-2.sentence-1)
|
||||
|
||||
#### [20.3.1.3.4](#asgn) Assignment [[unique.ptr.single.asgn]](unique.ptr.single.asgn)
|
||||
|
||||
[ð](#lib:operator=,unique_ptr)
|
||||
|
||||
`constexpr unique_ptr& operator=(unique_ptr&& u) noexcept;
|
||||
`
|
||||
|
||||
[1](#asgn-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2671)
|
||||
|
||||
*Constraints*: is_move_assignable_v<D> is true[.](#asgn-1.sentence-1)
|
||||
|
||||
[2](#asgn-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2675)
|
||||
|
||||
*Preconditions*: If D is not a reference type, D meets the[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) and assignment
|
||||
of the deleter from an rvalue of type D does not throw an exception[.](#asgn-2.sentence-1)
|
||||
|
||||
Otherwise, D is a reference type;remove_reference_t<D> meets the [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements and assignment of the deleter from an
|
||||
lvalue of type D does not throw an exception[.](#asgn-2.sentence-2)
|
||||
|
||||
[3](#asgn-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2685)
|
||||
|
||||
*Effects*: Calls reset(u.release()) followed byget_deleter() = std::forward<D>(u.get_deleter())[.](#asgn-3.sentence-1)
|
||||
|
||||
[4](#asgn-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2690)
|
||||
|
||||
*Postconditions*: If this != addressof(u),u.get() == nullptr,
|
||||
otherwise u.get() is unchanged[.](#asgn-4.sentence-1)
|
||||
|
||||
[5](#asgn-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2696)
|
||||
|
||||
*Returns*: *this[.](#asgn-5.sentence-1)
|
||||
|
||||
[ð](#lib:operator=,unique_ptr_)
|
||||
|
||||
`template<class U, class E> constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
||||
`
|
||||
|
||||
[6](#asgn-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2707)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(6.1)](#asgn-6.1)
|
||||
|
||||
unique_ptr<U, E>::pointer is implicitly convertible to pointer, and
|
||||
|
||||
- [(6.2)](#asgn-6.2)
|
||||
|
||||
U is not an array type, and
|
||||
|
||||
- [(6.3)](#asgn-6.3)
|
||||
|
||||
is_assignable_v<D&, E&&> is true[.](#asgn-6.sentence-1)
|
||||
|
||||
[7](#asgn-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2715)
|
||||
|
||||
*Preconditions*: If E is not a reference type,
|
||||
assignment of the deleter from an rvalue of type E is well-formed and does not throw an exception[.](#asgn-7.sentence-1)
|
||||
|
||||
Otherwise, E is a reference type and
|
||||
assignment of the deleter from an lvalue of type E is well-formed and does not throw an exception[.](#asgn-7.sentence-2)
|
||||
|
||||
[8](#asgn-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2724)
|
||||
|
||||
*Effects*: Calls reset(u.release()) followed byget_deleter() = std::forward<E>(u.get_deleter())[.](#asgn-8.sentence-1)
|
||||
|
||||
[9](#asgn-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2729)
|
||||
|
||||
*Postconditions*: u.get() == nullptr[.](#asgn-9.sentence-1)
|
||||
|
||||
[10](#asgn-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2733)
|
||||
|
||||
*Returns*: *this[.](#asgn-10.sentence-1)
|
||||
|
||||
[ð](#lib:operator=,unique_ptr__)
|
||||
|
||||
`constexpr unique_ptr& operator=(nullptr_t) noexcept;
|
||||
`
|
||||
|
||||
[11](#asgn-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2744)
|
||||
|
||||
*Effects*: As if by reset()[.](#asgn-11.sentence-1)
|
||||
|
||||
[12](#asgn-12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2748)
|
||||
|
||||
*Postconditions*: get() == nullptr[.](#asgn-12.sentence-1)
|
||||
|
||||
[13](#asgn-13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2752)
|
||||
|
||||
*Returns*: *this[.](#asgn-13.sentence-1)
|
||||
|
||||
#### [20.3.1.3.5](#observers) Observers [[unique.ptr.single.observers]](unique.ptr.single.observers)
|
||||
|
||||
[ð](#lib:operator*,unique_ptr)
|
||||
|
||||
`constexpr add_lvalue_reference_t<T> operator*() const noexcept(noexcept(*declval<pointer>()));
|
||||
`
|
||||
|
||||
[1](#observers-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2765)
|
||||
|
||||
*Mandates*: reference_converts_from_temporary_v<add_lvalue_reference_t<T>, decltype(
|
||||
*declval<pointer>())> is false[.](#observers-1.sentence-1)
|
||||
|
||||
[2](#observers-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2769)
|
||||
|
||||
*Preconditions*: get() != nullptr is true[.](#observers-2.sentence-1)
|
||||
|
||||
[3](#observers-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2773)
|
||||
|
||||
*Returns*: *get()[.](#observers-3.sentence-1)
|
||||
|
||||
[ð](#lib:operator-%3e,unique_ptr)
|
||||
|
||||
`constexpr pointer operator->() const noexcept;
|
||||
`
|
||||
|
||||
[4](#observers-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2785)
|
||||
|
||||
*Preconditions*: get() != nullptr[.](#observers-4.sentence-1)
|
||||
|
||||
[5](#observers-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2789)
|
||||
|
||||
*Returns*: get()[.](#observers-5.sentence-1)
|
||||
|
||||
[6](#observers-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2793)
|
||||
|
||||
[*Note [1](#observers-note-1)*:
|
||||
|
||||
The use of this function typically requires that T be a complete type[.](#observers-6.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#lib:get,unique_ptr)
|
||||
|
||||
`constexpr pointer get() const noexcept;
|
||||
`
|
||||
|
||||
[7](#observers-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2805)
|
||||
|
||||
*Returns*: The stored pointer[.](#observers-7.sentence-1)
|
||||
|
||||
[ð](#lib:get_deleter,unique_ptr)
|
||||
|
||||
`constexpr deleter_type& get_deleter() noexcept;
|
||||
constexpr const deleter_type& get_deleter() const noexcept;
|
||||
`
|
||||
|
||||
[8](#observers-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2817)
|
||||
|
||||
*Returns*: A reference to the stored deleter[.](#observers-8.sentence-1)
|
||||
|
||||
[ð](#lib:operator_bool,unique_ptr)
|
||||
|
||||
`constexpr explicit operator bool() const noexcept;
|
||||
`
|
||||
|
||||
[9](#observers-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2828)
|
||||
|
||||
*Returns*: get() != nullptr[.](#observers-9.sentence-1)
|
||||
|
||||
#### [20.3.1.3.6](#modifiers) Modifiers [[unique.ptr.single.modifiers]](unique.ptr.single.modifiers)
|
||||
|
||||
[ð](#lib:release,unique_ptr)
|
||||
|
||||
`constexpr pointer release() noexcept;
|
||||
`
|
||||
|
||||
[1](#modifiers-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2841)
|
||||
|
||||
*Postconditions*: get() == nullptr[.](#modifiers-1.sentence-1)
|
||||
|
||||
[2](#modifiers-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2845)
|
||||
|
||||
*Returns*: The value get() had at the start of
|
||||
the call to release[.](#modifiers-2.sentence-1)
|
||||
|
||||
[ð](#lib:reset,unique_ptr)
|
||||
|
||||
`constexpr void reset(pointer p = pointer()) noexcept;
|
||||
`
|
||||
|
||||
[3](#modifiers-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2857)
|
||||
|
||||
*Effects*: Assigns p to the stored pointer, and then,
|
||||
with the old value of the stored pointer, old_p,
|
||||
evaluates if (old_p) get_deleter()(old_p);
|
||||
|
||||
[*Note [1](#modifiers-note-1)*:
|
||||
|
||||
The order of these operations is significant
|
||||
because the call to get_deleter() might destroy *this[.](#modifiers-3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#modifiers-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2867)
|
||||
|
||||
*Postconditions*: get() == p[.](#modifiers-4.sentence-1)
|
||||
|
||||
[*Note [2](#modifiers-note-2)*:
|
||||
|
||||
The postcondition does not hold if the call to get_deleter() destroys *this since this->get() is no longer a valid expression[.](#modifiers-4.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[5](#modifiers-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2875)
|
||||
|
||||
*Remarks*: The behavior is undefined
|
||||
if the evaluation of get_deleter()(old_p) throws an exception[.](#modifiers-5.sentence-1)
|
||||
|
||||
[ð](#lib:swap,unique_ptr)
|
||||
|
||||
`constexpr void swap(unique_ptr& u) noexcept;
|
||||
`
|
||||
|
||||
[6](#modifiers-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2887)
|
||||
|
||||
*Preconditions*: get_deleter() is swappable ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
does not throw an exception under swap[.](#modifiers-6.sentence-1)
|
||||
|
||||
[7](#modifiers-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2892)
|
||||
|
||||
*Effects*: Invokes swap on the stored pointers and on the stored
|
||||
deleters of *this and u[.](#modifiers-7.sentence-1)
|
||||
125
cppdraft/unique/ptr/single/asgn.md
Normal file
125
cppdraft/unique/ptr/single/asgn.md
Normal file
@@ -0,0 +1,125 @@
|
||||
[unique.ptr.single.asgn]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.single.asgn)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#single.asgn)
|
||||
|
||||
#### 20.3.1.3 unique_ptr for single objects [[unique.ptr.single]](unique.ptr.single#asgn)
|
||||
|
||||
#### 20.3.1.3.4 Assignment [unique.ptr.single.asgn]
|
||||
|
||||
[ð](#lib:operator=,unique_ptr)
|
||||
|
||||
`constexpr unique_ptr& operator=(unique_ptr&& u) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2671)
|
||||
|
||||
*Constraints*: is_move_assignable_v<D> is true[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2675)
|
||||
|
||||
*Preconditions*: If D is not a reference type, D meets the[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) and assignment
|
||||
of the deleter from an rvalue of type D does not throw an exception[.](#2.sentence-1)
|
||||
|
||||
Otherwise, D is a reference type;remove_reference_t<D> meets the [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements and assignment of the deleter from an
|
||||
lvalue of type D does not throw an exception[.](#2.sentence-2)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2685)
|
||||
|
||||
*Effects*: Calls reset(u.release()) followed byget_deleter() = std::forward<D>(u.get_deleter())[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2690)
|
||||
|
||||
*Postconditions*: If this != addressof(u),u.get() == nullptr,
|
||||
otherwise u.get() is unchanged[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2696)
|
||||
|
||||
*Returns*: *this[.](#5.sentence-1)
|
||||
|
||||
[ð](#lib:operator=,unique_ptr_)
|
||||
|
||||
`template<class U, class E> constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
|
||||
`
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2707)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(6.1)](#6.1)
|
||||
|
||||
unique_ptr<U, E>::pointer is implicitly convertible to pointer, and
|
||||
|
||||
- [(6.2)](#6.2)
|
||||
|
||||
U is not an array type, and
|
||||
|
||||
- [(6.3)](#6.3)
|
||||
|
||||
is_assignable_v<D&, E&&> is true[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2715)
|
||||
|
||||
*Preconditions*: If E is not a reference type,
|
||||
assignment of the deleter from an rvalue of type E is well-formed and does not throw an exception[.](#7.sentence-1)
|
||||
|
||||
Otherwise, E is a reference type and
|
||||
assignment of the deleter from an lvalue of type E is well-formed and does not throw an exception[.](#7.sentence-2)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2724)
|
||||
|
||||
*Effects*: Calls reset(u.release()) followed byget_deleter() = std::forward<E>(u.get_deleter())[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2729)
|
||||
|
||||
*Postconditions*: u.get() == nullptr[.](#9.sentence-1)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2733)
|
||||
|
||||
*Returns*: *this[.](#10.sentence-1)
|
||||
|
||||
[ð](#lib:operator=,unique_ptr__)
|
||||
|
||||
`constexpr unique_ptr& operator=(nullptr_t) noexcept;
|
||||
`
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2744)
|
||||
|
||||
*Effects*: As if by reset()[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2748)
|
||||
|
||||
*Postconditions*: get() == nullptr[.](#12.sentence-1)
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2752)
|
||||
|
||||
*Returns*: *this[.](#13.sentence-1)
|
||||
244
cppdraft/unique/ptr/single/ctor.md
Normal file
244
cppdraft/unique/ptr/single/ctor.md
Normal file
@@ -0,0 +1,244 @@
|
||||
[unique.ptr.single.ctor]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.single.ctor)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#single.ctor)
|
||||
|
||||
#### 20.3.1.3 unique_ptr for single objects [[unique.ptr.single]](unique.ptr.single#ctor)
|
||||
|
||||
#### 20.3.1.3.2 Constructors [unique.ptr.single.ctor]
|
||||
|
||||
[ð](#lib:unique_ptr,constructor)
|
||||
|
||||
`constexpr unique_ptr() noexcept;
|
||||
constexpr unique_ptr(nullptr_t) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2456)
|
||||
|
||||
*Constraints*: is_pointer_v<deleter_type> is false andis_default_constructible_v<deleter_type> is true[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2461)
|
||||
|
||||
*Preconditions*: D meets the [*Cpp17DefaultConstructible*](utility.arg.requirements#:Cpp17DefaultConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [30](utility.arg.requirements#tab:cpp17.defaultconstructible "Table 30: Cpp17DefaultConstructible requirements")),
|
||||
and that construction does not throw an exception[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2466)
|
||||
|
||||
*Effects*: Constructs a unique_ptr object that owns
|
||||
nothing, value-initializing the stored pointer and the stored deleter[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2471)
|
||||
|
||||
*Postconditions*: get() == nullptr[.](#4.sentence-1)
|
||||
|
||||
get_deleter() returns a reference to the stored deleter[.](#4.sentence-2)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor_)
|
||||
|
||||
`constexpr explicit unique_ptr(type_identity_t<pointer> p) noexcept;
|
||||
`
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2483)
|
||||
|
||||
*Constraints*: is_pointer_v<deleter_type> is false andis_default_constructible_v<deleter_type> is true[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2488)
|
||||
|
||||
*Preconditions*: D meets the [*Cpp17DefaultConstructible*](utility.arg.requirements#:Cpp17DefaultConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [30](utility.arg.requirements#tab:cpp17.defaultconstructible "Table 30: Cpp17DefaultConstructible requirements")),
|
||||
and that construction does not throw an exception[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2493)
|
||||
|
||||
*Effects*: Constructs a unique_ptr which ownsp, initializing the stored pointer with p and
|
||||
value-initializing the stored deleter[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2499)
|
||||
|
||||
*Postconditions*: get() == p[.](#8.sentence-1)
|
||||
|
||||
get_deleter() returns a reference to the stored deleter[.](#8.sentence-2)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor__)
|
||||
|
||||
`constexpr unique_ptr(type_identity_t<pointer> p, const D& d) noexcept;
|
||||
constexpr unique_ptr(type_identity_t<pointer> p, remove_reference_t<D>&& d) noexcept;
|
||||
`
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2512)
|
||||
|
||||
*Constraints*: is_constructible_v<D, decltype(d)> is true[.](#9.sentence-1)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2516)
|
||||
|
||||
*Preconditions*: For the first constructor, if D is not a reference type,D meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements and
|
||||
such construction does not exit via an exception[.](#10.sentence-1)
|
||||
|
||||
For the second constructor, if D is not a reference type,D meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements and
|
||||
such construction does not exit via an exception[.](#10.sentence-2)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2525)
|
||||
|
||||
*Effects*: Constructs a unique_ptr object which owns p, initializing
|
||||
the stored pointer with p and initializing the deleter
|
||||
from std::forward<decltype(d)>(d)[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2531)
|
||||
|
||||
*Postconditions*: get() == p[.](#12.sentence-1)
|
||||
|
||||
get_deleter() returns a reference to the stored
|
||||
deleter[.](#12.sentence-2)
|
||||
|
||||
If D is a reference type then get_deleter() returns a reference to the lvalue d[.](#12.sentence-3)
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2538)
|
||||
|
||||
*Remarks*: If D is a reference type,
|
||||
the second constructor is defined as deleted[.](#13.sentence-1)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2543)
|
||||
|
||||
[*Example [1](#example-1)*: D d;
|
||||
unique_ptr<int, D> p1(new int, D()); // D must be [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") unique_ptr<int, D> p2(new int, d); // D must be [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined// with reference deleter type â *end example*]
|
||||
|
||||
[ð](#lib:unique_ptr,constructor___)
|
||||
|
||||
`constexpr unique_ptr(unique_ptr&& u) noexcept;
|
||||
`
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2562)
|
||||
|
||||
*Constraints*: is_move_constructible_v<D> is true[.](#15.sentence-1)
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2566)
|
||||
|
||||
*Preconditions*: If D is not a reference type,D meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements"))[.](#16.sentence-1)
|
||||
|
||||
Construction
|
||||
of the deleter from an rvalue of type D does not
|
||||
throw an exception[.](#16.sentence-2)
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2575)
|
||||
|
||||
*Effects*: Constructs a unique_ptr fromu[.](#17.sentence-1)
|
||||
|
||||
If D is a reference type, this
|
||||
deleter is copy constructed from u's deleter; otherwise, this
|
||||
deleter is move constructed from u's deleter[.](#17.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The
|
||||
construction of the deleter can be implemented with std::forward<D>[.](#17.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2586)
|
||||
|
||||
*Postconditions*: get() yields the value u.get() yielded before the construction[.](#18.sentence-1)
|
||||
|
||||
u.get() == nullptr[.](#18.sentence-2)
|
||||
|
||||
get_deleter() returns a reference
|
||||
to the stored deleter that was constructed fromu.get_deleter()[.](#18.sentence-3)
|
||||
|
||||
If D is a reference type thenget_deleter() and u.get_deleter() both reference
|
||||
the same lvalue deleter[.](#18.sentence-4)
|
||||
|
||||
[ð](#lib:unique_ptr,constructor____)
|
||||
|
||||
`template<class U, class E> constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
||||
`
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2603)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(19.1)](#19.1)
|
||||
|
||||
unique_ptr<U, E>::pointer is implicitly convertible to pointer,
|
||||
|
||||
- [(19.2)](#19.2)
|
||||
|
||||
U is not an array type, and
|
||||
|
||||
- [(19.3)](#19.3)
|
||||
|
||||
either D is a reference type and E is the same type as D, orD is not a reference type and E is implicitly convertible to D[.](#19.sentence-1)
|
||||
|
||||
[20](#20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2612)
|
||||
|
||||
*Preconditions*: If E is not a reference type,
|
||||
construction of the deleter from an rvalue of type E is well-formed and does not throw an exception[.](#20.sentence-1)
|
||||
|
||||
Otherwise, E is a reference type and
|
||||
construction of the deleter from an lvalue of type E is well-formed and does not throw an exception[.](#20.sentence-2)
|
||||
|
||||
[21](#21)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2621)
|
||||
|
||||
*Effects*: Constructs a unique_ptr from u[.](#21.sentence-1)
|
||||
|
||||
If E is a reference type, this deleter is copy constructed fromu's deleter; otherwise, this deleter is move constructed from u's
|
||||
deleter[.](#21.sentence-2)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
The deleter constructor can be implemented withstd::forward<E>[.](#21.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[22](#22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2632)
|
||||
|
||||
*Postconditions*: get() yields the value u.get() yielded before the construction[.](#22.sentence-1)
|
||||
|
||||
u.get() == nullptr[.](#22.sentence-2)
|
||||
|
||||
get_deleter() returns a reference
|
||||
to the stored deleter that was constructed fromu.get_deleter()[.](#22.sentence-3)
|
||||
35
cppdraft/unique/ptr/single/dtor.md
Normal file
35
cppdraft/unique/ptr/single/dtor.md
Normal file
@@ -0,0 +1,35 @@
|
||||
[unique.ptr.single.dtor]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.single.dtor)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#single.dtor)
|
||||
|
||||
#### 20.3.1.3 unique_ptr for single objects [[unique.ptr.single]](unique.ptr.single#dtor)
|
||||
|
||||
#### 20.3.1.3.3 Destructor [unique.ptr.single.dtor]
|
||||
|
||||
[ð](#lib:unique_ptr,destructor)
|
||||
|
||||
`constexpr ~unique_ptr();
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2649)
|
||||
|
||||
*Effects*: Equivalent to:if (get()) get_deleter()(get());
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The use of default_delete requires T to be a complete type[.](#1.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2657)
|
||||
|
||||
*Remarks*: The behavior is undefined
|
||||
if the evaluation of get_deleter()(get()) throws an exception[.](#2.sentence-1)
|
||||
73
cppdraft/unique/ptr/single/general.md
Normal file
73
cppdraft/unique/ptr/single/general.md
Normal file
@@ -0,0 +1,73 @@
|
||||
[unique.ptr.single.general]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.single.general)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#single.general)
|
||||
|
||||
#### 20.3.1.3 unique_ptr for single objects [[unique.ptr.single]](unique.ptr.single#general)
|
||||
|
||||
#### 20.3.1.3.1 General [unique.ptr.single.general]
|
||||
|
||||
[ð](#lib:unique_ptr)
|
||||
|
||||
namespace std {template<class T, class D = default_delete<T>> class unique_ptr {public:using pointer = *see below*; using element_type = T; using deleter_type = D; // [[unique.ptr.single.ctor]](unique.ptr.single.ctor "20.3.1.3.2 Constructors"), constructorsconstexpr unique_ptr() noexcept; constexpr explicit unique_ptr(type_identity_t<pointer> p) noexcept; constexpr unique_ptr(type_identity_t<pointer> p, *see below* d1) noexcept; constexpr unique_ptr(type_identity_t<pointer> p, *see below* d2) noexcept; constexpr unique_ptr(unique_ptr&& u) noexcept; constexpr unique_ptr(nullptr_t) noexcept; template<class U, class E>constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept; // [[unique.ptr.single.dtor]](unique.ptr.single.dtor "20.3.1.3.3 Destructor"), destructorconstexpr ~unique_ptr(); // [[unique.ptr.single.asgn]](unique.ptr.single.asgn "20.3.1.3.4 Assignment"), assignmentconstexpr unique_ptr& operator=(unique_ptr&& u) noexcept; template<class U, class E>constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; constexpr unique_ptr& operator=(nullptr_t) noexcept; // [[unique.ptr.single.observers]](unique.ptr.single.observers "20.3.1.3.5 Observers"), observersconstexpr add_lvalue_reference_t<T> operator*() const noexcept(*see below*); constexpr pointer operator->() const noexcept; constexpr pointer get() const noexcept; constexpr deleter_type& get_deleter() noexcept; constexpr const deleter_type& get_deleter() const noexcept; constexpr explicit operator bool() const noexcept; // [[unique.ptr.single.modifiers]](unique.ptr.single.modifiers "20.3.1.3.6 Modifiers"), modifiersconstexpr pointer release() noexcept; constexpr void reset(pointer p = pointer()) noexcept; constexpr void swap(unique_ptr& u) noexcept; // disable copy from lvalue unique_ptr(const unique_ptr&) = delete;
|
||||
unique_ptr& operator=(const unique_ptr&) = delete; };}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2407)
|
||||
|
||||
A program that instantiates the definition of unique_ptr<T, D> is ill-formed if T* is an invalid type[.](#1.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
This prevents the instantiation of specializations such asunique_ptr<T&, D> and unique_ptr<int() const, D>[.](#1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2415)
|
||||
|
||||
The default type for the template parameter D isdefault_delete[.](#2.sentence-1)
|
||||
|
||||
A client-supplied template argumentD shall be a function
|
||||
object type ([[function.objects]](function.objects "22.10 Function objects")), lvalue reference to function, or
|
||||
lvalue reference to function object type
|
||||
for which, given
|
||||
a value d of type D and a valueptr of type unique_ptr<T, D>::pointer, the expressiond(ptr) is valid and has the effect of disposing of the
|
||||
pointer as appropriate for that deleter[.](#2.sentence-2)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2427)
|
||||
|
||||
If the deleter's type D is not a reference type, D shall meet
|
||||
the [*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [35](utility.arg.requirements#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements"))[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2431)
|
||||
|
||||
If the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") remove_reference_t<D>::pointer is valid and denotes a
|
||||
type ([[temp.deduct]](temp.deduct "13.10.3 Template argument deduction")), then unique_ptr<T,
|
||||
D>::pointer shall be a synonym for remove_reference_t<D>::pointer[.](#4.sentence-1)
|
||||
|
||||
Otherwiseunique_ptr<T, D>::pointer shall be a synonym for element_type*[.](#4.sentence-2)
|
||||
|
||||
The type unique_ptr<T,
|
||||
D>::pointer shall
|
||||
meet the [*Cpp17NullablePointer*](nullablepointer.requirements#:Cpp17NullablePointer "16.4.4.4 Cpp17NullablePointer requirements [nullablepointer.requirements]") requirements (Table [36](nullablepointer.requirements#tab:cpp17.nullablepointer "Table 36: Cpp17NullablePointer requirements"))[.](#4.sentence-3)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2439)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
Given an allocator type X ([[allocator.requirements.general]](allocator.requirements.general "16.4.4.6.1 General")) and
|
||||
letting A be a synonym for allocator_traits<X>, the types A::pointer,A::const_pointer, A::void_pointer, and A::const_void_pointer may be used as unique_ptr<T, D>::pointer[.](#5.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
87
cppdraft/unique/ptr/single/modifiers.md
Normal file
87
cppdraft/unique/ptr/single/modifiers.md
Normal file
@@ -0,0 +1,87 @@
|
||||
[unique.ptr.single.modifiers]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.single.modifiers)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#single.modifiers)
|
||||
|
||||
#### 20.3.1.3 unique_ptr for single objects [[unique.ptr.single]](unique.ptr.single#modifiers)
|
||||
|
||||
#### 20.3.1.3.6 Modifiers [unique.ptr.single.modifiers]
|
||||
|
||||
[ð](#lib:release,unique_ptr)
|
||||
|
||||
`constexpr pointer release() noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2841)
|
||||
|
||||
*Postconditions*: get() == nullptr[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2845)
|
||||
|
||||
*Returns*: The value get() had at the start of
|
||||
the call to release[.](#2.sentence-1)
|
||||
|
||||
[ð](#lib:reset,unique_ptr)
|
||||
|
||||
`constexpr void reset(pointer p = pointer()) noexcept;
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2857)
|
||||
|
||||
*Effects*: Assigns p to the stored pointer, and then,
|
||||
with the old value of the stored pointer, old_p,
|
||||
evaluates if (old_p) get_deleter()(old_p);
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The order of these operations is significant
|
||||
because the call to get_deleter() might destroy *this[.](#3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2867)
|
||||
|
||||
*Postconditions*: get() == p[.](#4.sentence-1)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
The postcondition does not hold if the call to get_deleter() destroys *this since this->get() is no longer a valid expression[.](#4.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2875)
|
||||
|
||||
*Remarks*: The behavior is undefined
|
||||
if the evaluation of get_deleter()(old_p) throws an exception[.](#5.sentence-1)
|
||||
|
||||
[ð](#lib:swap,unique_ptr)
|
||||
|
||||
`constexpr void swap(unique_ptr& u) noexcept;
|
||||
`
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2887)
|
||||
|
||||
*Preconditions*: get_deleter() is swappable ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||||
does not throw an exception under swap[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2892)
|
||||
|
||||
*Effects*: Invokes swap on the stored pointers and on the stored
|
||||
deleters of *this and u[.](#7.sentence-1)
|
||||
96
cppdraft/unique/ptr/single/observers.md
Normal file
96
cppdraft/unique/ptr/single/observers.md
Normal file
@@ -0,0 +1,96 @@
|
||||
[unique.ptr.single.observers]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.single.observers)
|
||||
|
||||
### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#single.observers)
|
||||
|
||||
#### 20.3.1.3 unique_ptr for single objects [[unique.ptr.single]](unique.ptr.single#observers)
|
||||
|
||||
#### 20.3.1.3.5 Observers [unique.ptr.single.observers]
|
||||
|
||||
[ð](#lib:operator*,unique_ptr)
|
||||
|
||||
`constexpr add_lvalue_reference_t<T> operator*() const noexcept(noexcept(*declval<pointer>()));
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2765)
|
||||
|
||||
*Mandates*: reference_converts_from_temporary_v<add_lvalue_reference_t<T>, decltype(
|
||||
*declval<pointer>())> is false[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2769)
|
||||
|
||||
*Preconditions*: get() != nullptr is true[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2773)
|
||||
|
||||
*Returns*: *get()[.](#3.sentence-1)
|
||||
|
||||
[ð](#lib:operator-%3e,unique_ptr)
|
||||
|
||||
`constexpr pointer operator->() const noexcept;
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2785)
|
||||
|
||||
*Preconditions*: get() != nullptr[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2789)
|
||||
|
||||
*Returns*: get()[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2793)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The use of this function typically requires that T be a complete type[.](#6.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#lib:get,unique_ptr)
|
||||
|
||||
`constexpr pointer get() const noexcept;
|
||||
`
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2805)
|
||||
|
||||
*Returns*: The stored pointer[.](#7.sentence-1)
|
||||
|
||||
[ð](#lib:get_deleter,unique_ptr)
|
||||
|
||||
`constexpr deleter_type& get_deleter() noexcept;
|
||||
constexpr const deleter_type& get_deleter() const noexcept;
|
||||
`
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2817)
|
||||
|
||||
*Returns*: A reference to the stored deleter[.](#8.sentence-1)
|
||||
|
||||
[ð](#lib:operator_bool,unique_ptr)
|
||||
|
||||
`constexpr explicit operator bool() const noexcept;
|
||||
`
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2828)
|
||||
|
||||
*Returns*: get() != nullptr[.](#9.sentence-1)
|
||||
227
cppdraft/unique/ptr/special.md
Normal file
227
cppdraft/unique/ptr/special.md
Normal file
@@ -0,0 +1,227 @@
|
||||
[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.10 Function objects")) that
|
||||
induces a strict weak ordering ([[alg.sorting]](alg.sorting "26.8 Sorting 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.4 Concept 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.10 Function objects")) that induces a strict weak
|
||||
ordering ([[alg.sorting]](alg.sorting "26.8 Sorting 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.4 Concept 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)).
|
||||
Reference in New Issue
Block a user