diff --git a/example/make_future.cpp b/example/make_future.cpp index afaa13f9..025b4e5b 100644 --- a/example/make_future.cpp +++ b/example/make_future.cpp @@ -5,7 +5,7 @@ #include #ifndef BOOST_NO_CXX11_DECLTYPE_N3276 -#define BOOST_THREAD_NO_CXX11_DECLTYPE_N3276 +//#define BOOST_THREAD_NO_CXX11_DECLTYPE_N3276 #endif #if ! defined BOOST_NO_CXX11_DECLTYPE #define BOOST_RESULT_OF_USE_DECLTYPE @@ -53,8 +53,9 @@ boost::future compute(int x) boost::future compute_ref(int x) { - //int i = 0; - //if (x == 0) return boost::make_ready_future(i); This must not compile as the type is deduced as boost::future + static int i = 0; + //if (x == 0) return boost::make_ready_future(i); //This must not compile as the type is deduced as boost::future + if (x == 0) return boost::make_ready_no_decay_future(i); #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES if (x < 0) return boost::make_exceptional_future(std::logic_error("Error")); #else @@ -84,11 +85,11 @@ int main() for (int i=0; i< number_of_tests; i++) try { - { - std::cout << __FILE__ << " "<<__LINE__ << std::endl; - boost::future f = boost::async(boost::launch::async, p1); - std::cout << i << " "< f = boost::async(boost::launch::async, p1); +// std::cout << i << " "< f = compute_ref(0); std::cout << f.get() << std::endl; } - { - std::cout << __FILE__ << " "<< __LINE__ << std::endl; - boost::future f = compute(2); - std::cout << f.get() << std::endl; - } +// { +// std::cout << __FILE__ << " "<< __LINE__ << std::endl; +// boost::future f = compute(2); +// std::cout << f.get() << std::endl; +// } { std::cout << __FILE__ << " "<< __LINE__ << std::endl; boost::shared_future f = shared_compute(0); diff --git a/include/boost/thread/future.hpp b/include/boost/thread/future.hpp index 63e4604d..54c7966a 100644 --- a/include/boost/thread/future.hpp +++ b/include/boost/thread/future.hpp @@ -4076,6 +4076,15 @@ namespace boost return BOOST_THREAD_MAKE_RV_REF(p.get_future()); } + template + BOOST_THREAD_FUTURE make_ready_no_decay_future(T1 value) + { + typedef T future_value_type; + promise p; + p.set_value(value); + return BOOST_THREAD_MAKE_RV_REF(p.get_future()); + } + #if defined BOOST_THREAD_USES_MOVE inline BOOST_THREAD_FUTURE make_ready_future() {