test_9711.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_PROVIDES_FUTURE
  6. #define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
  7. #include <boost/config.hpp>
  8. #if ! defined BOOST_NO_CXX11_DECLTYPE
  9. #define BOOST_RESULT_OF_USE_DECLTYPE
  10. #endif
  11. #include <boost/thread/future.hpp>
  12. int main()
  13. {
  14. #if ! defined BOOST_NO_CXX11_LAMBDAS && ! (defined BOOST_MSVC && _MSC_VER < 1700)
  15. boost::promise<int> prom;
  16. boost::future<int> futr = prom.get_future();
  17. int callCount = 0;
  18. boost::future<void> futr2 = futr.then(boost::launch::deferred,
  19. [&] (boost::future<int> f) {
  20. callCount++;
  21. assert(f.valid());
  22. assert(f.is_ready());
  23. assert(17 == f.get());
  24. });
  25. assert(futr2.valid());
  26. assert(!futr2.is_ready());
  27. assert(0 == callCount);
  28. prom.set_value(17);
  29. assert(0 == callCount);
  30. futr2.get();
  31. assert(1 == callCount);
  32. #endif
  33. return 0;
  34. }