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 // void reset();
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
30     {
31         if (j == 'z')
32             throw A(6);
33         return data_ + i + j;
34     }
35 };
36 
main()37 int main()
38 {
39     {
40         std::packaged_task<double(int, char)> p(A(5));
41         std::future<double> f = p.get_future();
42         p(3, 'a');
43         assert(f.get() == 105.0);
44         p.reset();
45         p(4, 'a');
46         f = p.get_future();
47         assert(f.get() == 106.0);
48     }
49     {
50         std::packaged_task<double(int, char)> p;
51         try
52         {
53             p.reset();
54             assert(false);
55         }
56         catch (const std::future_error& e)
57         {
58             assert(e.code() == make_error_code(std::future_errc::no_state));
59         }
60     }
61 }
62