libcoro  1.0
Coroutine support library for C++20
Public Member Functions | Friends | List of all members
coro::future_variant< Types > Class Template Reference

makes a variant future - multiple futures shares single space More...

#include <future_variant.h>

Public Member Functions

template<std::invocable<> Fn>
auto & operator<< (Fn &&fn)
 Redirect return value to future object. More...
 
void reset ()
 Delete any underlying future and return object into uninitalized state. More...
 
template<typename promise_type >
auto & get_promise (promise_type &p)
 Initialize underlying future and retrieves promise. More...
 
template<typename fut_type = void>
_details::future_variant_getter< fut_type, future_variantget ()
 Retrieve result of the future. More...
 
awaiter operator co_await ()
 Helps to co_wait on future regardless on which variant is active. More...
 
void wait ()
 Helps to wait on future regardless on which variant is active. More...
 

Friends

template<typename fut_type , typename ... X>
fut_type & get (future_variant< X... > &me)
 Retrieve reference to future - if it is current variant. More...
 
template<typename fut_type , typename ... X>
const fut_type & get (const future_variant< X... > &me)
 Retrieve reference to future - if it is current variant. More...
 
template<typename fut_type , typename ... X>
bool holds_alternative (future_variant< X... > &me)
 tests whether holds given variant More...
 

Detailed Description

template<typename ... Types>
class coro::future_variant< Types >

makes a variant future - multiple futures shares single space

It is similar as variant over futures, but it is much easier to use

Template Parameters
Typeslist of types hosted by this object

You can use operator << to redirect result to this future object. This operator returns a reference to a selected future, which can be used to chain a callback

future_variant<int, double> fut;
fut << [&]{return async_double();} >> [&]{
auto res = fut.get();
}

;

You can use get_promise to initialize future and get promise at the same time

future_variant<int, double> fut;
promise<double> prom;
auto &f = fut.get_promise(prom);
// f = future<double>;
Note
you can switch future type only when underlying future is resolved

Definition at line 106 of file future_variant.h.


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