From Jason Turner

[func.wrap.func]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpn3m2w40y/{from.md → to.md} +96 -98
tmp/tmpn3m2w40y/{from.md → to.md} RENAMED
@@ -1,63 +1,52 @@
1
  #### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
2
 
3
  ``` cpp
4
  namespace std {
5
- template<class> class function; // undefined
6
 
7
  template<class R, class... ArgTypes>
8
  class function<R(ArgTypes...)> {
9
  public:
10
- typedef R result_type;
11
- typedef T1 argument_type; // only if sizeof...(ArgTypes) == 1 and
12
- // the type in ArgTypes is T1
13
- typedef T1 first_argument_type; // only if sizeof...(ArgTypes) == 2 and
14
- // ArgTypes contains T1 and T2
15
- typedef T2 second_argument_type; // only if sizeof...(ArgTypes) == 2 and
16
- // ArgTypes contains T1 and T2
17
 
18
- // [func.wrap.func.con], construct/copy/destroy:
19
  function() noexcept;
20
  function(nullptr_t) noexcept;
21
  function(const function&);
22
  function(function&&);
23
  template<class F> function(F);
24
- template<class A> function(allocator_arg_t, const A&) noexcept;
25
- template<class A> function(allocator_arg_t, const A&,
26
- nullptr_t) noexcept;
27
- template<class A> function(allocator_arg_t, const A&,
28
- const function&);
29
- template<class A> function(allocator_arg_t, const A&,
30
- function&&);
31
- template<class F, class A> function(allocator_arg_t, const A&, F);
32
 
33
  function& operator=(const function&);
34
  function& operator=(function&&);
35
- function& operator=(nullptr_t);
36
  template<class F> function& operator=(F&&);
37
  template<class F> function& operator=(reference_wrapper<F>) noexcept;
38
 
39
  ~function();
40
 
41
- // [func.wrap.func.mod], function modifiers:
42
  void swap(function&) noexcept;
43
- template<class F, class A> void assign(F&&, const A&);
44
 
45
- // [func.wrap.func.cap], function capacity:
46
  explicit operator bool() const noexcept;
47
 
48
- // [func.wrap.func.inv], function invocation:
49
  R operator()(ArgTypes...) const;
50
 
51
- // [func.wrap.func.targ], function target access:
52
- const std::type_info& target_type() const noexcept;
53
  template<class T> T* target() noexcept;
54
  template<class T> const T* target() const noexcept;
55
-
56
  };
57
 
58
- // [func.wrap.func.nullptr], Null pointer comparisons:
 
 
 
 
 
59
  template <class R, class... ArgTypes>
60
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
61
 
62
  template <class R, class... ArgTypes>
63
  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
@@ -66,154 +55,176 @@ namespace std {
66
  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
67
 
68
  template <class R, class... ArgTypes>
69
  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
70
 
71
- // [func.wrap.func.alg], specialized algorithms:
72
  template <class R, class... ArgTypes>
73
- void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
74
-
75
- template<class R, class... ArgTypes, class Alloc>
76
- struct uses_allocator<function<R(ArgTypes...)>, Alloc>
77
- : true_type { };
78
  }
79
  ```
80
 
81
  The `function` class template provides polymorphic wrappers that
82
  generalize the notion of a function pointer. Wrappers can store, copy,
83
  and call arbitrary callable objects ([[func.def]]), given a call
84
  signature ([[func.def]]), allowing functions to be first-class objects.
85
 
86
- A callable object `f` of type `F` is *Callable* for argument types
87
- `ArgTypes` and return type `R` if the expression
88
- `INVOKE(f, declval<ArgTypes>()..., R)`, considered as an unevaluated
89
- operand (Clause  [[expr]]), is well formed ([[func.require]]).
 
90
 
91
  The `function` class template is a call wrapper ([[func.def]]) whose
92
  call signature ([[func.def]]) is `R(ArgTypes...)`.
93
 
 
 
 
94
  ##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
95
 
96
- When any `function` constructor that takes a first argument of type
97
- `allocator_arg_t` is invoked, the second argument shall have a type that
98
- conforms to the requirements for Allocator (Table 
99
- [[allocator.requirements]]). A copy of the allocator argument is used to
100
- allocate memory, if necessary, for the internal data structures of the
101
- constructed `function` object.
102
-
103
  ``` cpp
104
  function() noexcept;
105
- template <class A> function(allocator_arg_t, const A& a) noexcept;
106
  ```
