test_10963.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (C) 2014 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. #define BOOST_THREAD_VERSION 4
  6. #include <boost/config.hpp>
  7. #if ! defined BOOST_NO_CXX11_DECLTYPE
  8. #define BOOST_RESULT_OF_USE_DECLTYPE
  9. #endif
  10. #define BOOST_THREAD_PROVIDES_EXECUTORS
  11. #include <boost/thread/future.hpp>
  12. #include <boost/static_assert.hpp>
  13. #include <cassert>
  14. #include <boost/thread/executors/basic_thread_pool.hpp>
  15. struct TestCallback
  16. {
  17. typedef boost::future<void> result_type;
  18. result_type operator()(boost::future<void> future) const
  19. {
  20. assert(future.is_ready());
  21. future.get();
  22. return boost::make_ready_future();
  23. }
  24. result_type operator()(boost::future<boost::future<void> > future) const
  25. {
  26. assert(future.is_ready());
  27. future.get();
  28. return boost::make_ready_future();
  29. }
  30. };
  31. int main()
  32. {
  33. #if ! defined BOOST_NO_CXX11_DECLTYPE && ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS
  34. {
  35. boost::promise<void> test_promise;
  36. boost::future<void> test_future(test_promise.get_future());
  37. auto f1 = test_future.then(TestCallback());
  38. BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
  39. auto f2 = f1.then(TestCallback());
  40. BOOST_STATIC_ASSERT(std::is_same<decltype(f2), boost::future<boost::future<void> > >::value);
  41. }
  42. {
  43. boost::basic_thread_pool executor;
  44. boost::promise<void> test_promise;
  45. boost::future<void> test_future(test_promise.get_future());
  46. auto f1 = test_future.then(executor, TestCallback());
  47. BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
  48. auto f2 = f1.then(executor, TestCallback());
  49. BOOST_STATIC_ASSERT(std::is_same<decltype(f2), boost::future<boost::future<void> > >::value);
  50. }
  51. #endif
  52. return 0;
  53. }