dtor_pass.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 packaged_task<R>
  15. // ~packaged_task();
  16. //#define BOOST_THREAD_VERSION 3
  17. #define BOOST_THREAD_VERSION 4
  18. #include <boost/thread/future.hpp>
  19. #include <boost/thread/thread.hpp>
  20. #include <boost/detail/lightweight_test.hpp>
  21. #if BOOST_THREAD_VERSION == 4
  22. #define BOOST_THREAD_DETAIL_SIGNATURE double()
  23. #else
  24. #define BOOST_THREAD_DETAIL_SIGNATURE double
  25. #endif
  26. #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
  27. #if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
  28. #define BOOST_THREAD_DETAIL_SIGNATURE_2 double(int, char)
  29. #define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5 + 3 +'a'
  30. #else
  31. #define BOOST_THREAD_DETAIL_SIGNATURE_2 double()
  32. #define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
  33. #endif
  34. #else
  35. #define BOOST_THREAD_DETAIL_SIGNATURE_2 double
  36. #define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
  37. #endif
  38. class A
  39. {
  40. long data_;
  41. public:
  42. explicit A(long i) : data_(i) {}
  43. long operator()() const {return data_;}
  44. long operator()(long i, long j) const {return data_ + i + j;}
  45. };
  46. void func(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> )
  47. {
  48. }
  49. void func2(boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p)
  50. {
  51. #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
  52. p(3, 'a');
  53. #else
  54. p();
  55. #endif
  56. }
  57. int main()
  58. {
  59. {
  60. boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(A(5));
  61. boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  62. #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
  63. boost::thread(func, boost::move(p)).detach();
  64. #else
  65. boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE>* p2=new boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE>(boost::move(p));
  66. delete p2;
  67. #endif
  68. try
  69. {
  70. f.get();
  71. BOOST_TEST(false);
  72. }
  73. catch (const boost::future_error& e)
  74. {
  75. BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
  76. }
  77. }
  78. {
  79. std::cout << __LINE__ << std::endl;
  80. boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(A(5));
  81. boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  82. #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
  83. boost::thread(func2, boost::move(p)).detach();
  84. #else
  85. p();
  86. #endif
  87. std::cout << __LINE__ << std::endl;
  88. BOOST_TEST(f.get() == BOOST_THREAD_DETAIL_SIGNATURE_2_RES);
  89. std::cout << __LINE__ << std::endl;
  90. }
  91. return boost::report_errors();
  92. }