- tmp/tmp9tvgs9l2/{from.md → to.md} +730 -31
tmp/tmp9tvgs9l2/{from.md → to.md}
RENAMED
|
@@ -100,16 +100,21 @@ namespace std {
|
|
| 100 |
// [func.identity], identity
|
| 101 |
struct identity; // freestanding
|
| 102 |
|
| 103 |
// [func.not.fn], function template not_fn
|
| 104 |
template<class F> constexpr unspecified not_fn(F&& f); // freestanding
|
|
|
|
| 105 |
|
| 106 |
// [func.bind.partial], function templates bind_front and bind_back
|
| 107 |
template<class F, class... Args>
|
| 108 |
constexpr unspecified bind_front(F&&, Args&&...); // freestanding
|
|
|
|
|
|
|
| 109 |
template<class F, class... Args>
|
| 110 |
constexpr unspecified bind_back(F&&, Args&&...); // freestanding
|
|
|
|
|
|
|
| 111 |
|
| 112 |
// [func.bind], bind
|
| 113 |
template<class T> struct is_bind_expression; // freestanding
|
| 114 |
template<class T>
|
| 115 |
constexpr bool is_bind_expression_v = // freestanding
|
|
@@ -126,39 +131,49 @@ namespace std {
|
|
| 126 |
|
| 127 |
namespace placeholders {
|
| 128 |
// M is the implementation-defined number of placeholders
|
| 129 |
see belownc _1; // freestanding
|
| 130 |
see belownc _2; // freestanding
|
| 131 |
-
|
| 132 |
-
.
|
| 133 |
-
.
|
| 134 |
see belownc _M; // freestanding
|
| 135 |
}
|
| 136 |
|
| 137 |
// [func.memfn], member function adaptors
|
| 138 |
template<class R, class T>
|
| 139 |
constexpr unspecified mem_fn(R T::*) noexcept; // freestanding
|
| 140 |
|
| 141 |
// [func.wrap], polymorphic function wrappers
|
|
|
|
| 142 |
class bad_function_call;
|
| 143 |
|
|
|
|
| 144 |
template<class> class function; // not defined
|
| 145 |
template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
|
| 146 |
|
| 147 |
-
// [func.wrap.func.alg], specialized algorithms
|
| 148 |
template<class R, class... ArgTypes>
|
| 149 |
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
|
| 150 |
|
| 151 |
-
// [func.wrap.func.nullptr], null pointer comparison operator functions
|
| 152 |
template<class R, class... ArgTypes>
|
| 153 |
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 154 |
|
| 155 |
-
// [func.wrap.move], move
|
| 156 |
template<class... S> class move_only_function; // not defined
|
| 157 |
template<class R, class... ArgTypes>
|
| 158 |
class move_only_function<R(ArgTypes...) cv ref noexcept(noex)>; // see below
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
// [func.search], searchers
|
| 161 |
template<class ForwardIterator1, class BinaryPredicate = equal_to<>>
|
| 162 |
class default_searcher; // freestanding
|
| 163 |
|
| 164 |
template<class RandomAccessIterator,
|
|
@@ -182,10 +197,29 @@ namespace std {
|
|
| 182 |
struct greater; // freestanding
|
| 183 |
struct less; // freestanding
|
| 184 |
struct greater_equal; // freestanding
|
| 185 |
struct less_equal; // freestanding
|
| 186 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
}
|
| 188 |
```
|
| 189 |
|
| 190 |
[*Example 1*:
|
| 191 |
|
|
@@ -237,19 +271,19 @@ collectively referred to as *state entities*.
|
|
| 237 |
### Requirements <a id="func.require">[[func.require]]</a>
|
| 238 |
|
| 239 |
Define `INVOKE(f, t₁, t₂, …, t_N)` as follows:
|
| 240 |
|
| 241 |
- `(t₁.*f)(t₂, …, t_N)` when `f` is a pointer to a member function of a
|
| 242 |
-
class `T` and `is_same_v<T, remove_cvref_t<decltype(
|
| 243 |
`is_base_of_v<T, remove_cvref_t<decltype(t₁)>>` is `true`;
|
| 244 |
- `(t₁.get().*f)(t₂, …, t_N)` when `f` is a pointer to a member function
|
| 245 |
of a class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization
|
| 246 |
of `reference_wrapper`;
|
| 247 |
- `((*t₁).*f)(t₂, …, t_N)` when `f` is a pointer to a member function of
|
| 248 |
a class `T` and `t₁` does not satisfy the previous two items;
|
| 249 |
- `t₁.*f` when N = 1 and `f` is a pointer to data member of a class `T`
|
| 250 |
-
and `is_same_v<T, remove_cvref_t<decltype(
|
| 251 |
`is_base_of_v<T, remove_cvref_t<decltype(t₁)>>` is `true`;
|
| 252 |
- `t₁.get().*f` when N = 1 and `f` is a pointer to data member of a
|
| 253 |
class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization of
|
| 254 |
`reference_wrapper`;
|
| 255 |
- `(*t₁).*f` when N = 1 and `f` is a pointer to data member of a class
|
|
@@ -363,10 +397,19 @@ namespace std {
|
|
| 363 |
|
| 364 |
// [refwrap.invoke], invocation
|
| 365 |
template<class... ArgTypes>
|
| 366 |
constexpr invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&...) const
|
| 367 |
noexcept(is_nothrow_invocable_v<T&, ArgTypes...>);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
};
|
| 369 |
|
| 370 |
template<class T>
|
| 371 |
reference_wrapper(T&) -> reference_wrapper<T>;
|
| 372 |
}
|
|
@@ -380,10 +423,15 @@ function of type `T`.
|
|
| 380 |
[[term.trivially.copyable.type]].
|
| 381 |
|
| 382 |
The template parameter `T` of `reference_wrapper` may be an incomplete
|
| 383 |
type.
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
#### Constructors <a id="refwrap.const">[[refwrap.const]]</a>
|
| 386 |
|
| 387 |
``` cpp
|
| 388 |
template<class U>
|
| 389 |
constexpr reference_wrapper(U&& u) noexcept(see below);
|
|
@@ -444,11 +492,68 @@ template<class... ArgTypes>
|
|
| 444 |
```
|
| 445 |
|
| 446 |
*Mandates:* `T` is a complete type.
|
| 447 |
|
| 448 |
*Returns:* *INVOKE*(get(),
|
| 449 |
-
std::forward\<ArgTypes\>(args)...)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
|
| 451 |
#### Helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
|
| 452 |
|
| 453 |
The template parameter `T` of the following `ref` and `cref` function
|
| 454 |
templates may be an incomplete type.
|
|
@@ -1361,10 +1466,28 @@ is `true`.
|
|
| 1361 |
wrapper [[term.perfect.forwarding.call.wrapper]] `g` with call pattern
|
| 1362 |
`!invoke(fd, call_args...)`.
|
| 1363 |
|
| 1364 |
*Throws:* Any exception thrown by the initialization of `fd`.
|
| 1365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1366 |
### Function templates `bind_front` and `bind_back` <a id="func.bind.partial">[[func.bind.partial]]</a>
|
| 1367 |
|
| 1368 |
``` cpp
|
| 1369 |
template<class F, class... Args>
|
| 1370 |
constexpr unspecified bind_front(F&& f, Args&&... args);
|
|
@@ -1410,10 +1533,48 @@ wrapper [[term.perfect.forwarding.call.wrapper]] `g` with call pattern:
|
|
| 1410 |
invocation.
|
| 1411 |
|
| 1412 |
*Throws:* Any exception thrown by the initialization of the state
|
| 1413 |
entities of `g` [[func.def]].
|
| 1414 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1415 |
### Function object binders <a id="func.bind">[[func.bind]]</a>
|
| 1416 |
|
| 1417 |
#### General <a id="func.bind.general">[[func.bind.general]]</a>
|
| 1418 |
|
| 1419 |
Subclause [[func.bind]] describes a uniform mechanism for binding
|
|
@@ -1548,13 +1709,11 @@ type `V`_`fd` is `cv FD&`.
|
|
| 1548 |
``` cpp
|
| 1549 |
namespace std::placeholders {
|
| 1550 |
// M is the number of placeholders
|
| 1551 |
see below _1;
|
| 1552 |
see below _2;
|
| 1553 |
-
|
| 1554 |
-
.
|
| 1555 |
-
.
|
| 1556 |
see below _M;
|
| 1557 |
}
|
| 1558 |
```
|
| 1559 |
|
| 1560 |
The number `M` of placeholders is *implementation-defined*.
|
|
@@ -1598,10 +1757,31 @@ expression [[expr.call]] of `fn`.
|
|
| 1598 |
#### General <a id="func.wrap.general">[[func.wrap.general]]</a>
|
| 1599 |
|
| 1600 |
Subclause [[func.wrap]] describes polymorphic wrapper classes that
|
| 1601 |
encapsulate arbitrary callable objects.
|
| 1602 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1603 |
#### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
|
| 1604 |
|
| 1605 |
An exception of type `bad_function_call` is thrown by
|
| 1606 |
`function::operator()` [[func.wrap.func.inv]] when the function wrapper
|
| 1607 |
object has no target.
|
|
@@ -1626,12 +1806,10 @@ const char* what() const noexcept override;
|
|
| 1626 |
|
| 1627 |
##### General <a id="func.wrap.func.general">[[func.wrap.func.general]]</a>
|
| 1628 |
|
| 1629 |
``` cpp
|
| 1630 |
namespace std {
|
| 1631 |
-
template<class> class function; // not defined
|
| 1632 |
-
|
| 1633 |
template<class R, class... ArgTypes>
|
| 1634 |
class function<R(ArgTypes...)> {
|
| 1635 |
public:
|
| 1636 |
using result_type = R;
|
| 1637 |
|
|
@@ -1675,16 +1853,10 @@ namespace std {
|
|
| 1675 |
The `function` class template provides polymorphic wrappers that
|
| 1676 |
generalize the notion of a function pointer. Wrappers can store, copy,
|
| 1677 |
and call arbitrary callable objects [[func.def]], given a call signature
|
| 1678 |
[[func.def]].
|
| 1679 |
|
| 1680 |
-
A callable type [[func.def]] `F` is *Lvalue-Callable* for argument types
|
| 1681 |
-
`ArgTypes` and return type `R` if the expression
|
| 1682 |
-
`INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
|
| 1683 |
-
unevaluated operand [[term.unevaluated.operand]], is well-formed
|
| 1684 |
-
[[func.require]].
|
| 1685 |
-
|
| 1686 |
The `function` class template is a call wrapper [[func.def]] whose call
|
| 1687 |
signature [[func.def]] is `R(ArgTypes...)`.
|
| 1688 |
|
| 1689 |
[*Note 1*: The types deduced by the deduction guides for `function`
|
| 1690 |
might change in future revisions of C++. — *end note*]
|
|
@@ -1706,11 +1878,11 @@ function(nullptr_t) noexcept;
|
|
| 1706 |
``` cpp
|
| 1707 |
function(const function& f);
|
| 1708 |
```
|
| 1709 |
|
| 1710 |
*Ensures:* `!*this` if `!f`; otherwise, the target object of `*this` is
|
| 1711 |
-
a copy of `f
|
| 1712 |
|
| 1713 |
*Throws:* Nothing if `f`’s target is a specialization of
|
| 1714 |
`reference_wrapper` or a function pointer. Otherwise, may throw
|
| 1715 |
`bad_alloc` or any exception thrown by the copy constructor of the
|
| 1716 |
stored callable object.
|
|
@@ -1740,12 +1912,11 @@ template<class F> function(F&& f);
|
|
| 1740 |
Let `FD` be `decay_t<F>`.
|
| 1741 |
|
| 1742 |
*Constraints:*
|
| 1743 |
|
| 1744 |
- `is_same_v<remove_cvref_t<F>, function>` is `false`, and
|
| 1745 |
-
- `FD
|
| 1746 |
-
`ArgTypes...` and return type `R`.
|
| 1747 |
|
| 1748 |
*Mandates:*
|
| 1749 |
|
| 1750 |
- `is_copy_constructible_v<FD>` is `true`, and
|
| 1751 |
- `is_constructible_v<FD, F>` is `true`.
|
|
@@ -1826,12 +1997,12 @@ function& operator=(nullptr_t) noexcept;
|
|
| 1826 |
|
| 1827 |
``` cpp
|
| 1828 |
template<class F> function& operator=(F&& f);
|
| 1829 |
```
|
| 1830 |
|
| 1831 |
-
*Constraints:* `decay_t<F>
|
| 1832 |
-
|
| 1833 |
|
| 1834 |
*Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
|
| 1835 |
|
| 1836 |
*Returns:* `*this`.
|
| 1837 |
|
|
@@ -1911,11 +2082,11 @@ template<class R, class... ArgTypes>
|
|
| 1911 |
void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
|
| 1912 |
```
|
| 1913 |
|
| 1914 |
*Effects:* As if by: `f1.swap(f2);`
|
| 1915 |
|
| 1916 |
-
#### Move
|
| 1917 |
|
| 1918 |
##### General <a id="func.wrap.move.general">[[func.wrap.move.general]]</a>
|
| 1919 |
|
| 1920 |
The header provides partial specializations of `move_only_function` for
|
| 1921 |
each combination of the possible replacements of the placeholders cv,
|
|
@@ -1933,18 +2104,16 @@ above, there is a placeholder *inv-quals* defined as follows:
|
|
| 1933 |
|
| 1934 |
##### Class template `move_only_function` <a id="func.wrap.move.class">[[func.wrap.move.class]]</a>
|
| 1935 |
|
| 1936 |
``` cpp
|
| 1937 |
namespace std {
|
| 1938 |
-
template<class... S> class move_only_function; // not defined
|
| 1939 |
-
|
| 1940 |
template<class R, class... ArgTypes>
|
| 1941 |
class move_only_function<R(ArgTypes...) cv ref noexcept(noex)> {
|
| 1942 |
public:
|
| 1943 |
using result_type = R;
|
| 1944 |
|
| 1945 |
-
// [func.wrap.move.ctor], constructors,
|
| 1946 |
move_only_function() noexcept;
|
| 1947 |
move_only_function(nullptr_t) noexcept;
|
| 1948 |
move_only_function(move_only_function&&) noexcept;
|
| 1949 |
template<class F> move_only_function(F&&);
|
| 1950 |
template<class T, class... Args>
|
|
@@ -1984,11 +2153,11 @@ dynamically allocated memory for a small contained value.
|
|
| 1984 |
|
| 1985 |
[*Note 1*: Such small-object optimization can only be applied to a type
|
| 1986 |
`T` for which `is_nothrow_move_constructible_v<T>` is
|
| 1987 |
`true`. — *end note*]
|
| 1988 |
|
| 1989 |
-
##### Constructors,
|
| 1990 |
|
| 1991 |
``` cpp
|
| 1992 |
template<class VT>
|
| 1993 |
static constexpr bool is-callable-from = see below;
|
| 1994 |
```
|
|
@@ -2177,10 +2346,540 @@ friend void swap(move_only_function& f1, move_only_function& f2) noexcept;
|
|
| 2177 |
friend bool operator==(const move_only_function& f, nullptr_t) noexcept;
|
| 2178 |
```
|
| 2179 |
|
| 2180 |
*Returns:* `true` if `f` has no target object, otherwise `false`.
|
| 2181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2182 |
### Searchers <a id="func.search">[[func.search]]</a>
|
| 2183 |
|
| 2184 |
#### General <a id="func.search.general">[[func.search.general]]</a>
|
| 2185 |
|
| 2186 |
Subclause [[func.search]] provides function object types
|
|
@@ -2292,11 +2991,11 @@ boyer_moore_searcher(RandomAccessIterator1 pat_first,
|
|
| 2292 |
Hash hf = Hash(),
|
| 2293 |
BinaryPredicate pred = BinaryPredicate());
|
| 2294 |
```
|
| 2295 |
|
| 2296 |
*Preconditions:* The value type of `RandomAccessIterator1` meets the
|
| 2297 |
-
*Cpp17DefaultConstructible*,
|
| 2298 |
*Cpp17CopyAssignable* requirements.
|
| 2299 |
|
| 2300 |
Let `V` be `iterator_traits<RandomAccessIterator1>::value_type`. For any
|
| 2301 |
two values `A` and `B` of type `V`, if `pred(A, B) == true`, then
|
| 2302 |
`hf(A) == hf(B)` is `true`.
|
|
|
|
| 100 |
// [func.identity], identity
|
| 101 |
struct identity; // freestanding
|
| 102 |
|
| 103 |
// [func.not.fn], function template not_fn
|
| 104 |
template<class F> constexpr unspecified not_fn(F&& f); // freestanding
|
| 105 |
+
template<auto f> constexpr unspecified not_fn() noexcept; // freestanding
|
| 106 |
|
| 107 |
// [func.bind.partial], function templates bind_front and bind_back
|
| 108 |
template<class F, class... Args>
|
| 109 |
constexpr unspecified bind_front(F&&, Args&&...); // freestanding
|
| 110 |
+
template<auto f, class... Args>
|
| 111 |
+
constexpr unspecified bind_front(Args&&...); // freestanding
|
| 112 |
template<class F, class... Args>
|
| 113 |
constexpr unspecified bind_back(F&&, Args&&...); // freestanding
|
| 114 |
+
template<auto f, class... Args>
|
| 115 |
+
constexpr unspecified bind_back(Args&&...); // freestanding
|
| 116 |
|
| 117 |
// [func.bind], bind
|
| 118 |
template<class T> struct is_bind_expression; // freestanding
|
| 119 |
template<class T>
|
| 120 |
constexpr bool is_bind_expression_v = // freestanding
|
|
|
|
| 131 |
|
| 132 |
namespace placeholders {
|
| 133 |
// M is the implementation-defined number of placeholders
|
| 134 |
see belownc _1; // freestanding
|
| 135 |
see belownc _2; // freestanding
|
| 136 |
+
⋮
|
|
|
|
|
|
|
| 137 |
see belownc _M; // freestanding
|
| 138 |
}
|
| 139 |
|
| 140 |
// [func.memfn], member function adaptors
|
| 141 |
template<class R, class T>
|
| 142 |
constexpr unspecified mem_fn(R T::*) noexcept; // freestanding
|
| 143 |
|
| 144 |
// [func.wrap], polymorphic function wrappers
|
| 145 |
+
// [func.wrap.badcall], class bad_function_call
|
| 146 |
class bad_function_call;
|
| 147 |
|
| 148 |
+
// [func.wrap.func], class template function
|
| 149 |
template<class> class function; // not defined
|
| 150 |
template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
|
| 151 |
|
| 152 |
+
// [func.wrap.func.alg], function specialized algorithms
|
| 153 |
template<class R, class... ArgTypes>
|
| 154 |
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
|
| 155 |
|
| 156 |
+
// [func.wrap.func.nullptr], function null pointer comparison operator functions
|
| 157 |
template<class R, class... ArgTypes>
|
| 158 |
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
|
| 159 |
|
| 160 |
+
// [func.wrap.move], move-only wrapper
|
| 161 |
template<class... S> class move_only_function; // not defined
|
| 162 |
template<class R, class... ArgTypes>
|
| 163 |
class move_only_function<R(ArgTypes...) cv ref noexcept(noex)>; // see below
|
| 164 |
|
| 165 |
+
// [func.wrap.copy], copyable wrapper
|
| 166 |
+
template<class... S> class copyable_function; // not defined
|
| 167 |
+
template<class R, class... ArgTypes>
|
| 168 |
+
class copyable_function<R(ArgTypes...) cv ref noexcept(noex)>; // see below
|
| 169 |
+
|
| 170 |
+
// [func.wrap.ref], non-owning wrapper
|
| 171 |
+
template<class... S> class function_ref; // freestanding, not defined
|
| 172 |
+
template<class R, class... ArgTypes>
|
| 173 |
+
class function_ref<R(ArgTypes...) cv noexcept(noex)>; // freestanding, see below
|
| 174 |
+
|
| 175 |
// [func.search], searchers
|
| 176 |
template<class ForwardIterator1, class BinaryPredicate = equal_to<>>
|
| 177 |
class default_searcher; // freestanding
|
| 178 |
|
| 179 |
template<class RandomAccessIterator,
|
|
|
|
| 197 |
struct greater; // freestanding
|
| 198 |
struct less; // freestanding
|
| 199 |
struct greater_equal; // freestanding
|
| 200 |
struct less_equal; // freestanding
|
| 201 |
}
|
| 202 |
+
|
| 203 |
+
template<class Fn, class... Args>
|
| 204 |
+
concept callable = // exposition only
|
| 205 |
+
requires (Fn&& fn, Args&&... args) {
|
| 206 |
+
std::forward<Fn>(fn)(std::forward<Args>(args)...);
|
| 207 |
+
};
|
| 208 |
+
|
| 209 |
+
template<class Fn, class... Args>
|
| 210 |
+
concept nothrow-callable = // exposition only
|
| 211 |
+
callable<Fn, Args...> &&
|
| 212 |
+
requires (Fn&& fn, Args&&... args) {
|
| 213 |
+
{ std::forward<Fn>(fn)(std::forward<Args>(args)...) } noexcept;
|
| 214 |
+
};
|
| 215 |
+
|
| 216 |
+
template<class Fn, class... Args>
|
| 217 |
+
using call-result-t = decltype(declval<Fn>()(declval<Args>()...)); // exposition only
|
| 218 |
+
|
| 219 |
+
template<const auto& T>
|
| 220 |
+
using decayed-typeof = decltype(auto(T)); // exposition only
|
| 221 |
}
|
| 222 |
```
|
| 223 |
|
| 224 |
[*Example 1*:
|
| 225 |
|
|
|
|
| 271 |
### Requirements <a id="func.require">[[func.require]]</a>
|
| 272 |
|
| 273 |
Define `INVOKE(f, t₁, t₂, …, t_N)` as follows:
|
| 274 |
|
| 275 |
- `(t₁.*f)(t₂, …, t_N)` when `f` is a pointer to a member function of a
|
| 276 |
+
class `T` and `is_same_v<T, remove_cvref_t<decltype(t₁)>> ||`
|
| 277 |
`is_base_of_v<T, remove_cvref_t<decltype(t₁)>>` is `true`;
|
| 278 |
- `(t₁.get().*f)(t₂, …, t_N)` when `f` is a pointer to a member function
|
| 279 |
of a class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization
|
| 280 |
of `reference_wrapper`;
|
| 281 |
- `((*t₁).*f)(t₂, …, t_N)` when `f` is a pointer to a member function of
|
| 282 |
a class `T` and `t₁` does not satisfy the previous two items;
|
| 283 |
- `t₁.*f` when N = 1 and `f` is a pointer to data member of a class `T`
|
| 284 |
+
and `is_same_v<T, remove_cvref_t<decltype(t₁)>> ||`
|
| 285 |
`is_base_of_v<T, remove_cvref_t<decltype(t₁)>>` is `true`;
|
| 286 |
- `t₁.get().*f` when N = 1 and `f` is a pointer to data member of a
|
| 287 |
class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization of
|
| 288 |
`reference_wrapper`;
|
| 289 |
- `(*t₁).*f` when N = 1 and `f` is a pointer to data member of a class
|
|
|
|
| 397 |
|
| 398 |
// [refwrap.invoke], invocation
|
| 399 |
template<class... ArgTypes>
|
| 400 |
constexpr invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&...) const
|
| 401 |
noexcept(is_nothrow_invocable_v<T&, ArgTypes...>);
|
| 402 |
+
|
| 403 |
+
// [refwrap.comparisons], comparisons
|
| 404 |
+
friend constexpr bool operator==(reference_wrapper, reference_wrapper);
|
| 405 |
+
friend constexpr bool operator==(reference_wrapper, const T&);
|
| 406 |
+
friend constexpr bool operator==(reference_wrapper, reference_wrapper<const T>);
|
| 407 |
+
|
| 408 |
+
friend constexpr auto operator<=>(reference_wrapper, reference_wrapper);
|
| 409 |
+
friend constexpr auto operator<=>(reference_wrapper, const T&);
|
| 410 |
+
friend constexpr auto operator<=>(reference_wrapper, reference_wrapper<const T>);
|
| 411 |
};
|
| 412 |
|
| 413 |
template<class T>
|
| 414 |
reference_wrapper(T&) -> reference_wrapper<T>;
|
| 415 |
}
|
|
|
|
| 423 |
[[term.trivially.copyable.type]].
|
| 424 |
|
| 425 |
The template parameter `T` of `reference_wrapper` may be an incomplete
|
| 426 |
type.
|
| 427 |
|
| 428 |
+
[*Note 1*: Using the comparison operators described in
|
| 429 |
+
[[refwrap.comparisons]] with `T` being an incomplete type can lead to an
|
| 430 |
+
ill-formed program with no diagnostic required
|
| 431 |
+
[[temp.point]], [[temp.constr.atomic]]. — *end note*]
|
| 432 |
+
|
| 433 |
#### Constructors <a id="refwrap.const">[[refwrap.const]]</a>
|
| 434 |
|
| 435 |
``` cpp
|
| 436 |
template<class U>
|
| 437 |
constexpr reference_wrapper(U&& u) noexcept(see below);
|
|
|
|
| 492 |
```
|
| 493 |
|
| 494 |
*Mandates:* `T` is a complete type.
|
| 495 |
|
| 496 |
*Returns:* *INVOKE*(get(),
|
| 497 |
+
std::forward\<ArgTypes\>(args)...) [[func.require]].
|
| 498 |
+
|
| 499 |
+
#### Comparisons <a id="refwrap.comparisons">[[refwrap.comparisons]]</a>
|
| 500 |
+
|
| 501 |
+
``` cpp
|
| 502 |
+
friend constexpr bool operator==(reference_wrapper x, reference_wrapper y);
|
| 503 |
+
```
|
| 504 |
+
|
| 505 |
+
*Constraints:* The expression `x.get() == y.get()` is well-formed and
|
| 506 |
+
its result is convertible to `bool`.
|
| 507 |
+
|
| 508 |
+
*Returns:* `x.get() == y.get()`.
|
| 509 |
+
|
| 510 |
+
``` cpp
|
| 511 |
+
friend constexpr bool operator==(reference_wrapper x, const T& y);
|
| 512 |
+
```
|
| 513 |
+
|
| 514 |
+
*Constraints:* The expression `x.get() == y` is well-formed and its
|
| 515 |
+
result is convertible to `bool`.
|
| 516 |
+
|
| 517 |
+
*Returns:* `x.get() == y`.
|
| 518 |
+
|
| 519 |
+
``` cpp
|
| 520 |
+
friend constexpr bool operator==(reference_wrapper x, reference_wrapper<const T> y);
|
| 521 |
+
```
|
| 522 |
+
|
| 523 |
+
*Constraints:* `is_const_v<T>` is `false` and the expression
|
| 524 |
+
`x.get() == y.get()` is well-formed and its result is convertible to
|
| 525 |
+
`bool`.
|
| 526 |
+
|
| 527 |
+
*Returns:* `x.get() == y.get()`.
|
| 528 |
+
|
| 529 |
+
``` cpp
|
| 530 |
+
friend constexpr auto operator<=>(reference_wrapper x, reference_wrapper y);
|
| 531 |
+
```
|
| 532 |
+
|
| 533 |
+
*Constraints:* The expression *`synth-three-way`*`(x.get(), y.get())` is
|
| 534 |
+
well-formed.
|
| 535 |
+
|
| 536 |
+
*Returns:* *`synth-three-way`*`(x.get(), y.get())`.
|
| 537 |
+
|
| 538 |
+
``` cpp
|
| 539 |
+
friend constexpr auto operator<=>(reference_wrapper x, const T& y);
|
| 540 |
+
```
|
| 541 |
+
|
| 542 |
+
*Constraints:* The expression *`synth-three-way`*`(x.get(), y)` is
|
| 543 |
+
well-formed.
|
| 544 |
+
|
| 545 |
+
*Returns:* *`synth-three-way`*`(x.get(), y)`.
|
| 546 |
+
|
| 547 |
+
``` cpp
|
| 548 |
+
friend constexpr auto operator<=>(reference_wrapper x, reference_wrapper<const T> y);
|
| 549 |
+
```
|
| 550 |
+
|
| 551 |
+
*Constraints:* `is_const_v<T>` is `false`. The expression
|
| 552 |
+
*`synth-three-way`*`(x.get(), y.get())` is well-formed.
|
| 553 |
+
|
| 554 |
+
*Returns:* *`synth-three-way`*`(x.get(), y.get())`.
|
| 555 |
|
| 556 |
#### Helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
|
| 557 |
|
| 558 |
The template parameter `T` of the following `ref` and `cref` function
|
| 559 |
templates may be an incomplete type.
|
|
|
|
| 1466 |
wrapper [[term.perfect.forwarding.call.wrapper]] `g` with call pattern
|
| 1467 |
`!invoke(fd, call_args...)`.
|
| 1468 |
|
| 1469 |
*Throws:* Any exception thrown by the initialization of `fd`.
|
| 1470 |
|
| 1471 |
+
``` cpp
|
| 1472 |
+
template<auto f> constexpr unspecified not_fn() noexcept;
|
| 1473 |
+
```
|
| 1474 |
+
|
| 1475 |
+
In the text that follows:
|
| 1476 |
+
|
| 1477 |
+
- `F` is the type of `f`,
|
| 1478 |
+
- `g` is a value of the result of a `not_fn` invocation,
|
| 1479 |
+
- `call_args` is an argument pack used in a function call
|
| 1480 |
+
expression [[expr.call]] of `g`.
|
| 1481 |
+
|
| 1482 |
+
*Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
|
| 1483 |
+
then `f != nullptr` is `true`.
|
| 1484 |
+
|
| 1485 |
+
*Returns:* A perfect forwarding call wrapper [[func.require]] `g` that
|
| 1486 |
+
does not have state entities, and has the call pattern
|
| 1487 |
+
`!invoke(f, call_args...)`.
|
| 1488 |
+
|
| 1489 |
### Function templates `bind_front` and `bind_back` <a id="func.bind.partial">[[func.bind.partial]]</a>
|
| 1490 |
|
| 1491 |
``` cpp
|
| 1492 |
template<class F, class... Args>
|
| 1493 |
constexpr unspecified bind_front(F&& f, Args&&... args);
|
|
|
|
| 1533 |
invocation.
|
| 1534 |
|
| 1535 |
*Throws:* Any exception thrown by the initialization of the state
|
| 1536 |
entities of `g` [[func.def]].
|
| 1537 |
|
| 1538 |
+
``` cpp
|
| 1539 |
+
template<auto f, class... Args>
|
| 1540 |
+
constexpr unspecified bind_front(Args&&... args);
|
| 1541 |
+
template<auto f, class... Args>
|
| 1542 |
+
constexpr unspecified bind_back(Args&&... args);
|
| 1543 |
+
```
|
| 1544 |
+
|
| 1545 |
+
Within this subclause:
|
| 1546 |
+
|
| 1547 |
+
- `F` is the type of `f`,
|
| 1548 |
+
- `g` is a value of the result of a `bind_front` or `bind_back`
|
| 1549 |
+
invocation,
|
| 1550 |
+
- `BoundArgs` is a pack that denotes `decay_t<Args>...`,
|
| 1551 |
+
- `bound_args` is a pack of bound argument entities of `g` [[func.def]]
|
| 1552 |
+
of types `BoundArgs...`, direct-non-list-initialized with
|
| 1553 |
+
`std::forward<Args>(args)...`, respectively, and
|
| 1554 |
+
- `call_args` is an argument pack used in a function call
|
| 1555 |
+
expression [[expr.call]] of `g`.
|
| 1556 |
+
|
| 1557 |
+
*Mandates:*
|
| 1558 |
+
|
| 1559 |
+
- `(is_constructible_v<BoundArgs, Args> && ...)` is `true`, and
|
| 1560 |
+
- `(is_move_constructible_v<BoundArgs> && ...)` is `true`, and
|
| 1561 |
+
- if `is_pointer_v<F> || is_member_pointer_v<F>` is `true`, then
|
| 1562 |
+
`f != nullptr` is `true`.
|
| 1563 |
+
|
| 1564 |
+
*Preconditions:* For each `Tᵢ` in `BoundArgs`, `Tᵢ` meets the
|
| 1565 |
+
*Cpp17MoveConstructible* requirements.
|
| 1566 |
+
|
| 1567 |
+
*Returns:* A perfect forwarding call wrapper [[func.require]] `g` that
|
| 1568 |
+
does not have a target object, and has the call pattern:
|
| 1569 |
+
|
| 1570 |
+
- `invoke(f, bound_args..., call_args...)` for a `bind_front`
|
| 1571 |
+
invocation, or
|
| 1572 |
+
- `invoke(f, call_args..., bound_args...)` for a `bind_back` invocation.
|
| 1573 |
+
|
| 1574 |
+
*Throws:* Any exception thrown by the initialization of `bound_args`.
|
| 1575 |
+
|
| 1576 |
### Function object binders <a id="func.bind">[[func.bind]]</a>
|
| 1577 |
|
| 1578 |
#### General <a id="func.bind.general">[[func.bind.general]]</a>
|
| 1579 |
|
| 1580 |
Subclause [[func.bind]] describes a uniform mechanism for binding
|
|
|
|
| 1709 |
``` cpp
|
| 1710 |
namespace std::placeholders {
|
| 1711 |
// M is the number of placeholders
|
| 1712 |
see below _1;
|
| 1713 |
see below _2;
|
| 1714 |
+
⋮
|
|
|
|
|
|
|
| 1715 |
see below _M;
|
| 1716 |
}
|
| 1717 |
```
|
| 1718 |
|
| 1719 |
The number `M` of placeholders is *implementation-defined*.
|
|
|
|
| 1757 |
#### General <a id="func.wrap.general">[[func.wrap.general]]</a>
|
| 1758 |
|
| 1759 |
Subclause [[func.wrap]] describes polymorphic wrapper classes that
|
| 1760 |
encapsulate arbitrary callable objects.
|
| 1761 |
|
| 1762 |
+
Let `t` be an object of a type that is a specialization of `function`,
|
| 1763 |
+
`copyable_function`, or `move_only_function`, such that the target
|
| 1764 |
+
object `x` of `t` has a type that is a specialization of `function`,
|
| 1765 |
+
`copyable_function`, or `move_only_function`. Each argument of the
|
| 1766 |
+
invocation of `x` evaluated as part of the invocation of `t` may alias
|
| 1767 |
+
an argument in the same position in the invocation of `t` that has the
|
| 1768 |
+
same type, even if the corresponding parameter is not of reference type.
|
| 1769 |
+
|
| 1770 |
+
[*Example 1*:
|
| 1771 |
+
|
| 1772 |
+
``` cpp
|
| 1773 |
+
move_only_function<void(T)> f{copyable_function<void(T)>{[](T) {}}};
|
| 1774 |
+
T t;
|
| 1775 |
+
f(t); // it is unspecified how many copies of T are made
|
| 1776 |
+
```
|
| 1777 |
+
|
| 1778 |
+
— *end example*]
|
| 1779 |
+
|
| 1780 |
+
*Recommended practice:* Implementations should avoid double wrapping
|
| 1781 |
+
when constructing polymorphic wrappers from one another.
|
| 1782 |
+
|
| 1783 |
#### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
|
| 1784 |
|
| 1785 |
An exception of type `bad_function_call` is thrown by
|
| 1786 |
`function::operator()` [[func.wrap.func.inv]] when the function wrapper
|
| 1787 |
object has no target.
|
|
|
|
| 1806 |
|
| 1807 |
##### General <a id="func.wrap.func.general">[[func.wrap.func.general]]</a>
|
| 1808 |
|
| 1809 |
``` cpp
|
| 1810 |
namespace std {
|
|
|
|
|
|
|
| 1811 |
template<class R, class... ArgTypes>
|
| 1812 |
class function<R(ArgTypes...)> {
|
| 1813 |
public:
|
| 1814 |
using result_type = R;
|
| 1815 |
|
|
|
|
| 1853 |
The `function` class template provides polymorphic wrappers that
|
| 1854 |
generalize the notion of a function pointer. Wrappers can store, copy,
|
| 1855 |
and call arbitrary callable objects [[func.def]], given a call signature
|
| 1856 |
[[func.def]].
|
| 1857 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1858 |
The `function` class template is a call wrapper [[func.def]] whose call
|
| 1859 |
signature [[func.def]] is `R(ArgTypes...)`.
|
| 1860 |
|
| 1861 |
[*Note 1*: The types deduced by the deduction guides for `function`
|
| 1862 |
might change in future revisions of C++. — *end note*]
|
|
|
|
| 1878 |
``` cpp
|
| 1879 |
function(const function& f);
|
| 1880 |
```
|
| 1881 |
|
| 1882 |
*Ensures:* `!*this` if `!f`; otherwise, the target object of `*this` is
|
| 1883 |
+
a copy of the target object of `f`.
|
| 1884 |
|
| 1885 |
*Throws:* Nothing if `f`’s target is a specialization of
|
| 1886 |
`reference_wrapper` or a function pointer. Otherwise, may throw
|
| 1887 |
`bad_alloc` or any exception thrown by the copy constructor of the
|
| 1888 |
stored callable object.
|
|
|
|
| 1912 |
Let `FD` be `decay_t<F>`.
|
| 1913 |
|
| 1914 |
*Constraints:*
|
| 1915 |
|
| 1916 |
- `is_same_v<remove_cvref_t<F>, function>` is `false`, and
|
| 1917 |
+
- `is_invocable_r_v<R, FD&, ArgTypes...>` is `true`.
|
|
|
|
| 1918 |
|
| 1919 |
*Mandates:*
|
| 1920 |
|
| 1921 |
- `is_copy_constructible_v<FD>` is `true`, and
|
| 1922 |
- `is_constructible_v<FD, F>` is `true`.
|
|
|
|
| 1997 |
|
| 1998 |
``` cpp
|
| 1999 |
template<class F> function& operator=(F&& f);
|
| 2000 |
```
|
| 2001 |
|
| 2002 |
+
*Constraints:* `is_invocable_r_v<R, decay_t<F>&, ArgTypes...>` is
|
| 2003 |
+
`true`.
|
| 2004 |
|
| 2005 |
*Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
|
| 2006 |
|
| 2007 |
*Returns:* `*this`.
|
| 2008 |
|
|
|
|
| 2082 |
void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
|
| 2083 |
```
|
| 2084 |
|
| 2085 |
*Effects:* As if by: `f1.swap(f2);`
|
| 2086 |
|
| 2087 |
+
#### Move-only wrapper <a id="func.wrap.move">[[func.wrap.move]]</a>
|
| 2088 |
|
| 2089 |
##### General <a id="func.wrap.move.general">[[func.wrap.move.general]]</a>
|
| 2090 |
|
| 2091 |
The header provides partial specializations of `move_only_function` for
|
| 2092 |
each combination of the possible replacements of the placeholders cv,
|
|
|
|
| 2104 |
|
| 2105 |
##### Class template `move_only_function` <a id="func.wrap.move.class">[[func.wrap.move.class]]</a>
|
| 2106 |
|
| 2107 |
``` cpp
|
| 2108 |
namespace std {
|
|
|
|
|
|
|
| 2109 |
template<class R, class... ArgTypes>
|
| 2110 |
class move_only_function<R(ArgTypes...) cv ref noexcept(noex)> {
|
| 2111 |
public:
|
| 2112 |
using result_type = R;
|
| 2113 |
|
| 2114 |
+
// [func.wrap.move.ctor], constructors, assignments, and destructor
|
| 2115 |
move_only_function() noexcept;
|
| 2116 |
move_only_function(nullptr_t) noexcept;
|
| 2117 |
move_only_function(move_only_function&&) noexcept;
|
| 2118 |
template<class F> move_only_function(F&&);
|
| 2119 |
template<class T, class... Args>
|
|
|
|
| 2153 |
|
| 2154 |
[*Note 1*: Such small-object optimization can only be applied to a type
|
| 2155 |
`T` for which `is_nothrow_move_constructible_v<T>` is
|
| 2156 |
`true`. — *end note*]
|
| 2157 |
|
| 2158 |
+
##### Constructors, assignments, and destructor <a id="func.wrap.move.ctor">[[func.wrap.move.ctor]]</a>
|
| 2159 |
|
| 2160 |
``` cpp
|
| 2161 |
template<class VT>
|
| 2162 |
static constexpr bool is-callable-from = see below;
|
| 2163 |
```
|
|
|
|
| 2346 |
friend bool operator==(const move_only_function& f, nullptr_t) noexcept;
|
| 2347 |
```
|
| 2348 |
|
| 2349 |
*Returns:* `true` if `f` has no target object, otherwise `false`.
|
| 2350 |
|
| 2351 |
+
#### Copyable wrapper <a id="func.wrap.copy">[[func.wrap.copy]]</a>
|
| 2352 |
+
|
| 2353 |
+
##### General <a id="func.wrap.copy.general">[[func.wrap.copy.general]]</a>
|
| 2354 |
+
|
| 2355 |
+
The header provides partial specializations of `copyable_function` for
|
| 2356 |
+
each combination of the possible replacements of the placeholders cv,
|
| 2357 |
+
*ref*, and *noex* where
|
| 2358 |
+
|
| 2359 |
+
- cv is either const or empty,
|
| 2360 |
+
- *ref* is either `&`, `&&`, or empty, and
|
| 2361 |
+
- *noex* is either `true` or `false`.
|
| 2362 |
+
|
| 2363 |
+
For each of the possible combinations of the placeholders mentioned
|
| 2364 |
+
above, there is a placeholder *inv-quals* defined as follows:
|
| 2365 |
+
|
| 2366 |
+
- If *ref* is empty, let *inv-quals* be cv`&`,
|
| 2367 |
+
- otherwise, let *inv-quals* be cv *ref*.
|
| 2368 |
+
|
| 2369 |
+
##### Class template `copyable_function` <a id="func.wrap.copy.class">[[func.wrap.copy.class]]</a>
|
| 2370 |
+
|
| 2371 |
+
``` cpp
|
| 2372 |
+
namespace std {
|
| 2373 |
+
template<class R, class... ArgTypes>
|
| 2374 |
+
class copyable_function<R(ArgTypes...) cv ref noexcept(noex)> {
|
| 2375 |
+
public:
|
| 2376 |
+
using result_type = R;
|
| 2377 |
+
|
| 2378 |
+
// [func.wrap.copy.ctor], constructors, assignments, and destructor
|
| 2379 |
+
copyable_function() noexcept;
|
| 2380 |
+
copyable_function(nullptr_t) noexcept;
|
| 2381 |
+
copyable_function(const copyable_function&);
|
| 2382 |
+
copyable_function(copyable_function&&) noexcept;
|
| 2383 |
+
template<class F> copyable_function(F&&);
|
| 2384 |
+
template<class T, class... Args>
|
| 2385 |
+
explicit copyable_function(in_place_type_t<T>, Args&&...);
|
| 2386 |
+
template<class T, class U, class... Args>
|
| 2387 |
+
explicit copyable_function(in_place_type_t<T>, initializer_list<U>, Args&&...);
|
| 2388 |
+
|
| 2389 |
+
copyable_function& operator=(const copyable_function&);
|
| 2390 |
+
copyable_function& operator=(copyable_function&&);
|
| 2391 |
+
copyable_function& operator=(nullptr_t) noexcept;
|
| 2392 |
+
template<class F> copyable_function& operator=(F&&);
|
| 2393 |
+
|
| 2394 |
+
~copyable_function();
|
| 2395 |
+
|
| 2396 |
+
// [func.wrap.copy.inv], invocation
|
| 2397 |
+
explicit operator bool() const noexcept;
|
| 2398 |
+
R operator()(ArgTypes...) cv ref noexcept(noex);
|
| 2399 |
+
|
| 2400 |
+
// [func.wrap.copy.util], utility
|
| 2401 |
+
void swap(copyable_function&) noexcept;
|
| 2402 |
+
friend void swap(copyable_function&, copyable_function&) noexcept;
|
| 2403 |
+
friend bool operator==(const copyable_function&, nullptr_t) noexcept;
|
| 2404 |
+
|
| 2405 |
+
private:
|
| 2406 |
+
template<class VT>
|
| 2407 |
+
static constexpr bool is-callable-from = see below; // exposition only
|
| 2408 |
+
};
|
| 2409 |
+
}
|
| 2410 |
+
```
|
| 2411 |
+
|
| 2412 |
+
The `copyable_function` class template provides polymorphic wrappers
|
| 2413 |
+
that generalize the notion of a callable object [[func.def]]. These
|
| 2414 |
+
wrappers can store, copy, move, and call arbitrary callable objects,
|
| 2415 |
+
given a call signature.
|
| 2416 |
+
|
| 2417 |
+
*Recommended practice:* Implementations should avoid the use of
|
| 2418 |
+
dynamically allocated memory for a small contained value.
|
| 2419 |
+
|
| 2420 |
+
[*Note 1*: Such small-object optimization can only be applied to a type
|
| 2421 |
+
`T` for which `is_nothrow_move_constructible_v<T>` is
|
| 2422 |
+
`true`. — *end note*]
|
| 2423 |
+
|
| 2424 |
+
##### Constructors, assignments, and destructor <a id="func.wrap.copy.ctor">[[func.wrap.copy.ctor]]</a>
|
| 2425 |
+
|
| 2426 |
+
``` cpp
|
| 2427 |
+
template<class VT>
|
| 2428 |
+
static constexpr bool is-callable-from = see below;
|
| 2429 |
+
```
|
| 2430 |
+
|
| 2431 |
+
If *noex* is `true`, *`is-callable-from`*`<VT>` is equal to:
|
| 2432 |
+
|
| 2433 |
+
``` cpp
|
| 2434 |
+
is_nothrow_invocable_r_v<R, VT cv ref, ArgTypes...> &&
|
| 2435 |
+
is_nothrow_invocable_r_v<R, VT inv-quals, ArgTypes...>
|
| 2436 |
+
```
|
| 2437 |
+
|
| 2438 |
+
Otherwise, *`is-callable-from`*`<VT>` is equal to:
|
| 2439 |
+
|
| 2440 |
+
``` cpp
|
| 2441 |
+
is_invocable_r_v<R, VT cv ref, ArgTypes...> &&
|
| 2442 |
+
is_invocable_r_v<R, VT inv-quals, ArgTypes...>
|
| 2443 |
+
```
|
| 2444 |
+
|
| 2445 |
+
``` cpp
|
| 2446 |
+
copyable_function() noexcept;
|
| 2447 |
+
copyable_function(nullptr_t) noexcept;
|
| 2448 |
+
```
|
| 2449 |
+
|
| 2450 |
+
*Ensures:* `*this` has no target object.
|
| 2451 |
+
|
| 2452 |
+
``` cpp
|
| 2453 |
+
copyable_function(const copyable_function& f);
|
| 2454 |
+
```
|
| 2455 |
+
|
| 2456 |
+
*Ensures:* `*this` has no target object if `f` had no target object.
|
| 2457 |
+
Otherwise, the target object of `*this` is a copy of the target object
|
| 2458 |
+
of `f`.
|
| 2459 |
+
|
| 2460 |
+
*Throws:* Any exception thrown by the initialization of the target
|
| 2461 |
+
object. May throw `bad_alloc`.
|
| 2462 |
+
|
| 2463 |
+
``` cpp
|
| 2464 |
+
copyable_function(copyable_function&& f) noexcept;
|
| 2465 |
+
```
|
| 2466 |
+
|
| 2467 |
+
*Ensures:* The target object of `*this` is the target object `f` had
|
| 2468 |
+
before construction, and `f` is in a valid state with an unspecified
|
| 2469 |
+
value.
|
| 2470 |
+
|
| 2471 |
+
``` cpp
|
| 2472 |
+
template<class F> copyable_function(F&& f);
|
| 2473 |
+
```
|
| 2474 |
+
|
| 2475 |
+
Let `VT` be `decay_t<F>`.
|
| 2476 |
+
|
| 2477 |
+
*Constraints:*
|
| 2478 |
+
|
| 2479 |
+
- `remove_cvref_t<F>` is not the same type as `copyable_function`, and
|
| 2480 |
+
- `remove_cvref_t<F>` is not a specialization of `in_place_type_t`, and
|
| 2481 |
+
- *`is-callable-from`*`<VT>` is `true`.
|
| 2482 |
+
|
| 2483 |
+
*Mandates:*
|
| 2484 |
+
|
| 2485 |
+
- `is_constructible_v<VT, F>` is `true`, and
|
| 2486 |
+
- `is_copy_constructible_v<VT>` is `true`.
|
| 2487 |
+
|
| 2488 |
+
*Preconditions:* `VT` meets the *Cpp17Destructible* and
|
| 2489 |
+
*Cpp17CopyConstructible* requirements.
|
| 2490 |
+
|
| 2491 |
+
*Ensures:* `*this` has no target object if any of the following hold:
|
| 2492 |
+
|
| 2493 |
+
- `f` is a null function pointer value, or
|
| 2494 |
+
- `f` is a null member pointer value, or
|
| 2495 |
+
- `remove_cvref_t<F>` is a specialization of the `copyable_function`
|
| 2496 |
+
class template, and `f` has no target object.
|
| 2497 |
+
|
| 2498 |
+
Otherwise, `*this` has a target object of type `VT`
|
| 2499 |
+
direct-non-list-initialized with `std::forward<F>(f)`.
|
| 2500 |
+
|
| 2501 |
+
*Throws:* Any exception thrown by the initialization of the target
|
| 2502 |
+
object. May throw `bad_alloc` unless `VT` is a function pointer or a
|
| 2503 |
+
specialization of `reference_wrapper`.
|
| 2504 |
+
|
| 2505 |
+
``` cpp
|
| 2506 |
+
template<class T, class... Args>
|
| 2507 |
+
explicit copyable_function(in_place_type_t<T>, Args&&... args);
|
| 2508 |
+
```
|
| 2509 |
+
|
| 2510 |
+
Let `VT` be `decay_t<T>`.
|
| 2511 |
+
|
| 2512 |
+
*Constraints:*
|
| 2513 |
+
|
| 2514 |
+
- `is_constructible_v<VT, Args...>` is `true`, and
|
| 2515 |
+
- *`is-callable-from`*`<VT>` is `true`.
|
| 2516 |
+
|
| 2517 |
+
*Mandates:*
|
| 2518 |
+
|
| 2519 |
+
- `VT` is the same type as `T`, and
|
| 2520 |
+
- `is_copy_constructible_v<VT>` is `true`.
|
| 2521 |
+
|
| 2522 |
+
*Preconditions:* `VT` meets the *Cpp17Destructible* and
|
| 2523 |
+
*Cpp17CopyConstructible* requirements.
|
| 2524 |
+
|
| 2525 |
+
*Ensures:* `*this` has a target object of type `VT`
|
| 2526 |
+
direct-non-list-initialized with `std::forward<Args>(args)...`.
|
| 2527 |
+
|
| 2528 |
+
*Throws:* Any exception thrown by the initialization of the target
|
| 2529 |
+
object. May throw `bad_alloc` unless `VT` is a pointer or a
|
| 2530 |
+
specialization of `reference_wrapper`.
|
| 2531 |
+
|
| 2532 |
+
``` cpp
|
| 2533 |
+
template<class T, class U, class... Args>
|
| 2534 |
+
explicit copyable_function(in_place_type_t<T>, initializer_list<U> ilist, Args&&... args);
|
| 2535 |
+
```
|
| 2536 |
+
|
| 2537 |
+
Let `VT` be `decay_t<T>`.
|
| 2538 |
+
|
| 2539 |
+
*Constraints:*
|
| 2540 |
+
|
| 2541 |
+
- `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`, and
|
| 2542 |
+
- *`is-callable-from`*`<VT>` is `true`.
|
| 2543 |
+
|
| 2544 |
+
*Mandates:*
|
| 2545 |
+
|
| 2546 |
+
- `VT` is the same type as `T`, and
|
| 2547 |
+
- `is_copy_constructible_v<VT>` is `true`.
|
| 2548 |
+
|
| 2549 |
+
*Preconditions:* `VT` meets the *Cpp17Destructible* and
|
| 2550 |
+
*Cpp17CopyConstructible* requirements.
|
| 2551 |
+
|
| 2552 |
+
*Ensures:* `*this` has a target object of type `VT`
|
| 2553 |
+
direct-non-list-initialized with `ilist, std::forward<Args>(args)...`.
|
| 2554 |
+
|
| 2555 |
+
*Throws:* Any exception thrown by the initialization of the target
|
| 2556 |
+
object. May throw `bad_alloc` unless `VT` is a pointer or a
|
| 2557 |
+
specialization of `reference_wrapper`.
|
| 2558 |
+
|
| 2559 |
+
``` cpp
|
| 2560 |
+
copyable_function& operator=(const copyable_function& f);
|
| 2561 |
+
```
|
| 2562 |
+
|
| 2563 |
+
*Effects:* Equivalent to: `copyable_function(f).swap(*this);`
|
| 2564 |
+
|
| 2565 |
+
*Returns:* `*this`.
|
| 2566 |
+
|
| 2567 |
+
``` cpp
|
| 2568 |
+
copyable_function& operator=(copyable_function&& f);
|
| 2569 |
+
```
|
| 2570 |
+
|
| 2571 |
+
*Effects:* Equivalent to: `copyable_function(std::move(f)).swap(*this);`
|
| 2572 |
+
|
| 2573 |
+
*Returns:* `*this`.
|
| 2574 |
+
|
| 2575 |
+
``` cpp
|
| 2576 |
+
copyable_function& operator=(nullptr_t) noexcept;
|
| 2577 |
+
```
|
| 2578 |
+
|
| 2579 |
+
*Effects:* Destroys the target object of `*this`, if any.
|
| 2580 |
+
|
| 2581 |
+
*Returns:* `*this`.
|
| 2582 |
+
|
| 2583 |
+
``` cpp
|
| 2584 |
+
template<class F> copyable_function& operator=(F&& f);
|
| 2585 |
+
```
|
| 2586 |
+
|
| 2587 |
+
*Effects:* Equivalent to:
|
| 2588 |
+
`copyable_function(std::forward<F>(f)).swap(*this);`
|
| 2589 |
+
|
| 2590 |
+
*Returns:* `*this`.
|
| 2591 |
+
|
| 2592 |
+
``` cpp
|
| 2593 |
+
~copyable_function();
|
| 2594 |
+
```
|
| 2595 |
+
|
| 2596 |
+
*Effects:* Destroys the target object of `*this`, if any.
|
| 2597 |
+
|
| 2598 |
+
##### Invocation <a id="func.wrap.copy.inv">[[func.wrap.copy.inv]]</a>
|
| 2599 |
+
|
| 2600 |
+
``` cpp
|
| 2601 |
+
explicit operator bool() const noexcept;
|
| 2602 |
+
```
|
| 2603 |
+
|
| 2604 |
+
*Returns:* `true` if `*this` has a target object, otherwise `false`.
|
| 2605 |
+
|
| 2606 |
+
``` cpp
|
| 2607 |
+
R operator()(ArgTypes... args) cv ref noexcept(noex);
|
| 2608 |
+
```
|
| 2609 |
+
|
| 2610 |
+
*Preconditions:* `*this` has a target object.
|
| 2611 |
+
|
| 2612 |
+
*Effects:* Equivalent to:
|
| 2613 |
+
|
| 2614 |
+
``` cpp
|
| 2615 |
+
return INVOKE<R>(static_cast<F inv-quals>(f), std::forward<ArgTypes>(args)...);
|
| 2616 |
+
```
|
| 2617 |
+
|
| 2618 |
+
where `f` is an lvalue designating the target object of `*this` and `F`
|
| 2619 |
+
is the type of `f`.
|
| 2620 |
+
|
| 2621 |
+
##### Utility <a id="func.wrap.copy.util">[[func.wrap.copy.util]]</a>
|
| 2622 |
+
|
| 2623 |
+
``` cpp
|
| 2624 |
+
void swap(copyable_function& other) noexcept;
|
| 2625 |
+
```
|
| 2626 |
+
|
| 2627 |
+
*Effects:* Exchanges the target objects of `*this` and `other`.
|
| 2628 |
+
|
| 2629 |
+
``` cpp
|
| 2630 |
+
friend void swap(copyable_function& f1, copyable_function& f2) noexcept;
|
| 2631 |
+
```
|
| 2632 |
+
|
| 2633 |
+
*Effects:* Equivalent to `f1.swap(f2)`.
|
| 2634 |
+
|
| 2635 |
+
``` cpp
|
| 2636 |
+
friend bool operator==(const copyable_function& f, nullptr_t) noexcept;
|
| 2637 |
+
```
|
| 2638 |
+
|
| 2639 |
+
*Returns:* `true` if `f` has no target object, otherwise `false`.
|
| 2640 |
+
|
| 2641 |
+
#### Non-owning wrapper <a id="func.wrap.ref">[[func.wrap.ref]]</a>
|
| 2642 |
+
|
| 2643 |
+
##### General <a id="func.wrap.ref.general">[[func.wrap.ref.general]]</a>
|
| 2644 |
+
|
| 2645 |
+
The header provides partial specializations of `function_ref` for each
|
| 2646 |
+
combination of the possible replacements of the placeholders cv and
|
| 2647 |
+
*noex* where:
|
| 2648 |
+
|
| 2649 |
+
- cv is either const or empty, and
|
| 2650 |
+
- *noex* is either `true` or `false`.
|
| 2651 |
+
|
| 2652 |
+
##### Class template `function_ref` <a id="func.wrap.ref.class">[[func.wrap.ref.class]]</a>
|
| 2653 |
+
|
| 2654 |
+
``` cpp
|
| 2655 |
+
namespace std {
|
| 2656 |
+
template<class R, class... ArgTypes>
|
| 2657 |
+
class function_ref<R(ArgTypes...) cv noexcept(noex)> {
|
| 2658 |
+
public:
|
| 2659 |
+
// [func.wrap.ref.ctor], constructors and assignment operators
|
| 2660 |
+
template<class F> function_ref(F*) noexcept;
|
| 2661 |
+
template<class F> constexpr function_ref(F&&) noexcept;
|
| 2662 |
+
template<auto f> constexpr function_ref(nontype_t<f>) noexcept;
|
| 2663 |
+
template<auto f, class U> constexpr function_ref(nontype_t<f>, U&&) noexcept;
|
| 2664 |
+
template<auto f, class T> constexpr function_ref(nontype_t<f>, cv T*) noexcept;
|
| 2665 |
+
|
| 2666 |
+
constexpr function_ref(const function_ref&) noexcept = default;
|
| 2667 |
+
constexpr function_ref& operator=(const function_ref&) noexcept = default;
|
| 2668 |
+
template<class T> function_ref& operator=(T) = delete;
|
| 2669 |
+
|
| 2670 |
+
// [func.wrap.ref.inv], invocation
|
| 2671 |
+
R operator()(ArgTypes...) const noexcept(noex);
|
| 2672 |
+
|
| 2673 |
+
private:
|
| 2674 |
+
template<class... T>
|
| 2675 |
+
static constexpr bool is-invocable-using = see belownc; // exposition only
|
| 2676 |
+
|
| 2677 |
+
R (*thunk-ptr)(BoundEntityType, ArgTypes&&...) noexcept(noex); // exposition only
|
| 2678 |
+
BoundEntityType bound-entity; // exposition only
|
| 2679 |
+
};
|
| 2680 |
+
|
| 2681 |
+
// [func.wrap.ref.deduct], deduction guides
|
| 2682 |
+
template<class F>
|
| 2683 |
+
function_ref(F*) -> function_ref<F>;
|
| 2684 |
+
template<auto f>
|
| 2685 |
+
function_ref(nontype_t<f>) -> function_ref<see below>;
|
| 2686 |
+
template<auto f, class T>
|
| 2687 |
+
function_ref(nontype_t<f>, T&&) -> function_ref<see below>;
|
| 2688 |
+
}
|
| 2689 |
+
```
|
| 2690 |
+
|
| 2691 |
+
An object of class `function_ref<R(Args...) cv noexcept(noex)>` stores a
|
| 2692 |
+
pointer to function *`thunk-ptr`* and an object *`bound-entity`*. The
|
| 2693 |
+
object *`bound-entity`* has an unspecified trivially copyable type
|
| 2694 |
+
*`BoundEntityType`*, that models `copyable` and is capable of storing a
|
| 2695 |
+
pointer to object value or a pointer to function value. The type of
|
| 2696 |
+
*`thunk-ptr`* is `R(*)(BoundEntityType, Args&&...) noexcept(noex)`.
|
| 2697 |
+
|
| 2698 |
+
Each specialization of `function_ref` is a trivially copyable type
|
| 2699 |
+
[[term.trivially.copyable.type]] that models `copyable`.
|
| 2700 |
+
|
| 2701 |
+
Within subclause [[func.wrap.ref]], `call-args` is an argument pack
|
| 2702 |
+
with elements such that
|
| 2703 |
+
|
| 2704 |
+
``` cpp
|
| 2705 |
+
decltype((call-args))...
|
| 2706 |
+
```
|
| 2707 |
+
|
| 2708 |
+
denote `ArgTypes&&...` respectively.
|
| 2709 |
+
|
| 2710 |
+
##### Constructors and assignment operators <a id="func.wrap.ref.ctor">[[func.wrap.ref.ctor]]</a>
|
| 2711 |
+
|
| 2712 |
+
``` cpp
|
| 2713 |
+
template<class... T>
|
| 2714 |
+
static constexpr bool is-invocable-using = see below;
|
| 2715 |
+
```
|
| 2716 |
+
|
| 2717 |
+
If *noex* is `true`, *`is-invocable-using`*`<T...>` is equal to:
|
| 2718 |
+
|
| 2719 |
+
``` cpp
|
| 2720 |
+
is_nothrow_invocable_r_v<R, T..., ArgTypes...>
|
| 2721 |
+
```
|
| 2722 |
+
|
| 2723 |
+
Otherwise, *`is-invocable-using`*`<T...>` is equal to:
|
| 2724 |
+
|
| 2725 |
+
``` cpp
|
| 2726 |
+
is_invocable_r_v<R, T..., ArgTypes...>
|
| 2727 |
+
```
|
| 2728 |
+
|
| 2729 |
+
``` cpp
|
| 2730 |
+
template<class F> function_ref(F* f) noexcept;
|
| 2731 |
+
```
|
| 2732 |
+
|
| 2733 |
+
*Constraints:*
|
| 2734 |
+
|
| 2735 |
+
- `is_function_v<F>` is `true`, and
|
| 2736 |
+
- *`is-invocable-using`*`<F>` is `true`.
|
| 2737 |
+
|
| 2738 |
+
*Preconditions:* `f` is not a null pointer.
|
| 2739 |
+
|
| 2740 |
+
*Effects:* Initializes *bound-entity* with `f`, and *thunk-ptr* with the
|
| 2741 |
+
address of a function *`thunk`* such that
|
| 2742 |
+
*`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
|
| 2743 |
+
expression-equivalent [[defns.expression.equivalent]] to
|
| 2744 |
+
`invoke_r<R>(f, `*`call-args`*`...)`.
|
| 2745 |
+
|
| 2746 |
+
``` cpp
|
| 2747 |
+
template<class F> constexpr function_ref(F&& f) noexcept;
|
| 2748 |
+
```
|
| 2749 |
+
|
| 2750 |
+
Let `T` be `remove_reference_t<F>`.
|
| 2751 |
+
|
| 2752 |
+
*Constraints:*
|
| 2753 |
+
|
| 2754 |
+
- `remove_cvref_t<F>` is not the same type as `function_ref`,
|
| 2755 |
+
- `is_member_pointer_v<T>` is `false`, and
|
| 2756 |
+
- *`is-invocable-using`*`<cv T&>` is `true`.
|
| 2757 |
+
|
| 2758 |
+
*Effects:* Initializes *bound-entity* with `addressof(f)`, and
|
| 2759 |
+
*thunk-ptr* with the address of a function *`thunk`* such that
|
| 2760 |
+
*`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
|
| 2761 |
+
expression-equivalent [[defns.expression.equivalent]] to
|
| 2762 |
+
`invoke_r<R>(static_cast<cv T&>(f), `*`call-args`*`...)`.
|
| 2763 |
+
|
| 2764 |
+
``` cpp
|
| 2765 |
+
template<auto f> constexpr function_ref(nontype_t<f>) noexcept;
|
| 2766 |
+
```
|
| 2767 |
+
|
| 2768 |
+
Let `F` be `decltype(f)`.
|
| 2769 |
+
|
| 2770 |
+
*Constraints:* *`is-invocable-using`*`<F>` is `true`.
|
| 2771 |
+
|
| 2772 |
+
*Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
|
| 2773 |
+
then `f != nullptr` is `true`.
|
| 2774 |
+
|
| 2775 |
+
*Effects:* Initializes *bound-entity* with a pointer to an unspecified
|
| 2776 |
+
object or null pointer value, and *thunk-ptr* with the address of a
|
| 2777 |
+
function *`thunk`* such that
|
| 2778 |
+
*`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
|
| 2779 |
+
expression-equivalent [[defns.expression.equivalent]] to
|
| 2780 |
+
`invoke_r<R>(f, `*`call-args`*`...)`.
|
| 2781 |
+
|
| 2782 |
+
``` cpp
|
| 2783 |
+
template<auto f, class U>
|
| 2784 |
+
constexpr function_ref(nontype_t<f>, U&& obj) noexcept;
|
| 2785 |
+
```
|
| 2786 |
+
|
| 2787 |
+
Let `T` be `remove_reference_t<U>` and `F` be `decltype(f)`.
|
| 2788 |
+
|
| 2789 |
+
*Constraints:*
|
| 2790 |
+
|
| 2791 |
+
- `is_rvalue_reference_v<U&&>` is `false`, and
|
| 2792 |
+
- *`is-invocable-using`*`<F, cv T&>` is `true`.
|
| 2793 |
+
|
| 2794 |
+
*Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
|
| 2795 |
+
then `f != nullptr` is `true`.
|
| 2796 |
+
|
| 2797 |
+
*Effects:* Initializes *bound-entity* with `addressof(obj)`, and
|
| 2798 |
+
*thunk-ptr* with the address of a function *`thunk`* such that
|
| 2799 |
+
*`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
|
| 2800 |
+
expression-equivalent [[defns.expression.equivalent]] to
|
| 2801 |
+
`invoke_r<R>(f, static_cast<cv T&>(obj), `*`call-args`*`...)`.
|
| 2802 |
+
|
| 2803 |
+
``` cpp
|
| 2804 |
+
template<auto f, class T>
|
| 2805 |
+
constexpr function_ref(nontype_t<f>, cv T* obj) noexcept;
|
| 2806 |
+
```
|
| 2807 |
+
|
| 2808 |
+
Let `F` be `decltype(f)`.
|
| 2809 |
+
|
| 2810 |
+
*Constraints:* *`is-invocable-using`*`<F, cv T*>` is `true`.
|
| 2811 |
+
|
| 2812 |
+
*Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
|
| 2813 |
+
then `f != nullptr` is `true`.
|
| 2814 |
+
|
| 2815 |
+
*Preconditions:* If `is_member_pointer_v<F>` is `true`, `obj` is not a
|
| 2816 |
+
null pointer.
|
| 2817 |
+
|
| 2818 |
+
*Effects:* Initializes *bound-entity* with `obj`, and *thunk-ptr* with
|
| 2819 |
+
the address of a function *`thunk`* such that
|
| 2820 |
+
*`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
|
| 2821 |
+
expression-equivalent [[defns.expression.equivalent]] to
|
| 2822 |
+
`invoke_r<R>(f, obj, `*`call-args`*`...)`.
|
| 2823 |
+
|
| 2824 |
+
``` cpp
|
| 2825 |
+
template<class T> function_ref& operator=(T) = delete;
|
| 2826 |
+
```
|
| 2827 |
+
|
| 2828 |
+
*Constraints:*
|
| 2829 |
+
|
| 2830 |
+
- `T` is not the same type as `function_ref`,
|
| 2831 |
+
- `is_pointer_v<T>` is `false`, and
|
| 2832 |
+
- `T` is not a specialization of `nontype_t`.
|
| 2833 |
+
|
| 2834 |
+
##### Invocation <a id="func.wrap.ref.inv">[[func.wrap.ref.inv]]</a>
|
| 2835 |
+
|
| 2836 |
+
``` cpp
|
| 2837 |
+
R operator()(ArgTypes... args) const noexcept(noex);
|
| 2838 |
+
```
|
| 2839 |
+
|
| 2840 |
+
*Effects:* Equivalent to:
|
| 2841 |
+
`return `*`thunk-ptr`*`(`*`bound-entity`*`, std::forward<ArgTypes>(args)...);`
|
| 2842 |
+
|
| 2843 |
+
##### Deduction guides <a id="func.wrap.ref.deduct">[[func.wrap.ref.deduct]]</a>
|
| 2844 |
+
|
| 2845 |
+
``` cpp
|
| 2846 |
+
template<class F>
|
| 2847 |
+
function_ref(F*) -> function_ref<F>;
|
| 2848 |
+
```
|
| 2849 |
+
|
| 2850 |
+
*Constraints:* `is_function_v<F>` is `true`.
|
| 2851 |
+
|
| 2852 |
+
``` cpp
|
| 2853 |
+
template<auto f>
|
| 2854 |
+
function_ref(nontype_t<f>) -> function_ref<see below>;
|
| 2855 |
+
```
|
| 2856 |
+
|
| 2857 |
+
Let `F` be `remove_pointer_t<decltype(f)>`.
|
| 2858 |
+
|
| 2859 |
+
*Constraints:* `is_function_v<F>` is `true`.
|
| 2860 |
+
|
| 2861 |
+
*Remarks:* The deduced type is `function_ref<F>`.
|
| 2862 |
+
|
| 2863 |
+
``` cpp
|
| 2864 |
+
template<auto f, class T>
|
| 2865 |
+
function_ref(nontype_t<f>, T&&) -> function_ref<see below>;
|
| 2866 |
+
```
|
| 2867 |
+
|
| 2868 |
+
Let `F` be `decltype(f)`.
|
| 2869 |
+
|
| 2870 |
+
*Constraints:*
|
| 2871 |
+
|
| 2872 |
+
- `F` is of the form `R(G::*)(A...) cv `\\ₒₚₜ ` noexcept(E)` for a type
|
| 2873 |
+
`G`, or
|
| 2874 |
+
- `F` is of the form `M G::*` for a type `G` and an object type `M`, in
|
| 2875 |
+
which case let `R` be `invoke_result_t<F, T&>`, `A...` be an empty
|
| 2876 |
+
pack, and `E` be `false`, or
|
| 2877 |
+
- `F` is of the form `R(*)(G, A...) noexcept(E)` for a type `G`.
|
| 2878 |
+
|
| 2879 |
+
*Remarks:* The deduced type is `function_ref<R(A...) noexcept(E)>`.
|
| 2880 |
+
|
| 2881 |
### Searchers <a id="func.search">[[func.search]]</a>
|
| 2882 |
|
| 2883 |
#### General <a id="func.search.general">[[func.search.general]]</a>
|
| 2884 |
|
| 2885 |
Subclause [[func.search]] provides function object types
|
|
|
|
| 2991 |
Hash hf = Hash(),
|
| 2992 |
BinaryPredicate pred = BinaryPredicate());
|
| 2993 |
```
|
| 2994 |
|
| 2995 |
*Preconditions:* The value type of `RandomAccessIterator1` meets the
|
| 2996 |
+
*Cpp17DefaultConstructible*, *Cpp17CopyConstructible*, and
|
| 2997 |
*Cpp17CopyAssignable* requirements.
|
| 2998 |
|
| 2999 |
Let `V` be `iterator_traits<RandomAccessIterator1>::value_type`. For any
|
| 3000 |
two values `A` and `B` of type `V`, if `pred(A, B) == true`, then
|
| 3001 |
`hf(A) == hf(B)` is `true`.
|