tmp/tmpbsz7f85c/{from.md → to.md}
RENAMED
|
@@ -1,196 +0,0 @@
|
|
| 1 |
-
### Class template `future` <a id="futures.unique_future">[[futures.unique_future]]</a>
|
| 2 |
-
|
| 3 |
-
The class template `future` defines a type for asynchronous return
|
| 4 |
-
objects which do not share their shared state with other asynchronous
|
| 5 |
-
return objects. A default-constructed `future` object has no shared
|
| 6 |
-
state. A `future` object with shared state can be created by functions
|
| 7 |
-
on asynchronous providers ([[futures.state]]) or by the move
|
| 8 |
-
constructor and shares its shared state with the original asynchronous
|
| 9 |
-
provider. The result (value or exception) of a `future` object can be
|
| 10 |
-
set by calling a respective function on an object that shares the same
|
| 11 |
-
shared state.
|
| 12 |
-
|
| 13 |
-
[*Note 1*: Member functions of `future` do not synchronize with
|
| 14 |
-
themselves or with member functions of `shared_future`. — *end note*]
|
| 15 |
-
|
| 16 |
-
The effect of calling any member function other than the destructor, the
|
| 17 |
-
move-assignment operator, `share`, or `valid` on a `future` object for
|
| 18 |
-
which `valid() == false` is undefined.
|
| 19 |
-
|
| 20 |
-
[*Note 2*: It is valid to move from a future object for which
|
| 21 |
-
`valid() == false`. — *end note*]
|
| 22 |
-
|
| 23 |
-
[*Note 3*: Implementations are encouraged to detect this case and throw
|
| 24 |
-
an object of type `future_error` with an error condition of
|
| 25 |
-
`future_errc::no_state`. — *end note*]
|
| 26 |
-
|
| 27 |
-
``` cpp
|
| 28 |
-
namespace std {
|
| 29 |
-
template <class R>
|
| 30 |
-
class future {
|
| 31 |
-
public:
|
| 32 |
-
future() noexcept;
|
| 33 |
-
future(future&&) noexcept;
|
| 34 |
-
future(const future& rhs) = delete;
|
| 35 |
-
~future();
|
| 36 |
-
future& operator=(const future& rhs) = delete;
|
| 37 |
-
future& operator=(future&&) noexcept;
|
| 38 |
-
shared_future<R> share() noexcept;
|
| 39 |
-
|
| 40 |
-
// retrieving the value
|
| 41 |
-
see below get();
|
| 42 |
-
|
| 43 |
-
// functions to check state
|
| 44 |
-
bool valid() const noexcept;
|
| 45 |
-
|
| 46 |
-
void wait() const;
|
| 47 |
-
template <class Rep, class Period>
|
| 48 |
-
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
| 49 |
-
template <class Clock, class Duration>
|
| 50 |
-
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
| 51 |
-
};
|
| 52 |
-
}
|
| 53 |
-
```
|
| 54 |
-
|
| 55 |
-
The implementation shall provide the template `future` and two
|
| 56 |
-
specializations, `future<R&>` and `future<{}void>`. These differ only in
|
| 57 |
-
the return type and return value of the member function `get`, as set
|
| 58 |
-
out in its description, below.
|
| 59 |
-
|
| 60 |
-
``` cpp
|
| 61 |
-
future() noexcept;
|
| 62 |
-
```
|
| 63 |
-
|
| 64 |
-
*Effects:* Constructs an *empty* `future` object that does not refer to
|
| 65 |
-
a shared state.
|
| 66 |
-
|
| 67 |
-
*Postconditions:* `valid() == false`.
|
| 68 |
-
|
| 69 |
-
``` cpp
|
| 70 |
-
future(future&& rhs) noexcept;
|
| 71 |
-
```
|
| 72 |
-
|
| 73 |
-
*Effects:* Move constructs a `future` object that refers to the shared
|
| 74 |
-
state that was originally referred to by `rhs` (if any).
|
| 75 |
-
|
| 76 |
-
*Postconditions:*
|
| 77 |
-
|
| 78 |
-
- `valid()` returns the same value as `rhs.valid()` prior to the
|
| 79 |
-
constructor invocation.
|
| 80 |
-
- `rhs.valid() == false`.
|
| 81 |
-
|
| 82 |
-
``` cpp
|
| 83 |
-
~future();
|
| 84 |
-
```
|
| 85 |
-
|
| 86 |
-
*Effects:*
|
| 87 |
-
|
| 88 |
-
- Releases any shared state ([[futures.state]]);
|
| 89 |
-
- destroys `*this`.
|
| 90 |
-
|
| 91 |
-
``` cpp
|
| 92 |
-
future& operator=(future&& rhs) noexcept;
|
| 93 |
-
```
|
| 94 |
-
|
| 95 |
-
*Effects:*
|
| 96 |
-
|
| 97 |
-
- Releases any shared state ([[futures.state]]).
|
| 98 |
-
- move assigns the contents of `rhs` to `*this`.
|
| 99 |
-
|
| 100 |
-
*Postconditions:*
|
| 101 |
-
|
| 102 |
-
- `valid()` returns the same value as `rhs.valid()` prior to the
|
| 103 |
-
assignment.
|
| 104 |
-
- `rhs.valid() == false`.
|
| 105 |
-
|
| 106 |
-
``` cpp
|
| 107 |
-
shared_future<R> share() noexcept;
|
| 108 |
-
```
|
| 109 |
-
|
| 110 |
-
*Returns:* `shared_future<R>(std::move(*this))`.
|
| 111 |
-
|
| 112 |
-
*Postconditions:* `valid() == false`.
|
| 113 |
-
|
| 114 |
-
``` cpp
|
| 115 |
-
R future::get();
|
| 116 |
-
R& future<R&>::get();
|
| 117 |
-
void future<void>::get();
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
[*Note 1*: As described above, the template and its two required
|
| 121 |
-
specializations differ only in the return type and return value of the
|
| 122 |
-
member function `get`. — *end note*]
|
| 123 |
-
|
| 124 |
-
*Effects:*
|
| 125 |
-
|
| 126 |
-
- `wait()`s until the shared state is ready, then retrieves the value
|
| 127 |
-
stored in the shared state;
|
| 128 |
-
- releases any shared state ([[futures.state]]).
|
| 129 |
-
|
| 130 |
-
*Returns:*
|
| 131 |
-
|
| 132 |
-
- `future::get()` returns the value `v` stored in the object’s shared
|
| 133 |
-
state as `std::move(v)`.
|
| 134 |
-
- `future<R&>::get()` returns the reference stored as value in the
|
| 135 |
-
object’s shared state.
|
| 136 |
-
- `future<void>::get()` returns nothing.
|
| 137 |
-
|
| 138 |
-
*Throws:* the stored exception, if an exception was stored in the shared
|
| 139 |
-
state.
|
| 140 |
-
|
| 141 |
-
*Postconditions:* `valid() == false`.
|
| 142 |
-
|
| 143 |
-
``` cpp
|
| 144 |
-
bool valid() const noexcept;
|
| 145 |
-
```
|
| 146 |
-
|
| 147 |
-
*Returns:* `true` only if `*this` refers to a shared state.
|
| 148 |
-
|
| 149 |
-
``` cpp
|
| 150 |
-
void wait() const;
|
| 151 |
-
```
|
| 152 |
-
|
| 153 |
-
*Effects:* Blocks until the shared state is ready.
|
| 154 |
-
|
| 155 |
-
``` cpp
|
| 156 |
-
template <class Rep, class Period>
|
| 157 |
-
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
| 158 |
-
```
|
| 159 |
-
|
| 160 |
-
*Effects:* None if the shared state contains a deferred
|
| 161 |
-
function ([[futures.async]]), otherwise blocks until the shared state
|
| 162 |
-
is ready or until the relative timeout ([[thread.req.timing]])
|
| 163 |
-
specified by `rel_time` has expired.
|
| 164 |
-
|
| 165 |
-
*Returns:*
|
| 166 |
-
|
| 167 |
-
- `future_status::deferred` if the shared state contains a deferred
|
| 168 |
-
function.
|
| 169 |
-
- `future_status::ready` if the shared state is ready.
|
| 170 |
-
- `future_status::timeout` if the function is returning because the
|
| 171 |
-
relative timeout ([[thread.req.timing]]) specified by `rel_time` has
|
| 172 |
-
expired.
|
| 173 |
-
|
| 174 |
-
*Throws:* timeout-related exceptions ([[thread.req.timing]]).
|
| 175 |
-
|
| 176 |
-
``` cpp
|
| 177 |
-
template <class Clock, class Duration>
|
| 178 |
-
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
| 179 |
-
```
|
| 180 |
-
|
| 181 |
-
*Effects:* None if the shared state contains a deferred
|
| 182 |
-
function ([[futures.async]]), otherwise blocks until the shared state
|
| 183 |
-
is ready or until the absolute timeout ([[thread.req.timing]])
|
| 184 |
-
specified by `abs_time` has expired.
|
| 185 |
-
|
| 186 |
-
*Returns:*
|
| 187 |
-
|
| 188 |
-
- `future_status::deferred` if the shared state contains a deferred
|
| 189 |
-
function.
|
| 190 |
-
- `future_status::ready` if the shared state is ready.
|
| 191 |
-
- `future_status::timeout` if the function is returning because the
|
| 192 |
-
absolute timeout ([[thread.req.timing]]) specified by `abs_time` has
|
| 193 |
-
expired.
|
| 194 |
-
|
| 195 |
-
*Throws:* timeout-related exceptions ([[thread.req.timing]]).
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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