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 
10 // Copyright (C) 2011,2014 Vicente J. Botet Escriba
11 //
12 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
13 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
14 
15 // <boost/thread/future.hpp>
16 
17 // class promise<R>
18 
19 // void promise::set_value_at_thread_exit(R&& p);
20 
21 #define BOOST_THREAD_VERSION 3
22 
23 #include <boost/thread/future.hpp>
24 #include <boost/detail/lightweight_test.hpp>
25 #include <boost/thread/detail/memory.hpp>
26 #include <boost/thread/csbl/memory/unique_ptr.hpp>
27 
28 boost::promise<boost::csbl::unique_ptr<int> > p;
29 boost::promise<boost::csbl::unique_ptr<int> > p2;
func()30 void func()
31 {
32   boost::csbl::unique_ptr<int> uptr(new int(5));
33   p.set_value_at_thread_exit(boost::move(uptr));
34 }
func2()35 void func2()
36 {
37   p2.set_value_at_thread_exit(boost::csbl::make_unique<int>(5));
38 }
39 
main()40 int main()
41 {
42   {
43     boost::future<boost::csbl::unique_ptr<int> > f = p.get_future();
44     boost::thread(func).detach();
45     BOOST_TEST(*f.get() == 5);
46   }
47   {
48     boost::future<boost::csbl::unique_ptr<int> > f = p2.get_future();
49     boost::thread(func2).detach();
50     BOOST_TEST(*f.get() == 5);
51   }
52 
53   return boost::report_errors();
54 }
55 
56