1 // Copyright (C) 2014 Vicente Botet
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #define BOOST_THREAD_VERSION 4
8 // BoostFutureTest.cpp : Defines the entry point for the console application.
13 // boost version 1.60.0
14 // has the following set.
15 #define BOOST_THREAD_VERSION 4
16 // #define BOOST_THREAD_PROVIDES_EXECUTORS
18 #include <boost/thread/future.hpp>
23 #if __cplusplus >= 201103L
27 boost::promise<void> promise1;
28 boost::promise<void> promise2;
30 auto future1 = promise1.get_future();
32 auto waitFuture = future1.then([&tmpValue, &promise2](boost::future<void> future){
33 assert(future.is_ready()); // this works correctly and is ready.
35 auto fut = boost::async(boost::launch::async, [&promise2, &tmpValue](){
36 boost::this_thread::sleep_for(boost::chrono::seconds(1));
39 std::cout << "Step 2 "<< std::endl; // should print 1 but prints 0
41 std::cout << "Step 1 "<< std::endl; // should print 1 but prints 0
43 return promise2.get_future();
45 }).then([&value, &tmpValue](boost::future<boost::future<void>> future){
46 //}).then([&value, &tmpValue](boost::future<void> future){
47 // error: no matching function for call to ‘boost::future<boost::future<void> >::then(main()::<lambda(boost::future<void>)>)’
50 assert(future.is_ready()); // this doesn't work correctly and is not ready.
60 std::cout << "value = " << value << std::endl; // should print 1 but prints 0