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 promise<R> 17 18 // future<R> get_future(); 19 20 #include <future> 21 #include <cassert> 22 23 int main() 24 { 25 { 26 std::promise<double> p; 27 std::future<double> f = p.get_future(); 28 p.set_value(105.5); 29 assert(f.get() == 105.5); 30 } 31 { 32 std::promise<double> p; 33 std::future<double> f = p.get_future(); 34 try 35 { 36 f = p.get_future(); 37 assert(false); 38 } 39 catch (const std::future_error& e) 40 { 41 assert(e.code() == make_error_code(std::future_errc::future_already_retrieved)); 42 } 43 } 44 { 45 std::promise<double> p; 46 std::promise<double> p0 = std::move(p); 47 try 48 { 49 std::future<double> f = p.get_future(); 50 assert(false); 51 } 52 catch (const std::future_error& e) 53 { 54 assert(e.code() == make_error_code(std::future_errc::no_state)); 55 } 56 } 57 } 58