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// future<R> get_future(); 18 19#include <future> 20#include <cassert> 21 22#include "test_macros.h" 23 24class A 25{ 26 long data_; 27 28public: 29 explicit A(long i) : data_(i) {} 30 31 long operator()(long i, long j) const {return data_ + i + j;} 32}; 33 34int main() 35{ 36 { 37 std::packaged_task<double(int, char)> p(A(5)); 38 std::future<double> f = p.get_future(); 39 p(3, 'a'); 40 assert(f.get() == 105.0); 41 } 42#ifndef TEST_HAS_NO_EXCEPTIONS 43 { 44 std::packaged_task<double(int, char)> p(A(5)); 45 std::future<double> f = p.get_future(); 46 try 47 { 48 f = p.get_future(); 49 assert(false); 50 } 51 catch (const std::future_error& e) 52 { 53 assert(e.code() == make_error_code(std::future_errc::future_already_retrieved)); 54 } 55 } 56 { 57 std::packaged_task<double(int, char)> p; 58 try 59 { 60 std::future<double> f = p.get_future(); 61 assert(false); 62 } 63 catch (const std::future_error& e) 64 { 65 assert(e.code() == make_error_code(std::future_errc::no_state)); 66 } 67 } 68#endif 69} 70