stlab 3.0.0
Modern, modular C++ algorithms, data structures, and concurrency primitives
Loading...
Searching...
No Matches
stlab::future< T, enable_if_copyable< void_to_monostate_t< T > > > Class Template Reference

Consumer side of a one-shot result (copyable T). More...

#include <future.hpp>

Public Types

using result_type
 The type of the value this future holds.

Public Member Functions

 future (const future &)=default
 future (future &&) noexcept=default
auto operator= (const future &) -> future &=default
auto operator= (future &&) noexcept -> future &=default
void swap (future &x) noexcept
 Exchanges the shared state with x.
auto valid () const -> bool
 True if this future has an associated shared state.
template<class F>
auto then (F &&f) const &
 Returns a future that completes with the result of f applied to this future's value (default executor).
Pipe operators (<tt>operator|</tt>, <tt>operator^</tt>)

operator| forwards to then (including executor_task_pair); operator^ forwards to recover (value-based error handling—use recover/^). Overloads mirror the matching then / recover overloads (lvalue vs rvalue, default vs explicit executor).

template<class F>
auto operator| (F &&f) const &
 Pipe operator: same as then(f).
template<class E, class F>
auto then (E &&executor, F &&f) const &
 Returns a future that completes with the result of f on executor applied to this future's value.
template<class F>
auto operator| (executor_task_pair< F > etp) const &
 Pipe operator: same as then(etp.executor(), etp.task()).
template<class F>
auto then (F &&f) &&
 Returns a future that completes with the result of f applied to this future's value (default executor). Rvalue overload; consumes *this.
template<class F>
auto operator| (F &&f) &&
 Pipe operator: same as then(f). Rvalue overload; consumes *this.
template<class E, class F>
auto then (E &&executor, F &&f) &&
 Returns a future that completes with the result of f on executor applied to this future's value. Rvalue overload; consumes *this.
template<class F>
auto operator| (executor_task_pair< F > etp) &&
 Pipe operator: same as then(etp.executor(), etp.task()). Rvalue overload; consumes *this.
template<class F>
auto recover (F &&f) const &
 Returns a future that completes with the result of f given this future (possibly in error state); default executor.
template<class F>
auto operator^ (F &&f) const &
 Pipe operator: same as recover(f).
template<class E, class F>
auto recover (E &&executor, F &&f) const &
 Returns a future that completes with the result of f given this future, run on executor.
template<class F>
auto operator^ (executor_task_pair< F > etp) const &
 Pipe operator: same as recover(etp.executor(), etp.task()).
template<class F>
auto recover (F &&f) &&
 Returns a future that completes with the result of f given this future (possibly in error state); default executor. Rvalue overload; consumes *this.
template<class F>
auto operator^ (F &&f) &&
 Pipe operator: same as recover(f). Rvalue overload; consumes *this.
template<class E, class F>
auto recover (E &&executor, F &&f) &&
 Returns a future that completes with the result of f given this future, run on executor. Rvalue overload; consumes *this.
template<class F>
auto operator^ (executor_task_pair< F > etp) &&
 Pipe operator: same as recover(etp.executor(), etp.task()). Rvalue overload; consumes *this.
void detach () &&
 Drops this future without cancelling the associated task.
template<class F>
void detach (F &&f) &&
 When this future completes (value or exception), invokes f with it and does not propagate further.
template<class F>
void on_completion (F &&f)
 Invokes f immediately when this future completes (value or exception). Requires f is noexcept.
template<class E, class F>
void on_completion (E &&executor, F &&f)
 Invokes f when this future completes (value or exception), on executor. Requires f is noexcept.
void reset () noexcept
 Releases the shared state; valid() becomes false.
auto is_ready () const &-> bool
 True if the result or exception is available.
auto get_try () const &
 Returns the value if ready, or std::nullopt / false (for void) if not; rethrows if completed with exception.
auto get_try () &&
 Same as get_try() but may move the value when this is the only reference.
auto get_ready () const &
 Returns the value.
auto get_ready () &&
 Same as get_ready() but may move the value when this is the only reference.
auto exception () const &-> std::exception_ptr
 Returns the stored exception, or a null exception_ptr if the future completed with a value.

Detailed Description

template<class T>
class stlab::future< T, enable_if_copyable< void_to_monostate_t< T > > >

Consumer side of a one-shot result (copyable T).

Copyable futures support multiple continuations (then, recover, |, ^) from the same object. Use get_ready() when is_ready(); otherwise get_try() returns std::optional<T> (or bool for void). Rvalue get_try()/get_ready() may move the value when this is the only outstanding reference.

Member Function Documentation

◆ exception()

template<class T>
auto stlab::future< T, enable_if_copyable< void_to_monostate_t< T > > >::exception ( ) const & -> std::exception_ptr
inlinenodiscard

Returns the stored exception, or a null exception_ptr if the future completed with a value.

Precondition
is_ready()

◆ get_ready()

template<class T>
auto stlab::future< T, enable_if_copyable< void_to_monostate_t< T > > >::get_ready ( ) const &
inlinenodiscard

Returns the value.

Precondition
is_ready(). Rethrows the stored exception if the future failed.

The documentation for this class was generated from the following file: