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 // XFAIL: libcpp-no-exceptions 11 // UNSUPPORTED: libcpp-has-no-threads 12 // UNSUPPORTED: c++98, c++03 13 14 // <future> 15 16 // class packaged_task<R(ArgTypes...)> 17 18 // void reset(); 19 20 #include <future> 21 #include <cassert> 22 23 class A 24 { 25 long data_; 26 27 public: 28 explicit A(long i) : data_(i) {} 29 30 long operator()(long i, long j) const 31 { 32 if (j == 'z') 33 throw A(6); 34 return data_ + i + j; 35 } 36 }; 37 38 int main() 39 { 40 { 41 std::packaged_task<double(int, char)> p(A(5)); 42 std::future<double> f = p.get_future(); 43 p(3, 'a'); 44 assert(f.get() == 105.0); 45 p.reset(); 46 p(4, 'a'); 47 f = p.get_future(); 48 assert(f.get() == 106.0); 49 } 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 } 63