From Jason Turner

[func.wrap.func]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmptr_xwt7_/{from.md → to.md} +56 -84
tmp/tmptr_xwt7_/{from.md → to.md} RENAMED
@@ -11,11 +11,11 @@ namespace std {
11
 
12
  // [func.wrap.func.con], construct/copy/destroy
13
  function() noexcept;
14
  function(nullptr_t) noexcept;
15
  function(const function&);
16
- function(function&&);
17
  template<class F> function(F);
18
 
19
  function& operator=(const function&);
20
  function& operator=(function&&);
21
  function& operator=(nullptr_t) noexcept;
@@ -42,132 +42,116 @@ namespace std {
42
  template<class R, class... ArgTypes>
43
  function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
44
 
45
  template<class F> function(F) -> function<see below>;
46
 
47
- // [func.wrap.func.nullptr], Null pointer comparisons
48
  template<class R, class... ArgTypes>
49
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
50
 
51
- template <class R, class... ArgTypes>
52
- bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
53
-
54
- template <class R, class... ArgTypes>
55
- bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
56
-
57
- template <class R, class... ArgTypes>
58
- bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
59
-
60
  // [func.wrap.func.alg], specialized algorithms
61
  template<class R, class... ArgTypes>
62
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
63
  }
64
  ```
65
 
66
  The `function` class template provides polymorphic wrappers that
67
  generalize the notion of a function pointer. Wrappers can store, copy,
68
- and call arbitrary callable objects ([[func.def]]), given a call
69
- signature ([[func.def]]), allowing functions to be first-class objects.
70
 
71
- A callable type ([[func.def]]) `F` is *Lvalue-Callable* for argument
72
- types `ArgTypes` and return type `R` if the expression
73
  `INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
74
- unevaluated operand (Clause  [[expr]]), is well formed (
75
- [[func.require]]).
76
 
77
- The `function` class template is a call wrapper ([[func.def]]) whose
78
- call signature ([[func.def]]) is `R(ArgTypes...)`.
79
 
80
  [*Note 1*: The types deduced by the deduction guides for `function` may
81
  change in future versions of this International Standard. — *end note*]
82
 
83
- ##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
84
 
85
  ``` cpp
86
  function() noexcept;
87
  ```
88
 
89
- *Postconditions:* `!*this`.
90
 
91
  ``` cpp
92
  function(nullptr_t) noexcept;
93
  ```
94
 
95
- *Postconditions:* `!*this`.
96
 
97
  ``` cpp
98
  function(const function& f);
99
  ```
100
 
101
- *Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
102
  `f.target()`.
103
 
104
- *Throws:* shall not throw exceptions if `f`’s target is a specialization
105
- of `reference_wrapper` or a function pointer. Otherwise, may throw
106
  `bad_alloc` or any exception thrown by the copy constructor of the
107
  stored callable object.
108
 
109
- [*Note 1*: Implementations are encouraged to avoid the use of
110
- dynamically allocated memory for small callable objects, for example,
111
- where `f`’s target is an object holding only a pointer or reference to
112
- an object and a member function pointer. — *end note*]
113
 
114
  ``` cpp
115
- function(function&& f);
116
  ```
117
 
118
- *Postconditions:* If `!f`, `*this` has no target; otherwise, the target
119
- of `*this` is equivalent to the target of `f` before the construction,
120
- and `f` is in a valid state with an unspecified value.
121
 
122
- *Throws:* shall not throw exceptions if `f`’s target is a specialization
123
- of `reference_wrapper` or a function pointer. Otherwise, may throw
124
- `bad_alloc` or any exception thrown by the copy or move constructor of
125
- the stored callable object.
126
-
127
- [*Note 2*: Implementations are encouraged to avoid the use of
128
- dynamically allocated memory for small callable objects, for example,
129
- where `f`’s target is an object holding only a pointer or reference to
130
- an object and a member function pointer. — *end note*]
131
 
132
  ``` cpp
133
  template<class F> function(F f);
134
  ```
135
 
136
- *Requires:* `F` shall be `CopyConstructible`.
 
137
 
138
- *Remarks:* This constructor template shall not participate in overload
139
- resolution unless `F` is Lvalue-Callable ([[func.wrap.func]]) for
140
- argument types `ArgTypes...` and return type `R`.
141
 
142
- *Postconditions:* `!*this` if any of the following hold:
143
 
144
  - `f` is a null function pointer value.
145
  - `f` is a null member pointer value.
146
  - `F` is an instance of the `function` class template, and `!f`.
147
 
148
  Otherwise, `*this` targets a copy of `f` initialized with
149
  `std::move(f)`.
150
 
151
- [*Note 3*: Implementations are encouraged to avoid the use of
152
- dynamically allocated memory for small callable objects, for example,
153
- where `f` is an object holding only a pointer or reference to an object
154
- and a member function pointer. — *end note*]
155
 
156
- *Throws:* shall not throw exceptions when `f` is a function pointer or a
157
- `reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
158
- any exception thrown by `F`’s copy or move constructor.
159
 
160
  ``` cpp
161
  template<class F> function(F) -> function<see below>;
162
  ```
163
 
164
- *Remarks:* This deduction guide participates in overload resolution only
165
- if `&F::operator()` is well-formed when treated as an unevaluated
166
- operand. In that case, if `decltype(&F::operator())` is of the form
167
- `R(G::*)(A...)` cv `&`ₒₚₜ ` noexcept` for a class type `G`, then the
168
- deduced type is `function<R(A...)>`.
169
 
170
  [*Example 1*:
171
 
172
  ``` cpp
173
  void f() {
@@ -198,26 +182,25 @@ function& operator=(function&& f);
198
  function& operator=(nullptr_t) noexcept;
199
  ```
200
 
201
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
202
 
203
- *Postconditions:* `!(*this)`.
204
 
205
  *Returns:* `*this`.
206
 
207
  ``` cpp
208
  template<class F> function& operator=(F&& f);
209
  ```
210
 
 
 
 
211
  *Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
212
 
213
  *Returns:* `*this`.
214
 
215
- *Remarks:* This assignment operator shall not participate in overload
216
- resolution unless `decay_t<F>` is Lvalue-Callable ([[func.wrap.func]])
217
- for argument types `ArgTypes...` and return type `R`.
218
-
219
  ``` cpp
220
  template<class F> function& operator=(reference_wrapper<F> f) noexcept;
221
  ```
222
 
223
  *Effects:* As if by: `function(f).swap(*this);`
@@ -228,40 +211,40 @@ template<class F> function& operator=(reference_wrapper<F> f) noexcept;
228
  ~function();
229
  ```
230
 
231
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
232
 
233
- ##### `function` modifiers <a id="func.wrap.func.mod">[[func.wrap.func.mod]]</a>
234
 
235
  ``` cpp
236
  void swap(function& other) noexcept;
237
  ```
238
 
239
- *Effects:* interchanges the targets of `*this` and `other`.
240
 
241
- ##### `function` capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
242
 
243
  ``` cpp
244
  explicit operator bool() const noexcept;
245
  ```
246
 
247
  *Returns:* `true` if `*this` has a target, otherwise `false`.
248
 
249
- ##### `function` invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
250
 
251
  ``` cpp
252
  R operator()(ArgTypes... args) const;
253
  ```
254
 
255
  *Returns:* *INVOKE*\<R\>(f,
256
- std::forward\<ArgTypes\>(args)...) ([[func.require]]), where `f` is the
257
- target object ([[func.def]]) of `*this`.
258
 
259
  *Throws:* `bad_function_call` if `!*this`; otherwise, any exception
260
  thrown by the wrapped callable object.
261
 
262
- ##### `function` target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
263
 
264
  ``` cpp
265
  const type_info& target_type() const noexcept;
266
  ```
267
 
@@ -274,31 +257,20 @@ template<class T> const T* target() const noexcept;
274
  ```
275
 
276
  *Returns:* If `target_type() == typeid(T)` a pointer to the stored
277
  function target; otherwise a null pointer.
278
 
279
- ##### null pointer comparison functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
280
 
281
  ``` cpp
282
  template<class R, class... ArgTypes>
283
  bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
284
- template <class R, class... ArgTypes>
285
- bool operator==(nullptr_t, const function<R(ArgTypes...)>& f) noexcept;
286
  ```
287
 
288
  *Returns:* `!f`.
289
 
290
- ``` cpp
291
- template <class R, class... ArgTypes>
292
- bool operator!=(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
293
- template <class R, class... ArgTypes>
294
- bool operator!=(nullptr_t, const function<R(ArgTypes...)>& f) noexcept;
295
- ```
296
-
297
- *Returns:* `(bool)f`.
298
-
299
- ##### specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
300
 
301
  ``` cpp
302
  template<class R, class... ArgTypes>
303
  void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
304
  ```
 
11
 
12
  // [func.wrap.func.con], construct/copy/destroy
13
  function() noexcept;
14
  function(nullptr_t) noexcept;
15
  function(const function&);
16
+ function(function&&) noexcept;
17
  template<class F> function(F);
18
 
19
  function& operator=(const function&);
20
  function& operator=(function&&);
21
  function& operator=(nullptr_t) noexcept;
 
42
  template<class R, class... ArgTypes>
43
  function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
44
 
45
  template<class F> function(F) -> function<see below>;
46
 
47
+ // [func.wrap.func.nullptr], null pointer comparison functions
48
  template<class R, class... ArgTypes>
49
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
50
 
 
 
 
 
 
 
 
 
 
51
  // [func.wrap.func.alg], specialized algorithms
52
  template<class R, class... ArgTypes>
53
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
54
  }
55
  ```
56
 
57
  The `function` class template provides polymorphic wrappers that
58
  generalize the notion of a function pointer. Wrappers can store, copy,
59
+ and call arbitrary callable objects [[func.def]], given a call signature
60
+ [[func.def]], allowing functions to be first-class objects.
61
 
62
+ A callable type [[func.def]] `F` is *Lvalue-Callable* for argument types
63
+ `ArgTypes` and return type `R` if the expression
64
  `INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
65
+ unevaluated operand [[expr.prop]], is well-formed [[func.require]].
 
66
 
67
+ The `function` class template is a call wrapper [[func.def]] whose call
68
+ signature [[func.def]] is `R(ArgTypes...)`.
69
 
70
  [*Note 1*: The types deduced by the deduction guides for `function` may
71
  change in future versions of this International Standard. — *end note*]
72
 
73
+ ##### Constructors and destructor <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
74
 
75
  ``` cpp
76
  function() noexcept;
77
  ```
78
 
79
+ *Ensures:* `!*this`.
80
 
81
  ``` cpp
82
  function(nullptr_t) noexcept;
83
  ```
84
 
85
+ *Ensures:* `!*this`.
86
 
87
  ``` cpp
88
  function(const function& f);
89
  ```
90
 
91
+ *Ensures:* `!*this` if `!f`; otherwise, `*this` targets a copy of
92
  `f.target()`.
93
 
94
+ *Throws:* Nothing if `f`’s target is a specialization of
95
+ `reference_wrapper` or a function pointer. Otherwise, may throw
96
  `bad_alloc` or any exception thrown by the copy constructor of the
97
  stored callable object.
98
 
99
+ [*Note 1*: Implementations should avoid the use of dynamically
100
+ allocated memory for small callable objects, for example, where `f`’s
101
+ target is an object holding only a pointer or reference to an object and
102
+ a member function pointer. — *end note*]
103
 
104
  ``` cpp
105
+ function(function&& f) noexcept;
106
  ```
107
 
108
+ *Ensures:* If `!f`, `*this` has no target; otherwise, the target of
109
+ `*this` is equivalent to the target of `f` before the construction, and
110
+ `f` is in a valid state with an unspecified value.
111
 
112
+ [*Note 2*: Implementations should avoid the use of dynamically
113
+ allocated memory for small callable objects, for example, where `f`’s
114
+ target is an object holding only a pointer or reference to an object and
115
+ a member function pointer. — *end note*]
 
 
 
 
 
116
 
117
  ``` cpp
118
  template<class F> function(F f);
119
  ```
120
 
121
+ *Constraints:* `F` is Lvalue-Callable [[func.wrap.func]] for argument
122
+ types `ArgTypes...` and return type `R`.
123
 
124
+ *Preconditions:* `F` meets the *Cpp17CopyConstructible* requirements.
 
 
125
 
126
+ *Ensures:* `!*this` if any of the following hold:
127
 
128
  - `f` is a null function pointer value.
129
  - `f` is a null member pointer value.
130
  - `F` is an instance of the `function` class template, and `!f`.
131
 
132
  Otherwise, `*this` targets a copy of `f` initialized with
133
  `std::move(f)`.
134
 
135
+ [*Note 3*: Implementations should avoid the use of dynamically
136
+ allocated memory for small callable objects, for example, where `f` is
137
+ an object holding only a pointer or reference to an object and a member
138
+ function pointer. — *end note*]
139
 
140
+ *Throws:* Nothing if `f` is a specialization of `reference_wrapper` or a
141
+ function pointer. Otherwise, may throw `bad_alloc` or any exception
142
+ thrown by `F`’s copy or move constructor.
143
 
144
  ``` cpp
145
  template<class F> function(F) -> function<see below>;
146
  ```
147
 
148
+ *Constraints:* `&F::operator()` is well-formed when treated as an
149
+ unevaluated operand and `decltype(&F::operator())` is of the form
150
+ `R(G::*)(A...)` cv \\ₒₚₜ ` `noexceptₒₚₜ for a class type `G`.
151
+
152
+ *Remarks:* The deduced type is `function<R(A...)>`.
153
 
154
  [*Example 1*:
155
 
156
  ``` cpp
157
  void f() {
 
182
  function& operator=(nullptr_t) noexcept;
183
  ```
184
 
185
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
186
 
187
+ *Ensures:* `!(*this)`.
188
 
189
  *Returns:* `*this`.
190
 
191
  ``` cpp
192
  template<class F> function& operator=(F&& f);
193
  ```
194
 
195
+ *Constraints:* `decay_t<F>` is Lvalue-Callable [[func.wrap.func]] for
196
+ argument types `ArgTypes...` and return type `R`.
197
+
198
  *Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
199
 
200
  *Returns:* `*this`.
201
 
 
 
 
 
202
  ``` cpp
203
  template<class F> function& operator=(reference_wrapper<F> f) noexcept;
204
  ```
205
 
206
  *Effects:* As if by: `function(f).swap(*this);`
 
211
  ~function();
212
  ```
213
 
214
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
215
 
216
+ ##### Modifiers <a id="func.wrap.func.mod">[[func.wrap.func.mod]]</a>
217
 
218
  ``` cpp
219
  void swap(function& other) noexcept;
220
  ```
221
 
222
+ *Effects:* Interchanges the targets of `*this` and `other`.
223
 
224
+ ##### Capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
225
 
226
  ``` cpp
227
  explicit operator bool() const noexcept;
228
  ```
229
 
230
  *Returns:* `true` if `*this` has a target, otherwise `false`.
231
 
232
+ ##### Invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
233
 
234
  ``` cpp
235
  R operator()(ArgTypes... args) const;
236
  ```
237
 
238
  *Returns:* *INVOKE*\<R\>(f,
239
+ std::forward\<ArgTypes\>(args)...) [[func.require]], where `f` is the
240
+ target object [[func.def]] of `*this`.
241
 
242
  *Throws:* `bad_function_call` if `!*this`; otherwise, any exception
243
  thrown by the wrapped callable object.
244
 
245
+ ##### Target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
246
 
247
  ``` cpp
248
  const type_info& target_type() const noexcept;
249
  ```
250
 
 
257
  ```
258
 
259
  *Returns:* If `target_type() == typeid(T)` a pointer to the stored
260
  function target; otherwise a null pointer.
261
 
262
+ ##### Null pointer comparison functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
263
 
264
  ``` cpp
265
  template<class R, class... ArgTypes>
266
  bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
 
 
267
  ```
268
 
269
  *Returns:* `!f`.
270
 
271
+ ##### Specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
 
 
 
 
 
 
 
 
 
272
 
273
  ``` cpp
274
  template<class R, class... ArgTypes>
275
  void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
276
  ```