The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Madhusudhan Srikkanth (7) [Avatar] Offline
Hi Anthony,

You should make spawn_async function introduced in Page 111 (Listing 4.17) a variadic template to accept any number of arguments.

This is so because the code in Listing 4.23 and others assumes this is the case.

Here is a straightforward implementation:

template<typename Func, typename... Args>
auto spawn_async(Func&& func, Args&&... args)
    std::experimental::promise<std::result_of_t<Func(Args&&...)>> prom;
    auto res = prom.get_future();
    auto lambda = [p = std::move(prom), f=std::decay_t<Func>(func)](auto&&... a) mutable
                            catch (...) 
    std::thread t(std::move(lambda), std::forward<Args>(args)...);
    return res;                     

Madhusudhan Srikkanth