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 // UNSUPPORTED: libcpp-has-no-threads
11 // UNSUPPORTED: c++98, c++03
12 
13 // <future>
14 
15 // class packaged_task<R(ArgTypes...)>
16 
17 // ~packaged_task();
18 
19 #include <future>
20 #include <cassert>
21 
22 class A
23 {
24     long data_;
25 
26 public:
A(long i)27     explicit A(long i) : data_(i) {}
28 
operator ()(long i,long j) const29     long operator()(long i, long j) const {return data_ + i + j;}
30 };
31 
func(std::packaged_task<double (int,char)> p)32 void func(std::packaged_task<double(int, char)> p)
33 {
34 }
35 
func2(std::packaged_task<double (int,char)> p)36 void func2(std::packaged_task<double(int, char)> p)
37 {
38     p(3, 'a');
39 }
40 
main()41 int main()
42 {
43     {
44         std::packaged_task<double(int, char)> p(A(5));
45         std::future<double> f = p.get_future();
46         std::thread(func, std::move(p)).detach();
47         try
48         {
49             double i = f.get();
50             assert(false);
51         }
52         catch (const std::future_error& e)
53         {
54             assert(e.code() == make_error_code(std::future_errc::broken_promise));
55         }
56     }
57     {
58         std::packaged_task<double(int, char)> p(A(5));
59         std::future<double> f = p.get_future();
60         std::thread(func2, std::move(p)).detach();
61         assert(f.get() == 105.0);
62     }
63 }
64