tmp/tmpq7q1nl2z/{from.md → to.md}
RENAMED
|
@@ -1,215 +0,0 @@
|
|
| 1 |
-
### Class template `shared_future` <a id="futures.shared_future">[[futures.shared_future]]</a>
|
| 2 |
-
|
| 3 |
-
The class template `shared_future` defines a type for asynchronous
|
| 4 |
-
return objects which may share their shared state with other
|
| 5 |
-
asynchronous return objects. A default-constructed `shared_future`
|
| 6 |
-
object has no shared state. A `shared_future` object with shared state
|
| 7 |
-
can be created by conversion from a `future` object and shares its
|
| 8 |
-
shared state with the original asynchronous provider (
|
| 9 |
-
[[futures.state]]) of the shared state. The result (value or exception)
|
| 10 |
-
of a `shared_future` object can be set by calling a respective function
|
| 11 |
-
on an object that shares the same shared state.
|
| 12 |
-
|
| 13 |
-
[*Note 1*: Member functions of `shared_future` do not synchronize with
|
| 14 |
-
themselves, but they synchronize with the shared state. — *end note*]
|
| 15 |
-
|
| 16 |
-
The effect of calling any member function other than the destructor, the
|
| 17 |
-
move-assignment operator, the copy-assignment operator, or `valid()` on
|
| 18 |
-
a `shared_future` object for which `valid() == false` is undefined.
|
| 19 |
-
|
| 20 |
-
[*Note 2*: It is valid to copy or move from a `shared_future` object
|
| 21 |
-
for which `valid()` is `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 shared_future {
|
| 31 |
-
public:
|
| 32 |
-
shared_future() noexcept;
|
| 33 |
-
shared_future(const shared_future& rhs) noexcept;
|
| 34 |
-
shared_future(future<R>&&) noexcept;
|
| 35 |
-
shared_future(shared_future&& rhs) noexcept;
|
| 36 |
-
~shared_future();
|
| 37 |
-
shared_future& operator=(const shared_future& rhs) noexcept;
|
| 38 |
-
shared_future& operator=(shared_future&& rhs) noexcept;
|
| 39 |
-
|
| 40 |
-
// retrieving the value
|
| 41 |
-
see below get() const;
|
| 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 `shared_future` and two
|
| 56 |
-
specializations, `shared_future<R&>` and `shared_future<void>`. These
|
| 57 |
-
differ only in the return type and return value of the member function
|
| 58 |
-
`get`, as set out in its description, below.
|
| 59 |
-
|
| 60 |
-
``` cpp
|
| 61 |
-
shared_future() noexcept;
|
| 62 |
-
```
|
| 63 |
-
|
| 64 |
-
*Effects:* Constructs an *empty* `shared_future` object that does not
|
| 65 |
-
refer to a shared state.
|
| 66 |
-
|
| 67 |
-
*Postconditions:* `valid() == false`.
|
| 68 |
-
|
| 69 |
-
``` cpp
|
| 70 |
-
shared_future(const shared_future& rhs) noexcept;
|
| 71 |
-
```
|
| 72 |
-
|
| 73 |
-
*Effects:* Constructs a `shared_future` object that refers to the same
|
| 74 |
-
shared state as `rhs` (if any).
|
| 75 |
-
|
| 76 |
-
*Postconditions:* `valid()` returns the same value as `rhs.valid()`.
|
| 77 |
-
|
| 78 |
-
``` cpp
|
| 79 |
-
shared_future(future<R>&& rhs) noexcept;
|
| 80 |
-
shared_future(shared_future&& rhs) noexcept;
|
| 81 |
-
```
|
| 82 |
-
|
| 83 |
-
*Effects:* Move constructs a `shared_future` object that refers to the
|
| 84 |
-
shared state that was originally referred to by `rhs` (if any).
|
| 85 |
-
|
| 86 |
-
*Postconditions:*
|
| 87 |
-
|
| 88 |
-
- `valid()` returns the same value as `rhs.valid()` returned prior to
|
| 89 |
-
the constructor invocation.
|
| 90 |
-
- `rhs.valid() == false`.
|
| 91 |
-
|
| 92 |
-
``` cpp
|
| 93 |
-
~shared_future();
|
| 94 |
-
```
|
| 95 |
-
|
| 96 |
-
*Effects:*
|
| 97 |
-
|
| 98 |
-
- Releases any shared state ([[futures.state]]);
|
| 99 |
-
- destroys `*this`.
|
| 100 |
-
|
| 101 |
-
``` cpp
|
| 102 |
-
shared_future& operator=(shared_future&& rhs) noexcept;
|
| 103 |
-
```
|
| 104 |
-
|
| 105 |
-
*Effects:*
|
| 106 |
-
|
| 107 |
-
- Releases any shared state ([[futures.state]]);
|
| 108 |
-
- move assigns the contents of `rhs` to `*this`.
|
| 109 |
-
|
| 110 |
-
*Postconditions:*
|
| 111 |
-
|
| 112 |
-
- `valid()` returns the same value as `rhs.valid()` returned prior to
|
| 113 |
-
the assignment.
|
| 114 |
-
- `rhs.valid() == false`.
|
| 115 |
-
|
| 116 |
-
``` cpp
|
| 117 |
-
shared_future& operator=(const shared_future& rhs) noexcept;
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
*Effects:*
|
| 121 |
-
|
| 122 |
-
- Releases any shared state ([[futures.state]]);
|
| 123 |
-
- assigns the contents of `rhs` to `*this`. \[*Note 4*: As a result,
|
| 124 |
-
`*this` refers to the same shared state as `rhs` (if
|
| 125 |
-
any). — *end note*]
|
| 126 |
-
|
| 127 |
-
*Postconditions:* `valid() == rhs.valid()`.
|
| 128 |
-
|
| 129 |
-
``` cpp
|
| 130 |
-
const R& shared_future::get() const;
|
| 131 |
-
R& shared_future<R&>::get() const;
|
| 132 |
-
void shared_future<void>::get() const;
|
| 133 |
-
```
|
| 134 |
-
|
| 135 |
-
[*Note 1*: As described above, the template and its two required
|
| 136 |
-
specializations differ only in the return type and return value of the
|
| 137 |
-
member function `get`. — *end note*]
|
| 138 |
-
|
| 139 |
-
[*Note 2*: Access to a value object stored in the shared state is
|
| 140 |
-
unsynchronized, so programmers should apply only those operations on `R`
|
| 141 |
-
that do not introduce a data
|
| 142 |
-
race ([[intro.multithread]]). — *end note*]
|
| 143 |
-
|
| 144 |
-
*Effects:* `wait()`s until the shared state is ready, then retrieves the
|
| 145 |
-
value stored in the shared state.
|
| 146 |
-
|
| 147 |
-
*Returns:*
|
| 148 |
-
|
| 149 |
-
- `shared_future::get()` returns a const reference to the value stored
|
| 150 |
-
in the object’s shared state. \[*Note 5*: Access through that
|
| 151 |
-
reference after the shared state has been destroyed produces undefined
|
| 152 |
-
behavior; this can be avoided by not storing the reference in any
|
| 153 |
-
storage with a greater lifetime than the `shared_future` object that
|
| 154 |
-
returned the reference. — *end note*]
|
| 155 |
-
- `shared_future<R&>::get()` returns the reference stored as value in
|
| 156 |
-
the object’s shared state.
|
| 157 |
-
- `shared_future<void>::get()` returns nothing.
|
| 158 |
-
|
| 159 |
-
*Throws:* the stored exception, if an exception was stored in the shared
|
| 160 |
-
state.
|
| 161 |
-
|
| 162 |
-
``` cpp
|
| 163 |
-
bool valid() const noexcept;
|
| 164 |
-
```
|
| 165 |
-
|
| 166 |
-
*Returns:* `true` only if `*this` refers to a shared state.
|
| 167 |
-
|
| 168 |
-
``` cpp
|
| 169 |
-
void wait() const;
|
| 170 |
-
```
|
| 171 |
-
|
| 172 |
-
*Effects:* Blocks until the shared state is ready.
|
| 173 |
-
|
| 174 |
-
``` cpp
|
| 175 |
-
template <class Rep, class Period>
|
| 176 |
-
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
| 177 |
-
```
|
| 178 |
-
|
| 179 |
-
*Effects:* None if the shared state contains a deferred
|
| 180 |
-
function ([[futures.async]]), otherwise blocks until the shared state
|
| 181 |
-
is ready or until the relative timeout ([[thread.req.timing]])
|
| 182 |
-
specified by `rel_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 |
-
relative timeout ([[thread.req.timing]]) specified by `rel_time` has
|
| 191 |
-
expired.
|
| 192 |
-
|
| 193 |
-
*Throws:* timeout-related exceptions ([[thread.req.timing]]).
|
| 194 |
-
|
| 195 |
-
``` cpp
|
| 196 |
-
template <class Clock, class Duration>
|
| 197 |
-
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
| 198 |
-
```
|
| 199 |
-
|
| 200 |
-
*Effects:* None if the shared state contains a deferred
|
| 201 |
-
function ([[futures.async]]), otherwise blocks until the shared state
|
| 202 |
-
is ready or until the absolute timeout ([[thread.req.timing]])
|
| 203 |
-
specified by `abs_time` has expired.
|
| 204 |
-
|
| 205 |
-
*Returns:*
|
| 206 |
-
|
| 207 |
-
- `future_status::deferred` if the shared state contains a deferred
|
| 208 |
-
function.
|
| 209 |
-
- `future_status::ready` if the shared state is ready.
|
| 210 |
-
- `future_status::timeout` if the function is returning because the
|
| 211 |
-
absolute timeout ([[thread.req.timing]]) specified by `abs_time` has
|
| 212 |
-
expired.
|
| 213 |
-
|
| 214 |
-
*Throws:* timeout-related exceptions ([[thread.req.timing]]).
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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