tmp/tmp33eqjmv5/{from.md → to.md}
RENAMED
|
@@ -1,126 +1,148 @@
|
|
| 1 |
##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
|
| 2 |
|
| 3 |
-
When any `function` constructor that takes a first argument of type
|
| 4 |
-
`allocator_arg_t` is invoked, the second argument shall have a type that
|
| 5 |
-
conforms to the requirements for Allocator (Table
|
| 6 |
-
[[allocator.requirements]]). A copy of the allocator argument is used to
|
| 7 |
-
allocate memory, if necessary, for the internal data structures of the
|
| 8 |
-
constructed `function` object.
|
| 9 |
-
|
| 10 |
``` cpp
|
| 11 |
function() noexcept;
|
| 12 |
-
template <class A> function(allocator_arg_t, const A& a) noexcept;
|
| 13 |
```
|
| 14 |
|
| 15 |
*Postconditions:* `!*this`.
|
| 16 |
|
| 17 |
``` cpp
|
| 18 |
function(nullptr_t) noexcept;
|
| 19 |
-
template <class A> function(allocator_arg_t, const A& a, nullptr_t) noexcept;
|
| 20 |
```
|
| 21 |
|
| 22 |
*Postconditions:* `!*this`.
|
| 23 |
|
| 24 |
``` cpp
|
| 25 |
function(const function& f);
|
| 26 |
-
template <class A> function(allocator_arg_t, const A& a, const function& f);
|
| 27 |
```
|
| 28 |
|
| 29 |
*Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
|
| 30 |
`f.target()`.
|
| 31 |
|
| 32 |
-
*Throws:* shall not throw exceptions if `f`’s target is a
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
``` cpp
|
| 41 |
function(function&& f);
|
| 42 |
-
template <class A> function(allocator_arg_t, const A& a, function&& f);
|
| 43 |
```
|
| 44 |
|
| 45 |
-
*
|
| 46 |
-
|
| 47 |
-
state with an unspecified value.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
``` cpp
|
| 50 |
template<class F> function(F f);
|
| 51 |
-
template <class F, class A> function(allocator_arg_t, const A& a, F f);
|
| 52 |
```
|
| 53 |
|
| 54 |
*Requires:* `F` shall be `CopyConstructible`.
|
| 55 |
|
| 56 |
-
*Remarks:*
|
| 57 |
-
resolution unless `
|
| 58 |
-
types `ArgTypes...` and return type `R`.
|
| 59 |
|
| 60 |
*Postconditions:* `!*this` if any of the following hold:
|
| 61 |
|
| 62 |
- `f` is a null function pointer value.
|
| 63 |
- `f` is a null member pointer value.
|
| 64 |
- `F` is an instance of the `function` class template, and `!f`.
|
| 65 |
|
| 66 |
Otherwise, `*this` targets a copy of `f` initialized with
|
| 67 |
-
`std::move(f)`.
|
|
|
|
|
|
|
| 68 |
dynamically allocated memory for small callable objects, for example,
|
| 69 |
-
where `f`
|
| 70 |
-
|
| 71 |
|
| 72 |
*Throws:* shall not throw exceptions when `f` is a function pointer or a
|
| 73 |
`reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
|
| 74 |
any exception thrown by `F`’s copy or move constructor.
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
``` cpp
|
| 77 |
function& operator=(const function& f);
|
| 78 |
```
|
| 79 |
|
| 80 |
-
*Effects:* `function(f).swap(*this);`
|
| 81 |
|
| 82 |
-
*Returns:* `*this`
|
| 83 |
|
| 84 |
``` cpp
|
| 85 |
function& operator=(function&& f);
|
| 86 |
```
|
| 87 |
|
| 88 |
*Effects:* Replaces the target of `*this` with the target of `f`.
|
| 89 |
|
| 90 |
-
*Returns:* `*this`
|
| 91 |
|
| 92 |
``` cpp
|
| 93 |
-
function& operator=(nullptr_t);
|
| 94 |
```
|
| 95 |
|
| 96 |
*Effects:* If `*this != nullptr`, destroys the target of `this`.
|
| 97 |
|
| 98 |
*Postconditions:* `!(*this)`.
|
| 99 |
|
| 100 |
-
*Returns:* `*this`
|
| 101 |
|
| 102 |
``` cpp
|
| 103 |
template<class F> function& operator=(F&& f);
|
| 104 |
```
|
| 105 |
|
| 106 |
-
*Effects:* `function(std::forward<F>(f)).swap(*this);`
|
| 107 |
|
| 108 |
-
*Returns:* `*this`
|
| 109 |
|
| 110 |
*Remarks:* This assignment operator shall not participate in overload
|
| 111 |
-
resolution unless `
|
| 112 |
-
|
| 113 |
-
return type `R`.
|
| 114 |
|
| 115 |
``` cpp
|
| 116 |
template<class F> function& operator=(reference_wrapper<F> f) noexcept;
|
| 117 |
```
|
| 118 |
|
| 119 |
-
*Effects:* `function(f).swap(*this);`
|
| 120 |
|
| 121 |
-
*Returns:* `*this`
|
| 122 |
|
| 123 |
``` cpp
|
| 124 |
~function();
|
| 125 |
```
|
| 126 |
|
|
|
|
| 1 |
##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
``` cpp
|
| 4 |
function() noexcept;
|
|
|
|
| 5 |
```
|
| 6 |
|
| 7 |
*Postconditions:* `!*this`.
|
| 8 |
|
| 9 |
``` cpp
|
| 10 |
function(nullptr_t) noexcept;
|
|
|
|
| 11 |
```
|
| 12 |
|
| 13 |
*Postconditions:* `!*this`.
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
function(const function& f);
|
|
|
|
| 17 |
```
|
| 18 |
|
| 19 |
*Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
|
| 20 |
`f.target()`.
|
| 21 |
|
| 22 |
+
*Throws:* shall not throw exceptions if `f`’s target is a specialization
|
| 23 |
+
of `reference_wrapper` or a function pointer. Otherwise, may throw
|
| 24 |
+
`bad_alloc` or any exception thrown by the copy constructor of the
|
| 25 |
+
stored callable object.
|
| 26 |
+
|
| 27 |
+
[*Note 1*: Implementations are encouraged to avoid the use of
|
| 28 |
+
dynamically allocated memory for small callable objects, for example,
|
| 29 |
+
where `f`’s target is an object holding only a pointer or reference to
|
| 30 |
+
an object and a member function pointer. — *end note*]
|
| 31 |
|
| 32 |
``` cpp
|
| 33 |
function(function&& f);
|
|
|
|
| 34 |
```
|
| 35 |
|
| 36 |
+
*Postconditions:* If `!f`, `*this` has no target; otherwise, the target
|
| 37 |
+
of `*this` is equivalent to the target of `f` before the construction,
|
| 38 |
+
and `f` is in a valid state with an unspecified value.
|
| 39 |
+
|
| 40 |
+
*Throws:* shall not throw exceptions if `f`’s target is a specialization
|
| 41 |
+
of `reference_wrapper` or a function pointer. Otherwise, may throw
|
| 42 |
+
`bad_alloc` or any exception thrown by the copy or move constructor of
|
| 43 |
+
the stored callable object.
|
| 44 |
+
|
| 45 |
+
[*Note 2*: Implementations are encouraged to avoid the use of
|
| 46 |
+
dynamically allocated memory for small callable objects, for example,
|
| 47 |
+
where `f`’s target is an object holding only a pointer or reference to
|
| 48 |
+
an object and a member function pointer. — *end note*]
|
| 49 |
|
| 50 |
``` cpp
|
| 51 |
template<class F> function(F f);
|
|
|
|
| 52 |
```
|
| 53 |
|
| 54 |
*Requires:* `F` shall be `CopyConstructible`.
|
| 55 |
|
| 56 |
+
*Remarks:* This constructor template shall not participate in overload
|
| 57 |
+
resolution unless `F` is Lvalue-Callable ([[func.wrap.func]]) for
|
| 58 |
+
argument types `ArgTypes...` and return type `R`.
|
| 59 |
|
| 60 |
*Postconditions:* `!*this` if any of the following hold:
|
| 61 |
|
| 62 |
- `f` is a null function pointer value.
|
| 63 |
- `f` is a null member pointer value.
|
| 64 |
- `F` is an instance of the `function` class template, and `!f`.
|
| 65 |
|
| 66 |
Otherwise, `*this` targets a copy of `f` initialized with
|
| 67 |
+
`std::move(f)`.
|
| 68 |
+
|
| 69 |
+
[*Note 3*: Implementations are encouraged to avoid the use of
|
| 70 |
dynamically allocated memory for small callable objects, for example,
|
| 71 |
+
where `f` is an object holding only a pointer or reference to an object
|
| 72 |
+
and a member function pointer. — *end note*]
|
| 73 |
|
| 74 |
*Throws:* shall not throw exceptions when `f` is a function pointer or a
|
| 75 |
`reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
|
| 76 |
any exception thrown by `F`’s copy or move constructor.
|
| 77 |
|
| 78 |
+
``` cpp
|
| 79 |
+
template<class F> function(F) -> function<see below>;
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
*Remarks:* This deduction guide participates in overload resolution only
|
| 83 |
+
if `&F::operator()` is well-formed when treated as an unevaluated
|
| 84 |
+
operand. In that case, if `decltype(&F::operator())` is of the form
|
| 85 |
+
`R(G::*)(A...)` cv `&`ₒₚₜ ` noexcept` for a class type `G`, then the
|
| 86 |
+
deduced type is `function<R(A...)>`.
|
| 87 |
+
|
| 88 |
+
[*Example 1*:
|
| 89 |
+
|
| 90 |
+
``` cpp
|
| 91 |
+
void f() {
|
| 92 |
+
int i{5};
|
| 93 |
+
function g = [&](double) { return i; }; // deduces function<int(double)>
|
| 94 |
+
}
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
— *end example*]
|
| 98 |
+
|
| 99 |
``` cpp
|
| 100 |
function& operator=(const function& f);
|
| 101 |
```
|
| 102 |
|
| 103 |
+
*Effects:* As if by `function(f).swap(*this);`
|
| 104 |
|
| 105 |
+
*Returns:* `*this`.
|
| 106 |
|
| 107 |
``` cpp
|
| 108 |
function& operator=(function&& f);
|
| 109 |
```
|
| 110 |
|
| 111 |
*Effects:* Replaces the target of `*this` with the target of `f`.
|
| 112 |
|
| 113 |
+
*Returns:* `*this`.
|
| 114 |
|
| 115 |
``` cpp
|
| 116 |
+
function& operator=(nullptr_t) noexcept;
|
| 117 |
```
|
| 118 |
|
| 119 |
*Effects:* If `*this != nullptr`, destroys the target of `this`.
|
| 120 |
|
| 121 |
*Postconditions:* `!(*this)`.
|
| 122 |
|
| 123 |
+
*Returns:* `*this`.
|
| 124 |
|
| 125 |
``` cpp
|
| 126 |
template<class F> function& operator=(F&& f);
|
| 127 |
```
|
| 128 |
|
| 129 |
+
*Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
|
| 130 |
|
| 131 |
+
*Returns:* `*this`.
|
| 132 |
|
| 133 |
*Remarks:* This assignment operator shall not participate in overload
|
| 134 |
+
resolution unless `decay_t<F>` is Lvalue-Callable ([[func.wrap.func]])
|
| 135 |
+
for argument types `ArgTypes...` and return type `R`.
|
|
|
|
| 136 |
|
| 137 |
``` cpp
|
| 138 |
template<class F> function& operator=(reference_wrapper<F> f) noexcept;
|
| 139 |
```
|
| 140 |
|
| 141 |
+
*Effects:* As if by: `function(f).swap(*this);`
|
| 142 |
|
| 143 |
+
*Returns:* `*this`.
|
| 144 |
|
| 145 |
``` cpp
|
| 146 |
~function();
|
| 147 |
```
|
| 148 |
|