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