future implementation with support for continuations, splits, and joins
stlab::future differs from
std::future in several ways:
- This future is copyable, so there is no need for a
- If this future is only used as an rvalue and there are no copies, then the value (either returned by
get_tryor through a continuation) will be moved.
- Multiple continuations - forming a split - may be attached to a single future with
constsince 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
- 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
get()functions. Instead, there is a
get_try()which returns an
void, the result is a
trueindicating 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.
- Error handling