This project is read-only.
1
Vote

Possible to expose asynchrony through cpplinq?

description

Hello,

I would like to do something like this, but I don't think the async/promise/future is possible with the forwarding going on (?)...
from(lines)
    >> select([](std::string const & l) { return std::async(game::try_parse, l); })
    >> for_each([&games](std::future<game*>& fg) { games.push_back(fg.get()); });
Where, 'lines' are a pre-selected std::string, and game::try_parse parses a game from the line. 'games' is a vector that will receive each game from it future.

I am receiving a compile error like this, which leads me to believe movability needs to be possible.
Error   1   error C2280: 'std::future<std::_Result_of<_Fty,const std::string &>::type>::future(const std::future<std::_Result_of<_Fty,const std::string &>::type> &)' : attempting to reference a deleted function  i:\source\spikes\player-game-scheduler-working\tools\cpplinq\cpplinq.hpp    360 1   game-scheduler
Thank you...

comments

mwpowellhtx wrote Jan 20, 2015 at 7:10 PM

Borrowing a page from Sutter and Stroustrup, sometimes a std algorithm is just a std algorithm. Or in this case, range based factory of threads (or futures, I suppose...).

marten_range wrote Jan 30, 2015 at 5:14 PM

If you try a rvalue reference in for_each does that make any difference.
from(lines)
    >> select([](std::string const & l) { return std::async(game::try_parse, l); })
    >> for_each([&games](std::future<game*>&& fg) { games.push_back(fg.get()); });

mwpowellhtx wrote Jan 30, 2015 at 6:56 PM

I will try that. Thank you.