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 // <future>
11 
12 // class packaged_task<R(ArgTypes...)>
13 
14 // void reset();
15 
16 #include <future>
17 #include <cassert>
18 
19 class A
20 {
21     long data_;
22 
23 public:
A(long i)24     explicit A(long i) : data_(i) {}
25 
operator ()(long i,long j) const26     long operator()(long i, long j) const
27     {
28         if (j == 'z')
29             throw A(6);
30         return data_ + i + j;
31     }
32 };
33 
main()34 int main()
35 {
36     {
37         std::packaged_task<double(int, char)> p(A(5));
38         std::future<double> f = p.get_future();
39         p(3, 'a');
40         assert(f.get() == 105.0);
41         p.reset();
42         p(4, 'a');
43         f = p.get_future();
44         assert(f.get() == 106.0);
45     }
46     {
47         std::packaged_task<double(int, char)> p;
48         try
49         {
50             p.reset();
51             assert(false);
52         }
53         catch (const std::future_error& e)
54         {
55             assert(e.code() == make_error_code(std::future_errc::no_state));
56         }
57     }
58 }
59