• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "test_macros.h"
23 
24 class A
25 {
26     long data_;
27 
28 public:
A(long i)29     explicit A(long i) : data_(i) {}
30 
operator ()(long i,long j) const31     long operator()(long i, long j) const
32     {
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 #ifndef TEST_HAS_NO_EXCEPTIONS
50     {
51         std::packaged_task<double(int, char)> p;
52         try
53         {
54             p.reset();
55             assert(false);
56         }
57         catch (const std::future_error& e)
58         {
59             assert(e.code() == make_error_code(std::future_errc::no_state));
60         }
61     }
62 #endif
63 }
64