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