set_rvalue_at_thread_exit_pass.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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,2014 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::set_value_at_thread_exit(R&& p);
  16. #define BOOST_THREAD_VERSION 3
  17. #include <boost/thread/future.hpp>
  18. #include <boost/detail/lightweight_test.hpp>
  19. #include <boost/thread/detail/memory.hpp>
  20. #include <boost/thread/csbl/memory/unique_ptr.hpp>
  21. boost::promise<boost::csbl::unique_ptr<int> > p;
  22. boost::promise<boost::csbl::unique_ptr<int> > p2;
  23. void func()
  24. {
  25. boost::csbl::unique_ptr<int> uptr(new int(5));
  26. p.set_value_at_thread_exit(boost::move(uptr));
  27. }
  28. void func2()
  29. {
  30. p2.set_value_at_thread_exit(boost::csbl::make_unique<int>(5));
  31. }
  32. int main()
  33. {
  34. {
  35. boost::future<boost::csbl::unique_ptr<int> > f = p.get_future();
  36. boost::thread(func).detach();
  37. BOOST_TEST(*f.get() == 5);
  38. }
  39. {
  40. boost::future<boost::csbl::unique_ptr<int> > f = p2.get_future();
  41. boost::thread(func2).detach();
  42. BOOST_TEST(*f.get() == 5);
  43. }
  44. return boost::report_errors();
  45. }