set_value_void_pass.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // void promise<void>::set_value();
  16. #define BOOST_THREAD_VERSION 3
  17. #include <boost/thread/future.hpp>
  18. #include <boost/detail/lightweight_test.hpp>
  19. #include <boost/static_assert.hpp>
  20. struct A
  21. {
  22. A()
  23. {
  24. }
  25. A(const A&)
  26. {
  27. throw 10;
  28. }
  29. };
  30. int main()
  31. {
  32. {
  33. typedef void T;
  34. boost::promise<T> p;
  35. boost::future<T> f = p.get_future();
  36. p.set_value();
  37. f.get();
  38. try
  39. {
  40. p.set_value();
  41. BOOST_TEST(false);
  42. }
  43. catch (const boost::future_error& e)
  44. {
  45. BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
  46. }
  47. catch (...)
  48. {
  49. BOOST_TEST(false);
  50. }
  51. }
  52. {
  53. typedef void T;
  54. boost::promise<T> p;
  55. boost::future<T> f = p.get_future();
  56. p.set_value_deferred();
  57. p.notify_deferred();
  58. f.get();
  59. try
  60. {
  61. p.set_value();
  62. BOOST_TEST(false);
  63. }
  64. catch (const boost::future_error& e)
  65. {
  66. BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
  67. }
  68. catch (...)
  69. {
  70. BOOST_TEST(false);
  71. }
  72. }
  73. return boost::report_errors();
  74. }