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 // future<R> get_future(); 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 int main() 34 { 35 { 36 std::packaged_task<double(int, char)> p(A(5)); 37 std::future<double> f = p.get_future(); 38 p(3, 'a'); 39 assert(f.get() == 105.0); 40 } 41 { 42 std::packaged_task<double(int, char)> p(A(5)); 43 std::future<double> f = p.get_future(); 44 try 45 { 46 f = p.get_future(); 47 assert(false); 48 } 49 catch (const std::future_error& e) 50 { 51 assert(e.code() == make_error_code(std::future_errc::future_already_retrieved)); 52 } 53 } 54 { 55 std::packaged_task<double(int, char)> p; 56 try 57 { 58 std::future<double> f = p.get_future(); 59 assert(false); 60 } 61 catch (const std::future_error& e) 62 { 63 assert(e.code() == make_error_code(std::future_errc::no_state)); 64 } 65 } 66 } 67