107
 
108
  *Postconditions:* `!*this`.
109
 
110
  ``` cpp
111
  function(nullptr_t) noexcept;
112
- template <class A> function(allocator_arg_t, const A& a, nullptr_t) noexcept;
113
  ```
114
 
115
  *Postconditions:* `!*this`.
116
 
117
  ``` cpp
118
  function(const function& f);
119
- template <class A> function(allocator_arg_t, const A& a, const function& f);
120
  ```
121
 
122
  *Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
123
  `f.target()`.
124
 
125
- *Throws:* shall not throw exceptions if `f`’s target is a callable
126
- object passed via `reference_wrapper` or a function pointer. Otherwise,
127
- may throw `bad_alloc` or any exception thrown by the copy constructor of
128
- the stored callable object. Implementations are encouraged to avoid the
129
- use of dynamically allocated memory for small callable objects, for
130
- example, where `f`’s target is an object holding only a pointer or
131
- reference to an object and a member function pointer.
 
 
132
 
133
  ``` cpp
134
  function(function&& f);
135
- template <class A> function(allocator_arg_t, const A& a, function&& f);
136
  ```
137
 
138
- *Effects:* If `!f`, `*this` has no target; otherwise, move-constructs
139
- the target of `f` into the target of `*this`, leaving `f` in a valid
140
- state with an unspecified value.
 
 
 
 
 
 
 
 
 
 
141
 
142
  ``` cpp
143
  template<class F> function(F f);
144
- template <class F, class A> function(allocator_arg_t, const A& a, F f);
145
  ```
146
 
147
  *Requires:* `F` shall be `CopyConstructible`.
148
 
149
- *Remarks:* These constructors shall not participate in overload
150
- resolution unless `f` is Callable ([[func.wrap.func]]) for argument
151
- types `ArgTypes...` and return type `R`.
152
 
153
  *Postconditions:* `!*this` if any of the following hold:
154
 
155
  - `f` is a null function pointer value.
156
  - `f` is a null member pointer value.
157
  - `F` is an instance of the `function` class template, and `!f`.
158
 
159
  Otherwise, `*this` targets a copy of `f` initialized with
160
- `std::move(f)`. Implementations are encouraged to avoid the use of
 
 
161
  dynamically allocated memory for small callable objects, for example,
162
- where `f`’s target is an object holding only a pointer or reference to
163
- an object and a member function pointer.
164
 
165
  *Throws:* shall not throw exceptions when `f` is a function pointer or a
166
  `reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
167
  any exception thrown by `F`’s copy or move constructor.
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  ``` cpp
170
  function& operator=(const function& f);
171
  ```
172
 
173
- *Effects:* `function(f).swap(*this);`
174
 
175
- *Returns:* `*this`
176
 
177
  ``` cpp
178
  function& operator=(function&& f);
179
  ```
180
 
181
  *Effects:* Replaces the target of `*this` with the target of `f`.
182
 
183
- *Returns:* `*this`
184
 
185
  ``` cpp
186
- function& operator=(nullptr_t);
187
  ```
188
 
189
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
190
 
191
  *Postconditions:* `!(*this)`.
192
 
193
- *Returns:* `*this`
194
 
195
  ``` cpp
196
  template<class F> function& operator=(F&& f);
197
  ```
198
 
199
- *Effects:* `function(std::forward<F>(f)).swap(*this);`
200
 
201
- *Returns:* `*this`
202
 
203
  *Remarks:* This assignment operator shall not participate in overload
204
- resolution unless `declval<typename decay<F>::type&>()` is
205
- Callable ([[func.wrap.func]]) for argument types `ArgTypes...` and
206
- return type `R`.
207
 
208
  ``` cpp
209
  template<class F> function& operator=(reference_wrapper<F> f) noexcept;
210
  ```
211
 
212
- *Effects:* `function(f).swap(*this);`
213
 
214
- *Returns:* `*this`
215
 
216
  ``` cpp
217
  ~function();
218
  ```
219
 
@@ -225,17 +236,10 @@ template<class F> function& operator=(reference_wrapper<F> f) noexcept;
225
  void swap(function& other) noexcept;
226
  ```
227
 
228
  *Effects:* interchanges the targets of `*this` and `other`.
229
 
230
- ``` cpp
231
- template<class F, class A>
232
- void assign(F&& f, const A& a);
233
- ```
234
-
235
- *Effects:* `function(allocator_arg, a, std::forward<F>(f)).swap(*this)`
236
-
237
  ##### `function` capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
