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 // future<R> get_future();
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 
main()32 int main()
33 {
34     {
35         std::packaged_task<double(int, char)> p(A(5));
36         std::future<double> f = p.get_future();
37         p(3, 'a');
38         assert(f.get() == 105.0);
39     }
40     {
41         std::packaged_task<double(int, char)> p(A(5));
42         std::future<double> f = p.get_future();
43         try
44         {
45             f = p.get_future();
46             assert(false);
47         }
48         catch (const std::future_error& e)
49         {
50             assert(e.code() ==  make_error_code(std::future_errc::future_already_retrieved));
51         }
52     }
53     {
54         std::packaged_task<double(int, char)> p;
55         try
56         {
57             std::future<double> f = p.get_future();
58             assert(false);
59         }
60         catch (const std::future_error& e)
61         {
62             assert(e.code() ==  make_error_code(std::future_errc::no_state));
63         }
64     }
65 }
66