From Jason Turner

[func.wrap.copy]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpblrod_7h/{from.md → to.md} +290 -0
tmp/tmpblrod_7h/{from.md → to.md} RENAMED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Copyable wrapper <a id="func.wrap.copy">[[func.wrap.copy]]</a>
2
+
3
+ ##### General <a id="func.wrap.copy.general">[[func.wrap.copy.general]]</a>
4
+
5
+ The header provides partial specializations of `copyable_function` for
6
+ each combination of the possible replacements of the placeholders cv,
7
+ *ref*, and *noex* where
8
+
9
+ - cv is either const or empty,
10
+ - *ref* is either `&`, `&&`, or empty, and
11
+ - *noex* is either `true` or `false`.
12
+
13
+ For each of the possible combinations of the placeholders mentioned
14
+ above, there is a placeholder *inv-quals* defined as follows:
15
+
16
+ - If *ref* is empty, let *inv-quals* be cv`&`,
17
+ - otherwise, let *inv-quals* be cv *ref*.
18
+
19
+ ##### Class template `copyable_function` <a id="func.wrap.copy.class">[[func.wrap.copy.class]]</a>
20
+
21
+ ``` cpp
22
+ namespace std {
23
+ template<class R, class... ArgTypes>
24
+ class copyable_function<R(ArgTypes...) cv ref noexcept(noex)> {
25
+ public:
26
+ using result_type = R;
27
+
28
+ // [func.wrap.copy.ctor], constructors, assignments, and destructor
29
+ copyable_function() noexcept;
30
+ copyable_function(nullptr_t) noexcept;
31
+ copyable_function(const copyable_function&);
32
+ copyable_function(copyable_function&&) noexcept;
33
+ template<class F> copyable_function(F&&);
34
+ template<class T, class... Args>
35
+ explicit copyable_function(in_place_type_t<T>, Args&&...);
36
+ template<class T, class U, class... Args>
37
+ explicit copyable_function(in_place_type_t<T>, initializer_list<U>, Args&&...);
38
+
39
+ copyable_function& operator=(const copyable_function&);
40
+ copyable_function& operator=(copyable_function&&);
41
+ copyable_function& operator=(nullptr_t) noexcept;
42
+ template<class F> copyable_function& operator=(F&&);
43
+
44
+ ~copyable_function();
45
+
46
+ // [func.wrap.copy.inv], invocation
47
+ explicit operator bool() const noexcept;
48
+ R operator()(ArgTypes...) cv ref noexcept(noex);
49
+
50
+ // [func.wrap.copy.util], utility
51
+ void swap(copyable_function&) noexcept;
52
+ friend void swap(copyable_function&, copyable_function&) noexcept;
53
+ friend bool operator==(const copyable_function&, nullptr_t) noexcept;
54
+
55
+ private:
56
+ template<class VT>
57
+ static constexpr bool is-callable-from = see below; // exposition only
58
+ };
59
+ }
60
+ ```
61
+
62
+ The `copyable_function` class template provides polymorphic wrappers
63
+ that generalize the notion of a callable object [[func.def]]. These
64
+ wrappers can store, copy, move, and call arbitrary callable objects,
65
+ given a call signature.
66
+
67
+ *Recommended practice:* Implementations should avoid the use of
68
+ dynamically allocated memory for a small contained value.
69
+
70
+ [*Note 1*: Such small-object optimization can only be applied to a type
71
+ `T` for which `is_nothrow_move_constructible_v<T>` is
72
+ `true`. — *end note*]
73
+
74
+ ##### Constructors, assignments, and destructor <a id="func.wrap.copy.ctor">[[func.wrap.copy.ctor]]</a>
75
+
76
+ ``` cpp
77
+ template<class VT>
78
+ static constexpr bool is-callable-from = see below;
79
+ ```
80
+
81
+ If *noex* is `true`, *`is-callable-from`*`<VT>` is equal to:
82
+
83
+ ``` cpp
84
+ is_nothrow_invocable_r_v<R, VT cv ref, ArgTypes...> &&
85
+ is_nothrow_invocable_r_v<R, VT inv-quals, ArgTypes...>
86
+ ```
87
+
88
+ Otherwise, *`is-callable-from`*`<VT>` is equal to:
89
+
90
+ ``` cpp
91
+ is_invocable_r_v<R, VT cv ref, ArgTypes...> &&
92
+ is_invocable_r_v<R, VT inv-quals, ArgTypes...>
93
+ ```
94
+
95
+ ``` cpp
96
+ copyable_function() noexcept;
97
+ copyable_function(nullptr_t) noexcept;
98
+ ```
99
+
100
+ *Ensures:* `*this` has no target object.
101
+
102
+ ``` cpp
103
+ copyable_function(const copyable_function& f);
104
+ ```
105
+
106
+ *Ensures:* `*this` has no target object if `f` had no target object.
107
+ Otherwise, the target object of `*this` is a copy of the target object
108
+ of `f`.
109
+
110
+ *Throws:* Any exception thrown by the initialization of the target
111
+ object. May throw `bad_alloc`.
112
+
113
+ ``` cpp
114
+ copyable_function(copyable_function&& f) noexcept;
115
+ ```
116
+
117
+ *Ensures:* The target object of `*this` is the target object `f` had
118
+ before construction, and `f` is in a valid state with an unspecified
119
+ value.
120
+
121
+ ``` cpp
122
+ template<class F> copyable_function(F&& f);
123
+ ```
124
+
125
+ Let `VT` be `decay_t<F>`.
126
+
127
+ *Constraints:*
128
+
129
+ - `remove_cvref_t<F>` is not the same type as `copyable_function`, and
130
+ - `remove_cvref_t<F>` is not a specialization of `in_place_type_t`, and
131
+ - *`is-callable-from`*`<VT>` is `true`.
132
+
133
+ *Mandates:*
134
+
135
+ - `is_constructible_v<VT, F>` is `true`, and
136
+ - `is_copy_constructible_v<VT>` is `true`.
137
+
138
+ *Preconditions:* `VT` meets the *Cpp17Destructible* and
139
+ *Cpp17CopyConstructible* requirements.
140
+
141
+ *Ensures:* `*this` has no target object if any of the following hold:
142
+
143
+ - `f` is a null function pointer value, or
144
+ - `f` is a null member pointer value, or
145
+ - `remove_cvref_t<F>` is a specialization of the `copyable_function`
146
+ class template, and `f` has no target object.
147
+
148
+ Otherwise, `*this` has a target object of type `VT`
149
+ direct-non-list-initialized with `std::forward<F>(f)`.
150
+
151
+ *Throws:* Any exception thrown by the initialization of the target
152
+ object. May throw `bad_alloc` unless `VT` is a function pointer or a
153
+ specialization of `reference_wrapper`.
154
+
155
+ ``` cpp
156
+ template<class T, class... Args>
157
+ explicit copyable_function(in_place_type_t<T>, Args&&... args);
158
+ ```
159
+
160
+ Let `VT` be `decay_t<T>`.
161
+
162
+ *Constraints:*
163
+
164
+ - `is_constructible_v<VT, Args...>` is `true`, and
165
+ - *`is-callable-from`*`<VT>` is `true`.
166
+
167
+ *Mandates:*
168
+
169
+ - `VT` is the same type as `T`, and
170
+ - `is_copy_constructible_v<VT>` is `true`.
171
+
172
+ *Preconditions:* `VT` meets the *Cpp17Destructible* and
173
+ *Cpp17CopyConstructible* requirements.
174
+
175
+ *Ensures:* `*this` has a target object of type `VT`
176
+ direct-non-list-initialized with `std::forward<Args>(args)...`.
177
+
178
+ *Throws:* Any exception thrown by the initialization of the target
179
+ object. May throw `bad_alloc` unless `VT` is a pointer or a
180
+ specialization of `reference_wrapper`.
181
+
182
+ ``` cpp
183
+ template<class T, class U, class... Args>
184
+ explicit copyable_function(in_place_type_t<T>, initializer_list<U> ilist, Args&&... args);
185
+ ```
186
+
187
+ Let `VT` be `decay_t<T>`.
188
+
189
+ *Constraints:*
190
+
191
+ - `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`, and
192
+ - *`is-callable-from`*`<VT>` is `true`.
193
+
194
+ *Mandates:*
195
+
196
+ - `VT` is the same type as `T`, and
197
+ - `is_copy_constructible_v<VT>` is `true`.
198
+
199
+ *Preconditions:* `VT` meets the *Cpp17Destructible* and
200
+ *Cpp17CopyConstructible* requirements.
201
+
202
+ *Ensures:* `*this` has a target object of type `VT`
203
+ direct-non-list-initialized with `ilist, std::forward<Args>(args)...`.
204
+
205
+ *Throws:* Any exception thrown by the initialization of the target
206
+ object. May throw `bad_alloc` unless `VT` is a pointer or a
207
+ specialization of `reference_wrapper`.
208
+
209
+ ``` cpp
210
+ copyable_function& operator=(const copyable_function& f);
211
+ ```
212
+
213
+ *Effects:* Equivalent to: `copyable_function(f).swap(*this);`
214
+
215
+ *Returns:* `*this`.
216
+
217
+ ``` cpp
218
+ copyable_function& operator=(copyable_function&& f);
219
+ ```
220
+
221
+ *Effects:* Equivalent to: `copyable_function(std::move(f)).swap(*this);`
222
+
223
+ *Returns:* `*this`.
224
+
225
+ ``` cpp
226
+ copyable_function& operator=(nullptr_t) noexcept;
227
+ ```
228
+
229
+ *Effects:* Destroys the target object of `*this`, if any.
230
+
231
+ *Returns:* `*this`.
232
+
233
+ ``` cpp
234
+ template<class F> copyable_function& operator=(F&& f);
235
+ ```
236
+
237
+ *Effects:* Equivalent to:
238
+ `copyable_function(std::forward<F>(f)).swap(*this);`
239
+
240
+ *Returns:* `*this`.
241
+
242
+ ``` cpp
243
+ ~copyable_function();
244
+ ```
245
+
246
+ *Effects:* Destroys the target object of `*this`, if any.
247
+
248
+ ##### Invocation <a id="func.wrap.copy.inv">[[func.wrap.copy.inv]]</a>
249
+
250
+ ``` cpp
251
+ explicit operator bool() const noexcept;
252
+ ```
253
+
254
+ *Returns:* `true` if `*this` has a target object, otherwise `false`.
255
+
256
+ ``` cpp
257
+ R operator()(ArgTypes... args) cv ref noexcept(noex);
258
+ ```
259
+
260
+ *Preconditions:* `*this` has a target object.
261
+
262
+ *Effects:* Equivalent to:
263
+
264
+ ``` cpp
265
+ return INVOKE<R>(static_cast<F inv-quals>(f), std::forward<ArgTypes>(args)...);
266
+ ```
267
+
268
+ where `f` is an lvalue designating the target object of `*this` and `F`
269
+ is the type of `f`.
270
+
271
+ ##### Utility <a id="func.wrap.copy.util">[[func.wrap.copy.util]]</a>
272
+
273
+ ``` cpp
274
+ void swap(copyable_function& other) noexcept;
275
+ ```
276
+
277
+ *Effects:* Exchanges the target objects of `*this` and `other`.
278
+
279
+ ``` cpp
280
+ friend void swap(copyable_function& f1, copyable_function& f2) noexcept;
281
+ ```
282
+
283
+ *Effects:* Equivalent to `f1.swap(f2)`.
284
+
285
+ ``` cpp
286
+ friend bool operator==(const copyable_function& f, nullptr_t) noexcept;
287
+ ```
288
+
289
+ *Returns:* `true` if `f` has no target object, otherwise `false`.
290
+