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