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 await can type s<<t>> (“s holding t”) meets following conditions:

  1. s has parameter-less function get either produce value of type t, or throw exception.
  2. s has function then accepting single-parameter function object taking parameter s<<t>>, s<<t>>&, or const s<<t>>. once passed then, value held parameter must available retrieval call get.
  3. optionally, if s<<t>> has bool-returning function is_ready() indicating whether value held, implementation of await can made more efficient.

currently, discussion still open. generalization accepted, resumable function able return boost::future. otherwise, limited std::future , std::shared_future.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -