1 // Copyright (C) 2010 Vicente Botet 2 // 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) 5 6 #define BOOST_THREAD_VERSION 4 7 8 #include <cassert> 9 #include <vector> 10 #include <future> 11 #include <functional> 12 #include <boost/thread/future.hpp> 13 14 15 int TRUC = 42; main()16int main() 17 { 18 std::vector< std::function<void()> > work_queue; 19 20 auto do_some_work = [&]()-> boost::future<int*> 21 { 22 auto promise = std::make_shared<boost::promise<int*>>(); 23 #if 0 24 work_queue.push_back( [=] 25 { 26 promise->set_value( &TRUC ); 27 }); 28 #else 29 auto inner = [=]() 30 { 31 promise->set_value( &TRUC ); 32 }; 33 work_queue.push_back(inner); 34 35 #endif 36 37 return promise->get_future(); 38 39 }; 40 41 auto ft_value = do_some_work(); 42 43 while( !work_queue.empty() ) 44 { 45 #if 0 46 auto work = work_queue.back(); 47 #else 48 std::function<void()> work; 49 work = work_queue.back(); 50 #endif 51 work_queue.pop_back(); 52 work(); 53 } 54 55 auto value = ft_value.get(); 56 assert( value == &TRUC ); 57 return 0; 58 } 59 60 61