tmp/tmp357y7tie/{from.md → to.md}
RENAMED
|
@@ -1,97 +1,78 @@
|
|
| 1 |
-
#####
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
constexpr unique_ptr() noexcept;
|
| 5 |
constexpr unique_ptr(nullptr_t) noexcept;
|
| 6 |
```
|
| 7 |
|
| 8 |
-
*
|
| 9 |
-
(
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 13 |
value-initializing the stored pointer and the stored deleter.
|
| 14 |
|
| 15 |
-
*
|
| 16 |
-
|
| 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 |
-
*
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
*
|
| 34 |
-
|
| 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
|
| 54 |
-
unique_ptr(pointer p,
|
| 55 |
```
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 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 |
-
``
|
| 67 |
-
|
| 68 |
-
|
| 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 |
-
*
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
-
*
|
| 79 |
-
|
| 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
|
| 92 |
-
unique_ptr<int, D> p2(new int, d); // D must be
|
| 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 |
|
|
@@ -99,54 +80,53 @@ unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object comb
|
|
| 99 |
|
| 100 |
``` cpp
|
| 101 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 102 |
```
|
| 103 |
|
| 104 |
-
*
|
| 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 |
-
*
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
`std::forward<D>`. — *end note*]
|
| 116 |
|
| 117 |
-
*
|
| 118 |
-
construction. `get_deleter()` returns a reference
|
| 119 |
-
that was constructed from `u.get_deleter()`. If
|
| 120 |
-
then `get_deleter()` and `u.get_deleter()` both
|
| 121 |
-
lvalue deleter.
|
| 122 |
|
| 123 |
``` cpp
|
| 124 |
template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 125 |
```
|
| 126 |
|
| 127 |
-
*
|
| 128 |
-
from an rvalue of type `E` shall be well formed and shall not throw an
|
| 129 |
-
exception. Otherwise, `E` is a reference type and construction of the
|
| 130 |
-
deleter from an lvalue of type `E` shall be well formed and shall not
|
| 131 |
-
throw an exception.
|
| 132 |
-
|
| 133 |
-
*Remarks:* This constructor shall not participate in overload resolution
|
| 134 |
-
unless:
|
| 135 |
|
| 136 |
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
|
| 137 |
- `U` is not an array type, and
|
| 138 |
- either `D` is a reference type and `E` is the same type as `D`, or `D`
|
| 139 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 140 |
|
| 141 |
-
*
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
[*Note 2*: The deleter constructor can be implemented with
|
| 147 |
`std::forward<E>`. — *end note*]
|
| 148 |
|
| 149 |
-
*
|
| 150 |
-
construction. `get_deleter()` returns a reference
|
| 151 |
-
that was constructed from `u.get_deleter()`.
|
| 152 |
|
|
|
|
| 1 |
+
##### 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 |
+
*Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
|
| 9 |
+
([[cpp17.defaultconstructible]]), and that construction does not throw
|
| 10 |
+
an exception.
|
| 11 |
+
|
| 12 |
+
*Constraints:* `is_pointer_v<deleter_type>` is `false` and
|
| 13 |
+
`is_default_constructible_v<deleter_type>` is `true`.
|
| 14 |
|
| 15 |
*Effects:* Constructs a `unique_ptr` object that owns nothing,
|
| 16 |
value-initializing the stored pointer and the stored deleter.
|
| 17 |
|
| 18 |
+
*Ensures:* `get() == nullptr`. `get_deleter()` returns a reference to
|
| 19 |
+
the stored deleter.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
explicit unique_ptr(pointer p) noexcept;
|
| 23 |
```
|
| 24 |
|
| 25 |
+
*Constraints:* `is_pointer_v<deleter_type>` is `false` and
|
| 26 |
+
`is_default_constructible_v<deleter_type>` is `true`.
|
| 27 |
+
|
| 28 |
+
*Mandates:* This constructor is not selected by class template argument
|
| 29 |
+
deduction [[over.match.class.deduct]].
|
| 30 |
+
|
| 31 |
+
*Preconditions:* `D` meets the *Cpp17DefaultConstructible* requirements
|
| 32 |
+
([[cpp17.defaultconstructible]]), and that construction does not throw
|
| 33 |
+
an exception.
|
| 34 |
|
| 35 |
*Effects:* Constructs a `unique_ptr` which owns `p`, initializing the
|
| 36 |
stored pointer with `p` and value-initializing the stored deleter.
|
| 37 |
|
| 38 |
+
*Ensures:* `get() == p`. `get_deleter()` returns a reference to the
|
| 39 |
+
stored deleter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
+
unique_ptr(pointer p, const D& d) noexcept;
|
| 43 |
+
unique_ptr(pointer p, remove_reference_t<D>&& d) noexcept;
|
| 44 |
```
|
| 45 |
|
| 46 |
+
*Constraints:* `is_constructible_v<D, decltype(d)>` is `true`.
|
| 47 |
|
| 48 |
+
*Mandates:* These constructors are not selected by class template
|
| 49 |
+
argument deduction [[over.match.class.deduct]].
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
*Preconditions:* For the first constructor, if `D` is not a reference
|
| 52 |
+
type, `D` meets the *Cpp17CopyConstructible* requirements and such
|
| 53 |
+
construction does not exit via an exception. For the second constructor,
|
| 54 |
+
if `D` is not a reference type, `D` meets the *Cpp17MoveConstructible*
|
| 55 |
+
requirements and such construction does not exit via an exception.
|
| 56 |
|
| 57 |
*Effects:* Constructs a `unique_ptr` object which owns `p`, initializing
|
| 58 |
the stored pointer with `p` and initializing the deleter from
|
| 59 |
`std::forward<decltype(d)>(d)`.
|
| 60 |
|
| 61 |
+
*Ensures:* `get() == p`. `get_deleter()` returns a reference to the
|
| 62 |
+
stored deleter. If `D` is a reference type then `get_deleter()` returns
|
| 63 |
+
a reference to the lvalue `d`.
|
| 64 |
|
| 65 |
+
*Remarks:* If `D` is a reference type, the second constructor is defined
|
| 66 |
+
as deleted.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
[*Example 1*:
|
| 69 |
|
| 70 |
``` cpp
|
| 71 |
D d;
|
| 72 |
+
unique_ptr<int, D> p1(new int, D()); // D must be Cpp17MoveConstructible
|
| 73 |
+
unique_ptr<int, D> p2(new int, d); // D must be Cpp17CopyConstructible
|
| 74 |
unique_ptr<int, D&> p3(new int, d); // p3 holds a reference to d
|
| 75 |
unique_ptr<int, const D&> p4(new int, D()); // error: rvalue deleter object combined
|
| 76 |
// with reference deleter type
|
| 77 |
```
|
| 78 |
|
|
|
|
| 80 |
|
| 81 |
``` cpp
|
| 82 |
unique_ptr(unique_ptr&& u) noexcept;
|
| 83 |
```
|
| 84 |
|
| 85 |
+
*Constraints:* `is_move_constructible_v<D>` is `true`.
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
+
*Preconditions:* If `D` is not a reference type, `D` meets the
|
| 88 |
+
*Cpp17MoveConstructible* requirements ([[cpp17.moveconstructible]]).
|
| 89 |
+
Construction of the deleter from an rvalue of type `D` does not throw an
|
| 90 |
+
exception.
|
| 91 |
|
| 92 |
+
*Effects:* Constructs a `unique_ptr` from `u`. If `D` is a reference
|
| 93 |
+
type, this deleter is copy constructed from `u`’s deleter; otherwise,
|
| 94 |
+
this deleter is move constructed from `u`’s deleter.
|
| 95 |
+
|
| 96 |
+
[*Note 1*: The construction of the deleter can be implemented with
|
| 97 |
`std::forward<D>`. — *end note*]
|
| 98 |
|
| 99 |
+
*Ensures:* `get()` yields the value `u.get()` yielded before the
|
| 100 |
+
construction. `u.get() == nullptr`. `get_deleter()` returns a reference
|
| 101 |
+
to the stored deleter that was constructed from `u.get_deleter()`. If
|
| 102 |
+
`D` is a reference type then `get_deleter()` and `u.get_deleter()` both
|
| 103 |
+
reference the same lvalue deleter.
|
| 104 |
|
| 105 |
``` cpp
|
| 106 |
template<class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept;
|
| 107 |
```
|
| 108 |
|
| 109 |
+
*Constraints:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
- `unique_ptr<U, E>::pointer` is implicitly convertible to `pointer`,
|
| 112 |
- `U` is not an array type, and
|
| 113 |
- either `D` is a reference type and `E` is the same type as `D`, or `D`
|
| 114 |
is not a reference type and `E` is implicitly convertible to `D`.
|
| 115 |
|
| 116 |
+
*Preconditions:* If `E` is not a reference type, construction of the
|
| 117 |
+
deleter from an rvalue of type `E` is well-formed and does not throw an
|
| 118 |
+
exception. Otherwise, `E` is a reference type and construction of the
|
| 119 |
+
deleter from an lvalue of type `E` is well-formed and does not throw an
|
| 120 |
+
exception.
|
| 121 |
+
|
| 122 |
+
*Effects:* Constructs a `unique_ptr` from `u`. If `E` is a reference
|
| 123 |
+
type, this deleter is copy constructed from `u`’s deleter; otherwise,
|
| 124 |
+
this deleter is move constructed from `u`’s deleter.
|
| 125 |
|
| 126 |
[*Note 2*: The deleter constructor can be implemented with
|
| 127 |
`std::forward<E>`. — *end note*]
|
| 128 |
|
| 129 |
+
*Ensures:* `get()` yields the value `u.get()` yielded before the
|
| 130 |
+
construction. `u.get() == nullptr`. `get_deleter()` returns a reference
|
| 131 |
+
to the stored deleter that was constructed from `u.get_deleter()`.
|
| 132 |
|