blob: 9d38d9b409c0923223299faf08895ffe55f65b63 [file] [log] [blame]
Howard Hinnant54da3382010-08-30 18:46:21 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant54da3382010-08-30 18:46:21 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant54da3382010-08-30 18:46:21 +000011
12// <future>
13
14// class packaged_task<R(ArgTypes...)>
15
16// void reset();
17
18#include <future>
19#include <cassert>
20
21class A
22{
23 long data_;
24
25public:
26 explicit A(long i) : data_(i) {}
27
28 long operator()(long i, long j) const
29 {
30 if (j == 'z')
31 throw A(6);
32 return data_ + i + j;
33 }
34};
35
36int main()
37{
38 {
39 std::packaged_task<double(int, char)> p(A(5));
40 std::future<double> f = p.get_future();
41 p(3, 'a');
42 assert(f.get() == 105.0);
43 p.reset();
44 p(4, 'a');
45 f = p.get_future();
46 assert(f.get() == 106.0);
47 }
48 {
49 std::packaged_task<double(int, char)> p;
50 try
51 {
52 p.reset();
53 assert(false);
54 }
55 catch (const std::future_error& e)
56 {
57 assert(e.code() == make_error_code(std::future_errc::no_state));
58 }
59 }
60}