- tmp/tmpnp7cdv59/{from.md → to.md} +325 -45
tmp/tmpnp7cdv59/{from.md → to.md}
RENAMED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
#### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
|
| 7 |
|
| 8 |
An exception of type `bad_function_call` is thrown by
|
| 9 |
`function::operator()` [[func.wrap.func.inv]] when the function wrapper
|
|
@@ -25,10 +27,12 @@ const char* what() const noexcept override;
|
|
| 25 |
|
| 26 |
*Returns:* An *implementation-defined* NTBS.
|
| 27 |
|
| 28 |
#### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
|
| 29 |
|
|
|
|
|
|
|
| 30 |
``` cpp
|
| 31 |
namespace std {
|
| 32 |
template<class> class function; // not defined
|
| 33 |
|
| 34 |
template<class R, class... ArgTypes>
|
|
@@ -39,11 +43,11 @@ namespace std {
|
|
| 39 |
// [func.wrap.func.con], construct/copy/destroy
|
| 40 |
function() noexcept;
|
| 41 |
function(nullptr_t) noexcept;
|
| 42 |
function(const function&);
|
| 43 |
function(function&&) noexcept;
|
| 44 |
-
template<class F> function(F);
|
| 45 |
|
| 46 |
function& operator=(const function&);
|
| 47 |
function& operator=(function&&);
|
| 48 |
function& operator=(nullptr_t) noexcept;
|
| 49 |
template<class F> function& operator=(F&&);
|
|
@@ -68,36 +72,29 @@ namespace std {
|
|
| 68 |
|
| 69 |
template<class R, class... ArgTypes>
|
| 70 |
function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
|
| 71 |
|
| 72 |
template<class F> function(F) -> function<see below>;
|
| 73 |
-
|
| 74 |
-
// [func.wrap.func.nullptr], null pointer comparison functions
|
| 75 |
-
template<class R, class... ArgTypes>
|
| 76 |
-
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 77 |
-
|
| 78 |
-
// [func.wrap.func.alg], specialized algorithms
|
| 79 |
-
template<class R, class... ArgTypes>
|
| 80 |
-
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
|
| 81 |
}
|
| 82 |
```
|
| 83 |
|
| 84 |
The `function` class template provides polymorphic wrappers that
|
| 85 |
generalize the notion of a function pointer. Wrappers can store, copy,
|
| 86 |
and call arbitrary callable objects [[func.def]], given a call signature
|
| 87 |
-
[[func.def]]
|
| 88 |
|
| 89 |
A callable type [[func.def]] `F` is *Lvalue-Callable* for argument types
|
| 90 |
`ArgTypes` and return type `R` if the expression
|
| 91 |
`INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
|
| 92 |
-
unevaluated operand [[
|
|
|
|
| 93 |
|
| 94 |
The `function` class template is a call wrapper [[func.def]] whose call
|
| 95 |
signature [[func.def]] is `R(ArgTypes...)`.
|
| 96 |
|
| 97 |
-
[*Note 1*: The types deduced by the deduction guides for `function`
|
| 98 |
-
change in future
|
| 99 |
|
| 100 |
##### Constructors and destructor <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
|
| 101 |
|
| 102 |
``` cpp
|
| 103 |
function() noexcept;
|
|
@@ -113,70 +110,87 @@ function(nullptr_t) noexcept;
|
|
| 113 |
|
| 114 |
``` cpp
|
| 115 |
function(const function& f);
|
| 116 |
```
|
| 117 |
|
| 118 |
-
*Ensures:* `!*this` if `!f`; otherwise, `*this`
|
| 119 |
-
`f.target()`.
|
| 120 |
|
| 121 |
*Throws:* Nothing if `f`’s target is a specialization of
|
| 122 |
`reference_wrapper` or a function pointer. Otherwise, may throw
|
| 123 |
`bad_alloc` or any exception thrown by the copy constructor of the
|
| 124 |
stored callable object.
|
| 125 |
|
| 126 |
-
|
| 127 |
-
allocated memory for small callable objects, for example,
|
| 128 |
-
target is an object holding only a pointer or reference to
|
| 129 |
-
a member function pointer.
|
| 130 |
|
| 131 |
``` cpp
|
| 132 |
function(function&& f) noexcept;
|
| 133 |
```
|
| 134 |
|
| 135 |
*Ensures:* If `!f`, `*this` has no target; otherwise, the target of
|
| 136 |
`*this` is equivalent to the target of `f` before the construction, and
|
| 137 |
`f` is in a valid state with an unspecified value.
|
| 138 |
|
| 139 |
-
|
| 140 |
-
allocated memory for small callable objects, for example,
|
| 141 |
-
target is an object holding only a pointer or reference to
|
| 142 |
-
a member function pointer.
|
| 143 |
|
| 144 |
``` cpp
|
| 145 |
-
template<class F> function(F f);
|
| 146 |
```
|
| 147 |
|
| 148 |
-
|
| 149 |
-
types `ArgTypes...` and return type `R`.
|
| 150 |
|
| 151 |
-
*
|
| 152 |
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
- `f` is a null function pointer value.
|
| 156 |
- `f` is a null member pointer value.
|
| 157 |
-
- `F` is
|
|
|
|
| 158 |
|
| 159 |
-
Otherwise, `*this`
|
| 160 |
-
`std::
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
function pointer. — *end note*]
|
| 166 |
|
| 167 |
-
*
|
| 168 |
-
|
| 169 |
-
|
|
|
|
| 170 |
|
| 171 |
``` cpp
|
| 172 |
template<class F> function(F) -> function<see below>;
|
| 173 |
```
|
| 174 |
|
| 175 |
*Constraints:* `&F::operator()` is well-formed when treated as an
|
| 176 |
-
unevaluated operand and
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
*Remarks:* The deduced type is `function<R(A...)>`.
|
| 180 |
|
| 181 |
[*Example 1*:
|
| 182 |
|
|
@@ -244,11 +258,11 @@ template<class F> function& operator=(reference_wrapper<F> f) noexcept;
|
|
| 244 |
|
| 245 |
``` cpp
|
| 246 |
void swap(function& other) noexcept;
|
| 247 |
```
|
| 248 |
|
| 249 |
-
*Effects:* Interchanges the
|
| 250 |
|
| 251 |
##### Capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
|
| 252 |
|
| 253 |
``` cpp
|
| 254 |
explicit operator bool() const noexcept;
|
|
@@ -265,11 +279,11 @@ R operator()(ArgTypes... args) const;
|
|
| 265 |
*Returns:* *INVOKE*\<R\>(f,
|
| 266 |
std::forward\<ArgTypes\>(args)...) [[func.require]], where `f` is the
|
| 267 |
target object [[func.def]] of `*this`.
|
| 268 |
|
| 269 |
*Throws:* `bad_function_call` if `!*this`; otherwise, any exception
|
| 270 |
-
thrown by the
|
| 271 |
|
| 272 |
##### Target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
|
| 273 |
|
| 274 |
``` cpp
|
| 275 |
const type_info& target_type() const noexcept;
|
|
@@ -284,11 +298,11 @@ template<class T> const T* target() const noexcept;
|
|
| 284 |
```
|
| 285 |
|
| 286 |
*Returns:* If `target_type() == typeid(T)` a pointer to the stored
|
| 287 |
function target; otherwise a null pointer.
|
| 288 |
|
| 289 |
-
##### Null pointer comparison functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
|
| 290 |
|
| 291 |
``` cpp
|
| 292 |
template<class R, class... ArgTypes>
|
| 293 |
bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
|
| 294 |
```
|
|
@@ -302,5 +316,271 @@ template<class R, class... ArgTypes>
|
|
| 302 |
void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
|
| 303 |
```
|
| 304 |
|
| 305 |
*Effects:* As if by: `f1.swap(f2);`
|
| 306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="func.wrap.general">[[func.wrap.general]]</a>
|
| 4 |
+
|
| 5 |
+
Subclause [[func.wrap]] describes polymorphic wrapper classes that
|
| 6 |
+
encapsulate arbitrary callable objects.
|
| 7 |
|
| 8 |
#### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
|
| 9 |
|
| 10 |
An exception of type `bad_function_call` is thrown by
|
| 11 |
`function::operator()` [[func.wrap.func.inv]] when the function wrapper
|
|
|
|
| 27 |
|
| 28 |
*Returns:* An *implementation-defined* NTBS.
|
| 29 |
|
| 30 |
#### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
|
| 31 |
|
| 32 |
+
##### General <a id="func.wrap.func.general">[[func.wrap.func.general]]</a>
|
| 33 |
+
|
| 34 |
``` cpp
|
| 35 |
namespace std {
|
| 36 |
template<class> class function; // not defined
|
| 37 |
|
| 38 |
template<class R, class... ArgTypes>
|
|
|
|
| 43 |
// [func.wrap.func.con], construct/copy/destroy
|
| 44 |
function() noexcept;
|
| 45 |
function(nullptr_t) noexcept;
|
| 46 |
function(const function&);
|
| 47 |
function(function&&) noexcept;
|
| 48 |
+
template<class F> function(F&&);
|
| 49 |
|
| 50 |
function& operator=(const function&);
|
| 51 |
function& operator=(function&&);
|
| 52 |
function& operator=(nullptr_t) noexcept;
|
| 53 |
template<class F> function& operator=(F&&);
|
|
|
|
| 72 |
|
| 73 |
template<class R, class... ArgTypes>
|
| 74 |
function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
|
| 75 |
|
| 76 |
template<class F> function(F) -> function<see below>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
```
|
| 79 |
|
| 80 |
The `function` class template provides polymorphic wrappers that
|
| 81 |
generalize the notion of a function pointer. Wrappers can store, copy,
|
| 82 |
and call arbitrary callable objects [[func.def]], given a call signature
|
| 83 |
+
[[func.def]].
|
| 84 |
|
| 85 |
A callable type [[func.def]] `F` is *Lvalue-Callable* for argument types
|
| 86 |
`ArgTypes` and return type `R` if the expression
|
| 87 |
`INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
|
| 88 |
+
unevaluated operand [[term.unevaluated.operand]], is well-formed
|
| 89 |
+
[[func.require]].
|
| 90 |
|
| 91 |
The `function` class template is a call wrapper [[func.def]] whose call
|
| 92 |
signature [[func.def]] is `R(ArgTypes...)`.
|
| 93 |
|
| 94 |
+
[*Note 1*: The types deduced by the deduction guides for `function`
|
| 95 |
+
might change in future revisions of C++. — *end note*]
|
| 96 |
|
| 97 |
##### Constructors and destructor <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
|
| 98 |
|
| 99 |
``` cpp
|
| 100 |
function() noexcept;
|
|
|
|
| 110 |
|
| 111 |
``` cpp
|
| 112 |
function(const function& f);
|
| 113 |
```
|
| 114 |
|
| 115 |
+
*Ensures:* `!*this` if `!f`; otherwise, the target object of `*this` is
|
| 116 |
+
a copy of `f.target()`.
|
| 117 |
|
| 118 |
*Throws:* Nothing if `f`’s target is a specialization of
|
| 119 |
`reference_wrapper` or a function pointer. Otherwise, may throw
|
| 120 |
`bad_alloc` or any exception thrown by the copy constructor of the
|
| 121 |
stored callable object.
|
| 122 |
|
| 123 |
+
*Recommended practice:* Implementations should avoid the use of
|
| 124 |
+
dynamically allocated memory for small callable objects, for example,
|
| 125 |
+
where `f`’s target is an object holding only a pointer or reference to
|
| 126 |
+
an object and a member function pointer.
|
| 127 |
|
| 128 |
``` cpp
|
| 129 |
function(function&& f) noexcept;
|
| 130 |
```
|
| 131 |
|
| 132 |
*Ensures:* If `!f`, `*this` has no target; otherwise, the target of
|
| 133 |
`*this` is equivalent to the target of `f` before the construction, and
|
| 134 |
`f` is in a valid state with an unspecified value.
|
| 135 |
|
| 136 |
+
*Recommended practice:* Implementations should avoid the use of
|
| 137 |
+
dynamically allocated memory for small callable objects, for example,
|
| 138 |
+
where `f`’s target is an object holding only a pointer or reference to
|
| 139 |
+
an object and a member function pointer.
|
| 140 |
|
| 141 |
``` cpp
|
| 142 |
+
template<class F> function(F&& f);
|
| 143 |
```
|
| 144 |
|
| 145 |
+
Let `FD` be `decay_t<F>`.
|
|
|
|
| 146 |
|
| 147 |
+
*Constraints:*
|
| 148 |
|
| 149 |
+
- `is_same_v<remove_cvref_t<F>, function>` is `false`, and
|
| 150 |
+
- `FD` is Lvalue-Callable [[func.wrap.func]] for argument types
|
| 151 |
+
`ArgTypes...` and return type `R`.
|
| 152 |
+
|
| 153 |
+
*Mandates:*
|
| 154 |
+
|
| 155 |
+
- `is_copy_constructible_v<FD>` is `true`, and
|
| 156 |
+
- `is_constructible_v<FD, F>` is `true`.
|
| 157 |
+
|
| 158 |
+
*Preconditions:* `FD` meets the *Cpp17CopyConstructible* requirements.
|
| 159 |
+
|
| 160 |
+
*Ensures:* `!*this` is `true` if any of the following hold:
|
| 161 |
|
| 162 |
- `f` is a null function pointer value.
|
| 163 |
- `f` is a null member pointer value.
|
| 164 |
+
- `remove_cvref_t<F>` is a specialization of the `function` class
|
| 165 |
+
template, and `!f` is `true`.
|
| 166 |
|
| 167 |
+
Otherwise, `*this` has a target object of type `FD`
|
| 168 |
+
direct-non-list-initialized with `std::forward<F>(f)`.
|
| 169 |
|
| 170 |
+
*Throws:* Nothing if `FD` is a specialization of `reference_wrapper` or
|
| 171 |
+
a function pointer type. Otherwise, may throw `bad_alloc` or any
|
| 172 |
+
exception thrown by the initialization of the target object.
|
|
|
|
| 173 |
|
| 174 |
+
*Recommended practice:* Implementations should avoid the use of
|
| 175 |
+
dynamically allocated memory for small callable objects, for example,
|
| 176 |
+
where `f` refers to an object holding only a pointer or reference to an
|
| 177 |
+
object and a member function pointer.
|
| 178 |
|
| 179 |
``` cpp
|
| 180 |
template<class F> function(F) -> function<see below>;
|
| 181 |
```
|
| 182 |
|
| 183 |
*Constraints:* `&F::operator()` is well-formed when treated as an
|
| 184 |
+
unevaluated operand and either
|
| 185 |
+
|
| 186 |
+
- `F::operator()` is a non-static member function and
|
| 187 |
+
`decltype(&F::operator())` is either of the form
|
| 188 |
+
`R(G::*)(A...)` cv \\ₒₚₜ ` `noexceptₒₚₜ or of the form
|
| 189 |
+
`R(*)(G, A...) `noexceptₒₚₜ for a type `G`, or
|
| 190 |
+
- `F::operator()` is a static member function and
|
| 191 |
+
`decltype(&F::operator())` is of the form `R(*)(A...) `noexceptₒₚₜ .
|
| 192 |
|
| 193 |
*Remarks:* The deduced type is `function<R(A...)>`.
|
| 194 |
|
| 195 |
[*Example 1*:
|
| 196 |
|
|
|
|
| 258 |
|
| 259 |
``` cpp
|
| 260 |
void swap(function& other) noexcept;
|
| 261 |
```
|
| 262 |
|
| 263 |
+
*Effects:* Interchanges the target objects of `*this` and `other`.
|
| 264 |
|
| 265 |
##### Capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
|
| 266 |
|
| 267 |
``` cpp
|
| 268 |
explicit operator bool() const noexcept;
|
|
|
|
| 279 |
*Returns:* *INVOKE*\<R\>(f,
|
| 280 |
std::forward\<ArgTypes\>(args)...) [[func.require]], where `f` is the
|
| 281 |
target object [[func.def]] of `*this`.
|
| 282 |
|
| 283 |
*Throws:* `bad_function_call` if `!*this`; otherwise, any exception
|
| 284 |
+
thrown by the target object.
|
| 285 |
|
| 286 |
##### Target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
|
| 287 |
|
| 288 |
``` cpp
|
| 289 |
const type_info& target_type() const noexcept;
|
|
|
|
| 298 |
```
|
| 299 |
|
| 300 |
*Returns:* If `target_type() == typeid(T)` a pointer to the stored
|
| 301 |
function target; otherwise a null pointer.
|
| 302 |
|
| 303 |
+
##### Null pointer comparison operator functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
|
| 304 |
|
| 305 |
``` cpp
|
| 306 |
template<class R, class... ArgTypes>
|
| 307 |
bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
|
| 308 |
```
|
|
|
|
| 316 |
void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
|
| 317 |
```
|
| 318 |
|
| 319 |
*Effects:* As if by: `f1.swap(f2);`
|
| 320 |
|
| 321 |
+
#### Move only wrapper <a id="func.wrap.move">[[func.wrap.move]]</a>
|
| 322 |
+
|
| 323 |
+
##### General <a id="func.wrap.move.general">[[func.wrap.move.general]]</a>
|
| 324 |
+
|
| 325 |
+
The header provides partial specializations of `move_only_function` for
|
| 326 |
+
each combination of the possible replacements of the placeholders cv,
|
| 327 |
+
*ref*, and *noex* where
|
| 328 |
+
|
| 329 |
+
- cv is either const or empty,
|
| 330 |
+
- *ref* is either `&`, `&&`, or empty, and
|
| 331 |
+
- *noex* is either `true` or `false`.
|
| 332 |
+
|
| 333 |
+
For each of the possible combinations of the placeholders mentioned
|
| 334 |
+
above, there is a placeholder *inv-quals* defined as follows:
|
| 335 |
+
|
| 336 |
+
- If *ref* is empty, let *inv-quals* be cv`&`,
|
| 337 |
+
- otherwise, let *inv-quals* be cv *ref*.
|
| 338 |
+
|
| 339 |
+
##### Class template `move_only_function` <a id="func.wrap.move.class">[[func.wrap.move.class]]</a>
|
| 340 |
+
|
| 341 |
+
``` cpp
|
| 342 |
+
namespace std {
|
| 343 |
+
template<class... S> class move_only_function; // not defined
|
| 344 |
+
|
| 345 |
+
template<class R, class... ArgTypes>
|
| 346 |
+
class move_only_function<R(ArgTypes...) cv ref noexcept(noex)> {
|
| 347 |
+
public:
|
| 348 |
+
using result_type = R;
|
| 349 |
+
|
| 350 |
+
// [func.wrap.move.ctor], constructors, assignment, and destructor
|
| 351 |
+
move_only_function() noexcept;
|
| 352 |
+
move_only_function(nullptr_t) noexcept;
|
| 353 |
+
move_only_function(move_only_function&&) noexcept;
|
| 354 |
+
template<class F> move_only_function(F&&);
|
| 355 |
+
template<class T, class... Args>
|
| 356 |
+
explicit move_only_function(in_place_type_t<T>, Args&&...);
|
| 357 |
+
template<class T, class U, class... Args>
|
| 358 |
+
explicit move_only_function(in_place_type_t<T>, initializer_list<U>, Args&&...);
|
| 359 |
+
|
| 360 |
+
move_only_function& operator=(move_only_function&&);
|
| 361 |
+
move_only_function& operator=(nullptr_t) noexcept;
|
| 362 |
+
template<class F> move_only_function& operator=(F&&);
|
| 363 |
+
|
| 364 |
+
~move_only_function();
|
| 365 |
+
|
| 366 |
+
// [func.wrap.move.inv], invocation
|
| 367 |
+
explicit operator bool() const noexcept;
|
| 368 |
+
R operator()(ArgTypes...) cv ref noexcept(noex);
|
| 369 |
+
|
| 370 |
+
// [func.wrap.move.util], utility
|
| 371 |
+
void swap(move_only_function&) noexcept;
|
| 372 |
+
friend void swap(move_only_function&, move_only_function&) noexcept;
|
| 373 |
+
friend bool operator==(const move_only_function&, nullptr_t) noexcept;
|
| 374 |
+
|
| 375 |
+
private:
|
| 376 |
+
template<class VT>
|
| 377 |
+
static constexpr bool is-callable-from = see below; // exposition only
|
| 378 |
+
};
|
| 379 |
+
}
|
| 380 |
+
```
|
| 381 |
+
|
| 382 |
+
The `move_only_function` class template provides polymorphic wrappers
|
| 383 |
+
that generalize the notion of a callable object [[func.def]]. These
|
| 384 |
+
wrappers can store, move, and call arbitrary callable objects, given a
|
| 385 |
+
call signature.
|
| 386 |
+
|
| 387 |
+
*Recommended practice:* Implementations should avoid the use of
|
| 388 |
+
dynamically allocated memory for a small contained value.
|
| 389 |
+
|
| 390 |
+
[*Note 1*: Such small-object optimization can only be applied to a type
|
| 391 |
+
`T` for which `is_nothrow_move_constructible_v<T>` is
|
| 392 |
+
`true`. — *end note*]
|
| 393 |
+
|
| 394 |
+
##### Constructors, assignment, and destructor <a id="func.wrap.move.ctor">[[func.wrap.move.ctor]]</a>
|
| 395 |
+
|
| 396 |
+
``` cpp
|
| 397 |
+
template<class VT>
|
| 398 |
+
static constexpr bool is-callable-from = see below;
|
| 399 |
+
```
|
| 400 |
+
|
| 401 |
+
If *noex* is `true`, *`is-callable-from`*`<VT>` is equal to:
|
| 402 |
+
|
| 403 |
+
``` cpp
|
| 404 |
+
is_nothrow_invocable_r_v<R, VT cv ref, ArgTypes...> &&
|
| 405 |
+
is_nothrow_invocable_r_v<R, VT inv-quals, ArgTypes...>
|
| 406 |
+
```
|
| 407 |
+
|
| 408 |
+
Otherwise, *`is-callable-from`*`<VT>` is equal to:
|
| 409 |
+
|
| 410 |
+
``` cpp
|
| 411 |
+
is_invocable_r_v<R, VT cv ref, ArgTypes...> &&
|
| 412 |
+
is_invocable_r_v<R, VT inv-quals, ArgTypes...>
|
| 413 |
+
```
|
| 414 |
+
|
| 415 |
+
``` cpp
|
| 416 |
+
move_only_function() noexcept;
|
| 417 |
+
move_only_function(nullptr_t) noexcept;
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
*Ensures:* `*this` has no target object.
|
| 421 |
+
|
| 422 |
+
``` cpp
|
| 423 |
+
move_only_function(move_only_function&& f) noexcept;
|
| 424 |
+
```
|
| 425 |
+
|
| 426 |
+
*Ensures:* The target object of `*this` is the target object `f` had
|
| 427 |
+
before construction, and `f` is in a valid state with an unspecified
|
| 428 |
+
value.
|
| 429 |
+
|
| 430 |
+
``` cpp
|
| 431 |
+
template<class F> move_only_function(F&& f);
|
| 432 |
+
```
|
| 433 |
+
|
| 434 |
+
Let `VT` be `decay_t<F>`.
|
| 435 |
+
|
| 436 |
+
*Constraints:*
|
| 437 |
+
|
| 438 |
+
- `remove_cvref_t<F>` is not the same type as `move_only_function`, and
|
| 439 |
+
- `remove_cvref_t<F>` is not a specialization of `in_place_type_t`, and
|
| 440 |
+
- *`is-callable-from`*`<VT>` is `true`.
|
| 441 |
+
|
| 442 |
+
*Mandates:* `is_constructible_v<VT, F>` is `true`.
|
| 443 |
+
|
| 444 |
+
*Preconditions:* `VT` meets the *Cpp17Destructible* requirements, and if
|
| 445 |
+
`is_move_constructible_v<VT>` is `true`, `VT` meets the
|
| 446 |
+
*Cpp17MoveConstructible* requirements.
|
| 447 |
+
|
| 448 |
+
*Ensures:* `*this` has no target object if any of the following hold:
|
| 449 |
+
|
| 450 |
+
- `f` is a null function pointer value, or
|
| 451 |
+
- `f` is a null member pointer value, or
|
| 452 |
+
- `remove_cvref_t<F>` is a specialization of the `move_only_function`
|
| 453 |
+
class template, and `f` has no target object.
|
| 454 |
+
|
| 455 |
+
Otherwise, `*this` has a target object of type `VT`
|
| 456 |
+
direct-non-list-initialized with `std::forward<F>(f)`.
|
| 457 |
+
|
| 458 |
+
*Throws:* Any exception thrown by the initialization of the target
|
| 459 |
+
object. May throw `bad_alloc` unless `VT` is a function pointer or a
|
| 460 |
+
specialization of `reference_wrapper`.
|
| 461 |
+
|
| 462 |
+
``` cpp
|
| 463 |
+
template<class T, class... Args>
|
| 464 |
+
explicit move_only_function(in_place_type_t<T>, Args&&... args);
|
| 465 |
+
```
|
| 466 |
+
|
| 467 |
+
Let `VT` be `decay_t<T>`.
|
| 468 |
+
|
| 469 |
+
*Constraints:*
|
| 470 |
+
|
| 471 |
+
- `is_constructible_v<VT, Args...>` is `true`, and
|
| 472 |
+
- *`is-callable-from`*`<VT>` is `true`.
|
| 473 |
+
|
| 474 |
+
*Mandates:* `VT` is the same type as `T`.
|
| 475 |
+
|
| 476 |
+
*Preconditions:* `VT` meets the *Cpp17Destructible* requirements, and if
|
| 477 |
+
`is_move_constructible_v<VT>` is `true`, `VT` meets the
|
| 478 |
+
*Cpp17MoveConstructible* requirements.
|
| 479 |
+
|
| 480 |
+
*Ensures:* `*this` has a target object of type `VT`
|
| 481 |
+
direct-non-list-initialized with `std::forward<Args>(args)...`.
|
| 482 |
+
|
| 483 |
+
*Throws:* Any exception thrown by the initialization of the target
|
| 484 |
+
object. May throw `bad_alloc` unless `VT` is a function pointer or a
|
| 485 |
+
specialization of `reference_wrapper`.
|
| 486 |
+
|
| 487 |
+
``` cpp
|
| 488 |
+
template<class T, class U, class... Args>
|
| 489 |
+
explicit move_only_function(in_place_type_t<T>, initializer_list<U> ilist, Args&&... args);
|
| 490 |
+
```
|
| 491 |
+
|
| 492 |
+
Let `VT` be `decay_t<T>`.
|
| 493 |
+
|
| 494 |
+
*Constraints:*
|
| 495 |
+
|
| 496 |
+
- `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`, and
|
| 497 |
+
- *`is-callable-from`*`<VT>` is `true`.
|
| 498 |
+
|
| 499 |
+
*Mandates:* `VT` is the same type as `T`.
|
| 500 |
+
|
| 501 |
+
*Preconditions:* `VT` meets the *Cpp17Destructible* requirements, and if
|
| 502 |
+
`is_move_constructible_v<VT>` is `true`, `VT` meets the
|
| 503 |
+
*Cpp17MoveConstructible* requirements.
|
| 504 |
+
|
| 505 |
+
*Ensures:* `*this` has a target object of type `VT`
|
| 506 |
+
direct-non-list-initialized with `ilist, std::forward<Args>(args)...`.
|
| 507 |
+
|
| 508 |
+
*Throws:* Any exception thrown by the initialization of the target
|
| 509 |
+
object. May throw `bad_alloc` unless `VT` is a function pointer or a
|
| 510 |
+
specialization of `reference_wrapper`.
|
| 511 |
+
|
| 512 |
+
``` cpp
|
| 513 |
+
move_only_function& operator=(move_only_function&& f);
|
| 514 |
+
```
|
| 515 |
+
|
| 516 |
+
*Effects:* Equivalent to:
|
| 517 |
+
`move_only_function(std::move(f)).swap(*this);`
|
| 518 |
+
|
| 519 |
+
*Returns:* `*this`.
|
| 520 |
+
|
| 521 |
+
``` cpp
|
| 522 |
+
move_only_function& operator=(nullptr_t) noexcept;
|
| 523 |
+
```
|
| 524 |
+
|
| 525 |
+
*Effects:* Destroys the target object of `*this`, if any.
|
| 526 |
+
|
| 527 |
+
*Returns:* `*this`.
|
| 528 |
+
|
| 529 |
+
``` cpp
|
| 530 |
+
template<class F> move_only_function& operator=(F&& f);
|
| 531 |
+
```
|
| 532 |
+
|
| 533 |
+
*Effects:* Equivalent to:
|
| 534 |
+
`move_only_function(std::forward<F>(f)).swap(*this);`
|
| 535 |
+
|
| 536 |
+
*Returns:* `*this`.
|
| 537 |
+
|
| 538 |
+
``` cpp
|
| 539 |
+
~move_only_function();
|
| 540 |
+
```
|
| 541 |
+
|
| 542 |
+
*Effects:* Destroys the target object of `*this`, if any.
|
| 543 |
+
|
| 544 |
+
##### Invocation <a id="func.wrap.move.inv">[[func.wrap.move.inv]]</a>
|
| 545 |
+
|
| 546 |
+
``` cpp
|
| 547 |
+
explicit operator bool() const noexcept;
|
| 548 |
+
```
|
| 549 |
+
|
| 550 |
+
*Returns:* `true` if `*this` has a target object, otherwise `false`.
|
| 551 |
+
|
| 552 |
+
``` cpp
|
| 553 |
+
R operator()(ArgTypes... args) cv ref noexcept(noex);
|
| 554 |
+
```
|
| 555 |
+
|
| 556 |
+
*Preconditions:* `*this` has a target object.
|
| 557 |
+
|
| 558 |
+
*Effects:* Equivalent to:
|
| 559 |
+
|
| 560 |
+
``` cpp
|
| 561 |
+
return INVOKE<R>(static_cast<F inv-quals>(f), std::forward<ArgTypes>(args)...);
|
| 562 |
+
```
|
| 563 |
+
|
| 564 |
+
where `f` is an lvalue designating the target object of `*this` and `F`
|
| 565 |
+
is the type of `f`.
|
| 566 |
+
|
| 567 |
+
##### Utility <a id="func.wrap.move.util">[[func.wrap.move.util]]</a>
|
| 568 |
+
|
| 569 |
+
``` cpp
|
| 570 |
+
void swap(move_only_function& other) noexcept;
|
| 571 |
+
```
|
| 572 |
+
|
| 573 |
+
*Effects:* Exchanges the target objects of `*this` and `other`.
|
| 574 |
+
|
| 575 |
+
``` cpp
|
| 576 |
+
friend void swap(move_only_function& f1, move_only_function& f2) noexcept;
|
| 577 |
+
```
|
| 578 |
+
|
| 579 |
+
*Effects:* Equivalent to `f1.swap(f2)`.
|
| 580 |
+
|
| 581 |
+
``` cpp
|
| 582 |
+
friend bool operator==(const move_only_function& f, nullptr_t) noexcept;
|
| 583 |
+
```
|
| 584 |
+
|
| 585 |
+
*Returns:* `true` if `f` has no target object, otherwise `false`.
|
| 586 |
+
|