tmp/tmpg0frlzdn/{from.md → to.md}
RENAMED
|
@@ -1,123 +1,120 @@
|
|
| 1 |
##### `unique_ptr` constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
constexpr unique_ptr() noexcept;
|
|
|
|
| 5 |
```
|
| 6 |
|
| 7 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 8 |
-
(Table [[defaultconstructible]]), and that construction shall not
|
| 9 |
-
an exception.
|
| 10 |
|
| 11 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 12 |
value-initializing the stored pointer and the stored deleter.
|
| 13 |
|
| 14 |
*Postconditions:* `get() == nullptr`. `get_deleter()` returns a
|
| 15 |
reference to the stored deleter.
|
| 16 |
|
| 17 |
-
*Remarks:* If
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
``` cpp
|
| 21 |
explicit unique_ptr(pointer p) noexcept;
|
| 22 |
```
|
| 23 |
|
| 24 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 25 |
-
(Table [[defaultconstructible]]), and that construction shall not
|
| 26 |
-
an exception.
|
| 27 |
|
| 28 |
*Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
|
| 29 |
stored pointer with `p` and value-initializing the stored deleter.
|
| 30 |
|
| 31 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 32 |
the stored deleter.
|
| 33 |
|
| 34 |
-
*Remarks:* If
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
``` cpp
|
| 38 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 39 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 40 |
```
|
| 41 |
|
| 42 |
The signature of these constructors depends upon whether `D` is a
|
| 43 |
-
reference type. If `D` is non-reference type `A`, then the signatures
|
| 44 |
are:
|
| 45 |
|
| 46 |
``` cpp
|
| 47 |
-
unique_ptr(pointer p, const A& d);
|
| 48 |
-
unique_ptr(pointer p, A&& d);
|
| 49 |
```
|
| 50 |
|
| 51 |
-
If `D` is an lvalue
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
-
unique_ptr(pointer p, A& d);
|
| 55 |
-
unique_ptr(pointer p, A&& d);
|
| 56 |
```
|
| 57 |
|
| 58 |
-
If `D` is an lvalue
|
| 59 |
|
| 60 |
``` cpp
|
| 61 |
-
unique_ptr(pointer p, const A& d);
|
| 62 |
-
unique_ptr(pointer p, const A&& d);
|
| 63 |
```
|
| 64 |
|
| 65 |
-
*Requires:*
|
| 66 |
-
|
| 67 |
-
- If `D` is not an lvalue-reference type then
|
| 68 |
-
- If `d` is an lvalue or `const` rvalue then the first constructor of
|
| 69 |
-
this pair will be selected. `D` shall satisfy the requirements of
|
| 70 |
-
`CopyConstructible` (Table [[copyconstructible]]), and the copy
|
| 71 |
-
constructor of `D` shall not throw an exception. This `unique_ptr`
|
| 72 |
-
will hold a copy of `d`.
|
| 73 |
-
- Otherwise, `d` is a non-const rvalue and the second constructor of
|
| 74 |
-
this pair will be selected. `D` shall satisfy the requirements of
|
| 75 |
-
`MoveConstructible` (Table [[moveconstructible]]), and the move
|
| 76 |
-
constructor of `D` shall not throw an exception. This `unique_ptr`
|
| 77 |
-
will hold a value move constructed from `d`.
|
| 78 |
-
- Otherwise `D` is an lvalue-reference type. `d` shall be
|
| 79 |
-
reference-compatible with one of the constructors. If `d` is an
|
| 80 |
-
rvalue, it will bind to the second constructor of this pair and the
|
| 81 |
-
program is ill-formed. The diagnostic could be implemented using a
|
| 82 |
-
`static_assert` which assures that `D` is not a reference type. Else
|
| 83 |
-
`d` is an lvalue and will bind to the first constructor of this pair.
|
| 84 |
-
The type which `D` references need not be `CopyConstructible` nor
|
| 85 |
-
`MoveConstructible`. This `unique_ptr` will hold a `D` which refers to
|
| 86 |
-
the lvalue `d`. `D` may not be an rvalue-reference type.
|
| 87 |
-
|
| 88 |
*Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
|
| 89 |
-
the stored pointer with `p` and initializing the deleter
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 93 |
the stored deleter. If `D` is a reference type then `get_deleter()`
|
| 94 |
returns a reference to the lvalue `d`.
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
``` cpp
|
| 97 |
D d;
|
| 98 |
unique_ptr<int, D> p1(new int, D()); // D must be MoveConstructible
|
| 99 |
unique_ptr<int, D> p2(new int, d); // D must be CopyConstructible
|
| 100 |
unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
|
| 101 |
unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
|
| 102 |
// with reference deleter type
|
| 103 |
```
|
| 104 |
|
|
|
|
|
|
|
| 105 |
``` cpp
|
| 106 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 107 |
```
|
| 108 |
|
| 109 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 110 |
-
requirements of `MoveConstructible` (Table [[moveconstructible]]).
|
| 111 |
Construction of the deleter from an rvalue of type `D` shall not throw
|
| 112 |
an exception.
|
| 113 |
|
| 114 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 115 |
to `*this`. If `D` is a reference type, this deleter is copy constructed
|
| 116 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 117 |
-
`u`’s deleter.
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
|
| 120 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 121 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 122 |
that was constructed from `u.get_deleter()`. If `D` is a reference type
|
| 123 |
then `get_deleter()` and `u.get_deleter()` both reference the same
|
|
@@ -142,28 +139,14 @@ unless:
|
|
| 142 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 143 |
|
| 144 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 145 |
to `*this`. If `E` is a reference type, this deleter is copy constructed
|
| 146 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 147 |
-
`u`’s deleter.
|
| 148 |
-
|
|
|
|
|
|
|
| 149 |
|
| 150 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 151 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 152 |
that was constructed from `u.get_deleter()`.
|
| 153 |
|
| 154 |
-
``` cpp
|
| 155 |
-
template <class U>
|
| 156 |
-
unique_ptr(auto_ptr<U>&& u) noexcept;
|
| 157 |
-
```
|
| 158 |
-
|
| 159 |
-
*Effects:* Constructs a `unique_ptr` object, initializing the stored
|
| 160 |
-
pointer with `u.release()` and value-initializing the stored deleter.
|
| 161 |
-
|
| 162 |
-
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 163 |
-
construction. `u.get() == nullptr`. `get_deleter()` returns a reference
|
| 164 |
-
to the stored deleter.
|
| 165 |
-
|
| 166 |
-
*Remarks:* This constructor shall not participate in overload resolution
|
| 167 |
-
unless `U*` is implicitly convertible to `T*` and `D` is the same type
|
| 168 |
-
as `default_delete<T>`.
|
| 169 |
-
|
|
|
|
| 1 |
##### `unique_ptr` constructors <a id="unique.ptr.single.ctor">[[unique.ptr.single.ctor]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
constexpr unique_ptr() noexcept;
|
| 5 |
+
constexpr unique_ptr(nullptr_t) noexcept;
|
| 6 |
```
|
| 7 |
|
| 8 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 9 |
+
(Table [[tab:defaultconstructible]]), and that construction shall not
|
| 10 |
+
throw an exception.
|
| 11 |
|
| 12 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 13 |
value-initializing the stored pointer and the stored deleter.
|
| 14 |
|
| 15 |
*Postconditions:* `get() == nullptr`. `get_deleter()` returns a
|
| 16 |
reference to the stored deleter.
|
| 17 |
|
| 18 |
+
*Remarks:* If `is_pointer_v<deleter_type>` is `true` or
|
| 19 |
+
`is_default_constructible_v<deleter_type>` is `false`, this constructor
|
| 20 |
+
shall not participate in overload resolution.
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
explicit unique_ptr(pointer p) noexcept;
|
| 24 |
```
|
| 25 |
|
| 26 |
*Requires:* `D` shall satisfy the requirements of `DefaultConstructible`
|
| 27 |
+
(Table [[tab:defaultconstructible]]), and that construction shall not
|
| 28 |
+
throw an exception.
|
| 29 |
|
| 30 |
*Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
|
| 31 |
stored pointer with `p` and value-initializing the stored deleter.
|
| 32 |
|
| 33 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 34 |
the stored deleter.
|
| 35 |
|
| 36 |
+
*Remarks:* If `is_pointer_v<deleter_type>` is `true` or
|
| 37 |
+
`is_default_constructible_v<deleter_type>` is `false`, this constructor
|
| 38 |
+
shall not participate in overload resolution. If class template argument
|
| 39 |
+
deduction ([[over.match.class.deduct]]) would select the function
|
| 40 |
+
template corresponding to this constructor, then the program is
|
| 41 |
+
ill-formed.
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
unique_ptr(pointer p, see below d1) noexcept;
|
| 45 |
unique_ptr(pointer p, see below d2) noexcept;
|
| 46 |
```
|
| 47 |
|
| 48 |
The signature of these constructors depends upon whether `D` is a
|
| 49 |
+
reference type. If `D` is a non-reference type `A`, then the signatures
|
| 50 |
are:
|
| 51 |
|
| 52 |
``` cpp
|
| 53 |
+
unique_ptr(pointer p, const A& d) noexcept;
|
| 54 |
+
unique_ptr(pointer p, A&& d) noexcept;
|
| 55 |
```
|
| 56 |
|
| 57 |
+
If `D` is an lvalue reference type `A&`, then the signatures are:
|
| 58 |
|
| 59 |
``` cpp
|
| 60 |
+
unique_ptr(pointer p, A& d) noexcept;
|
| 61 |
+
unique_ptr(pointer p, A&& d) = delete;
|
| 62 |
```
|
| 63 |
|
| 64 |
+
If `D` is an lvalue reference type `const A&`, then the signatures are:
|
| 65 |
|
| 66 |
``` cpp
|
| 67 |
+
unique_ptr(pointer p, const A& d) noexcept;
|
| 68 |
+
unique_ptr(pointer p, const A&& d) = delete;
|
| 69 |
```
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
*Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
|
| 72 |
+
the stored pointer with `p` and initializing the deleter from
|
| 73 |
+
`std::forward<decltype(d)>(d)`.
|
| 74 |
+
|
| 75 |
+
*Remarks:* These constructors shall not participate in overload
|
| 76 |
+
resolution unless `is_constructible_v<D, decltype(d)>` is `true`.
|
| 77 |
|
| 78 |
*Postconditions:* `get() == p`. `get_deleter()` returns a reference to
|
| 79 |
the stored deleter. If `D` is a reference type then `get_deleter()`
|
| 80 |
returns a reference to the lvalue `d`.
|
| 81 |
|
| 82 |
+
*Remarks:* If class template argument
|
| 83 |
+
deduction ([[over.match.class.deduct]]) would select a function
|
| 84 |
+
template corresponding to either of these constructors, then the program
|
| 85 |
+
is ill-formed.
|
| 86 |
+
|
| 87 |
+
[*Example 1*:
|
| 88 |
+
|
| 89 |
``` cpp
|
| 90 |
D d;
|
| 91 |
unique_ptr<int, D> p1(new int, D()); // D must be MoveConstructible
|
| 92 |
unique_ptr<int, D> p2(new int, d); // D must be CopyConstructible
|
| 93 |
unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
|
| 94 |
unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
|
| 95 |
// with reference deleter type
|
| 96 |
```
|
| 97 |
|
| 98 |
+
— *end example*]
|
| 99 |
+
|
| 100 |
``` cpp
|
| 101 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 102 |
```
|
| 103 |
|
| 104 |
*Requires:* If `D` is not a reference type, `D` shall satisfy the
|
| 105 |
+
requirements of `MoveConstructible` (Table [[tab:moveconstructible]]).
|
| 106 |
Construction of the deleter from an rvalue of type `D` shall not throw
|
| 107 |
an exception.
|
| 108 |
|
| 109 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 110 |
to `*this`. If `D` is a reference type, this deleter is copy constructed
|
| 111 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 112 |
+
`u`’s deleter.
|
| 113 |
+
|
| 114 |
+
[*Note 1*: The deleter constructor can be implemented with
|
| 115 |
+
`std::forward<D>`. — *end note*]
|
| 116 |
|
| 117 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 118 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 119 |
that was constructed from `u.get_deleter()`. If `D` is a reference type
|
| 120 |
then `get_deleter()` and `u.get_deleter()` both reference the same
|
|
|
|
| 139 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 140 |
|
| 141 |
*Effects:* Constructs a `unique_ptr` by transferring ownership from `u`
|
| 142 |
to `*this`. If `E` is a reference type, this deleter is copy constructed
|
| 143 |
from `u`’s deleter; otherwise, this deleter is move constructed from
|
| 144 |
+
`u`’s deleter.
|
| 145 |
+
|
| 146 |
+
[*Note 2*: The deleter constructor can be implemented with
|
| 147 |
+
`std::forward<E>`. — *end note*]
|
| 148 |
|
| 149 |
*Postconditions:* `get()` yields the value `u.get()` yielded before the
|
| 150 |
construction. `get_deleter()` returns a reference to the stored deleter
|
| 151 |
that was constructed from `u.get_deleter()`.
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|