c++ - C++17 resumable/await : Can it also be used with boost::future? -
in c++17, there's nice future c#'s await.
std::future<int> get_answer() { return std::async(std::launch::async, [] { return 42; }); } std::future<void> do_something() resumable { // ... int = await get_answer(); // ... } but wonder whether boost::future can used or not:
boost::future<int> get_answer() { return boost::async(boost::launch::async, [] { return 42; }); } boost::future<void> do_something() resumable { // ... int = await get_answer(); // ... }
the paper linked (n3722) explicitly says std::future<t> , std::shared_future<t> accepted return type resumable function:
the return type of resumable function must future or shared_future . restrictions on t defined std::future, not proposal, t must copyable or movable type, or ‘void.’ must possible construct variable of t without argument; is, has have accessible (implicit or explic it) default constructor if of class type.
however, section 4 of proposal (generalization) proposes lift return type restriction. returned type should type following restrictions:
the operand of unary operator
awaitcan types<<t>>(“s holding t”) meets following conditions:
- s has parameter-less function
geteither produce value of type t, or throw exception.- s has function
thenaccepting single-parameter function object taking parameters<<t>>,s<<t>>&, orconst s<<t>>. once passedthen, value held parameter must available retrieval callget.- optionally, if
s<<t>>hasbool-returning functionis_ready()indicating whether value held, implementation ofawaitcan made more efficient.
currently, discussion still open. generalization accepted, resumable function able return boost::future. otherwise, limited std::future , std::shared_future.
Comments
Post a Comment