future<T, enable_if_copyable<T>> |
Defined in
<concurrency/future.hpp> |
An alternative future
implementation with support for continuations, splits, and joins
Types
Type | Definition | Notes |
---|---|---|
T |
result type |
stlab::future
differs from std::future
in several ways:
- This future is copyable, so there is no need for a
std::shared_future
. - If this future is only used as an rvalue and there are no copies, then the value (either returned by
get_try
or through a continuation) will be moved. - Multiple continuations - forming a split - may be attached to a single future with
then()
.then()
is declaredconst
since it does not mutate the result object of the future. The continuation is called with the value type, not the future. - A sink argument to a continuation should take the argument by value and move the object as needed.
- If the continuation reads the argument it should take it by
const&
. - Behavior of modifying the argument through a non-const reference is undefined (may be a compilation error).
- If the last copy of a future destructs, the associated task and any held futures for the task arguments are released and the associated packaged_task will become a no-op if called.
- There are no
wait()
orget()
functions. Instead, there is aget_try()
which returns anoptional<T>
(or ifT
isvoid
, the result is abool
withtrue
indicating the associated task has executed.
It is necessary to specialize the template stlab::smart_test
if type T is e.g. a container of a non copyable type like std::vector<std::unique_ptr<>>
so that the the library can correctly dispatch for move-only types internally. This is unfortunately necessary because of a defect in the C++ standard. (The trait std::is_copy_constructible<> does not return the correct results in such a case.) For further details see in ./test/traits_test.cpp.
To Do
- Error handling