238
 
239
  ``` cpp
240
  explicit operator bool() const noexcept;
241
  ```
@@ -243,44 +247,38 @@ explicit operator bool() const noexcept;
243
  *Returns:* `true` if `*this` has a target, otherwise `false`.
244
 
245
  ##### `function` invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
246
 
247
  ``` cpp
248
- R operator()(ArgTypes... args) const
249
  ```
250
 
251
- *Effects:*
252
- *`INVOKE`*`(f, std::forward<ArgTypes>(args)..., R)` ([[func.require]]),
253
- where `f` is the target object ([[func.def]]) of `*this`.
254
-
255
- *Returns:* Nothing if `R` is `void`, otherwise the return value of
256
- *`INVOKE`*`(f, std::forward<ArgTypes>(args)..., R)`.
257
 
258
  *Throws:* `bad_function_call` if `!*this`; otherwise, any exception
259
  thrown by the wrapped callable object.
260
 
261
- ##### function target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
262
 
263
  ``` cpp
264
- const std::type_info& target_type() const noexcept;
265
  ```
266
 
267
  *Returns:* If `*this` has a target of type `T`, `typeid(T)`; otherwise,
268
  `typeid(void)`.
269
 
270
  ``` cpp
271
  template<class T> T* target() noexcept;
272
  template<class T> const T* target() const noexcept;
273
  ```
274
 
275
- *Requires:* `T` shall be a type that is Callable ([[func.wrap.func]])
276
- for parameter types `ArgTypes` and return type `R`.
277
-
278
  *Returns:* If `target_type() == typeid(T)` a pointer to the stored
279
  function target; otherwise a null pointer.
280
 
281
- ##### null pointer comparison operators <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
282
 
283
  ``` cpp
284
  template <class R, class... ArgTypes>
285
  bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
286
  template <class R, class... ArgTypes>
@@ -300,10 +298,10 @@ template <class R, class... ArgTypes>
300
 
301
  ##### specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
302
 
303
  ``` cpp
304
  template<class R, class... ArgTypes>
305
- void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2);
306
  ```
307
 
308
- *Effects:* `f1.swap(f2);`
309
 
 
1
  #### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
2
 
3
  ``` cpp
4
  namespace std {
5
+ template<class> class function; // not defined
6
 
7
  template<class R, class... ArgTypes>
8
  class function<R(ArgTypes...)> {
9
  public:
10
+ using result_type = R;
 
 
 
 
 
 
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;
22
  template<class F> function& operator=(F&&);
23
  template<class F> function& operator=(reference_wrapper<F>) noexcept;
24
 
25
  ~function();
26
 
27
+ // [func.wrap.func.mod], function modifiers
28
  void swap(function&) noexcept;
 
29
 
30
+ // [func.wrap.func.cap], function capacity
31
  explicit operator bool() const noexcept;
32
 
33
+ // [func.wrap.func.inv], function invocation
34
  R operator()(ArgTypes...) const;
35
 
36
+ // [func.wrap.func.targ], function target access
37
+ const type_info& target_type() const noexcept;
38
  template<class T> T* target() noexcept;
39
  template<class T> const T* target() const noexcept;
 
40
  };
41
 
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;
 
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() {
174
+ int i{5};
175
+ function g = [&](double) { return i; }; // deduces function<int(double)>
176
+ }
177
+ ```
178
+
179
+ — *end example*]
180
+
181
  ``` cpp
182
  function& operator=(const function& f);
183
  ```
184
 
185
+ *Effects:* As if by `function(f).swap(*this);`
186
 
187
+ *Returns:* `*this`.
188
 
189
  ``` cpp
190
  function& operator=(function&& f);
191
  ```
192
 
193
  *Effects:* Replaces the target of `*this` with the target of `f`.
194
 
195
+ *Returns:* `*this`.
196
 
197
  ``` cpp
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);`
224
 
225
+ *Returns:* `*this`.
226
 
227
  ``` cpp
228
  ~function();
229
  ```
230
 
 
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
  ```
 
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
 
268
  *Returns:* If `*this` has a target of type `T`, `typeid(T)`; otherwise,
269
  `typeid(void)`.
270
 
271
  ``` cpp
272
  template<class T> T* target() noexcept;
273
  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>
 
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
  ```
305
 
306
+ *Effects:* As if by: `f1.swap(f2);`
307