boost::future and when_all => compile error "call to deleted constructor"
Hello,
I am trying to use boost::future with continuations, in particular
when_all/when_any.
I am using Boost trunk from GitHub (since only that has when_all etc).
This is what I want to compile:
===
#include <iostream>
#define BOOST_THREAD_PROVIDES_FUTURE
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY
#include
Le 26/03/14 14:48, Tobias Oberstein a écrit :
Hello,
Hi,
I am trying to use boost::future with continuations, in particular when_all/when_any.
I am using Boost trunk from GitHub (since only that has when_all etc).
You will be able to have it for Boost 1.56 (it is already on master)
This is what I want to compile:
===
#include <iostream>
#define BOOST_THREAD_PROVIDES_FUTURE #define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION #define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY #include
using namespace boost;
int main() { future<int> f1 = async([]() { return 1; }); future<int> f2 = async([]() { return 2; });
auto f3 = when_all(f1, f2);
f3.then([](decltype(f3)) { std::cout << "done" << std::endl; });
f3.get(); }
Am I doing it wrong?
there are two errors (1) You need to move the futures (2) You can not use then() on a future and next try to get the value. You need to store the result of then on another future. int main() { future<int> f1 = async([]() { return 1;}); future<int> f2 = async([]() { return 2;}); auto f3 = when_all(boost::move(f1), boost::move(f2)); (1) auto f4 = f3.then([](decltype(f3)) (2) { std::cout << "done" << std::endl; }); f4.get(); (2) } Best, Vicente
Hi Vicente,
I am using Boost trunk from GitHub (since only that has when_all etc).
You will be able to have it for Boost 1.56 (it is already on master)
This is awesome! I am coming back to C++ after a couple of years .. and the improvements are great. FWIW, I am implementing WAMP (http://wamp.ws/), a messaging protocol that provides RPC and PubSub, in C++11. The nifty thing is, I can talk over stdio to a WAMP router (which spawns the C++ program), and using "futures" and continuations, it seems I'll be able to get away without any threads _and_ without (necessarily) ASIO. I got "call" and "publish" already working https://github.com/tavendo/AutobahnCpp/blob/master/test/test7.cpp I am doing my own "poor man's" event loop on std::cin (#L118) .. but it should be pluggable onto ASIO in the end as well. Now I am tackling "register" (being called) and "subscribe" (receiving events).
there are two errors (1) You need to move the futures (2) You can not use then() on a future and next try to get the value. You need to store the result of then on another future.
Thanks a bunch! I understand better now. In the meantime, I also got some feedback on StackOverflow .. basically stating the same. And it works for me now. http://stackoverflow.com/questions/22664296/using-boostfuture-with-continuat... Thanks again for helping and the great work!! I am looking forward to 1.56 .. Cheers, /Tobias
participants (2)
-
Tobias Oberstein
-
Vicente J. Botet Escriba