get_future_pass.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // Copyright (C) 2011 Vicente J. Botet Escriba
  10. //
  11. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  12. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  13. // <boost/thread/future.hpp>
  14. // class promise<R>
  15. // future<R> get_future();
  16. #define BOOST_THREAD_VERSION 3
  17. #include <boost/thread/future.hpp>
  18. #include <boost/detail/lightweight_test.hpp>
  19. int main()
  20. {
  21. {
  22. boost::promise<double> p;
  23. boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  24. p.set_value(105.5);
  25. BOOST_TEST(f.get() == 105.5);
  26. }
  27. {
  28. boost::promise<double> p;
  29. boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  30. try
  31. {
  32. f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  33. BOOST_TEST(false);
  34. }
  35. catch (const boost::future_error& e)
  36. {
  37. BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::future_already_retrieved));
  38. }
  39. }
  40. {
  41. boost::promise<double> p;
  42. boost::promise<double> p0 = boost::move(p);
  43. try
  44. {
  45. boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  46. BOOST_TEST(false);
  47. }
  48. catch (const boost::future_error& e)
  49. {
  50. BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
  51. }
  52. }
  53. return boost::report_errors();
  54. }