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 // <future> 11 12 // class promise<R> 13 14 // void promise::set_value(const R& r); 15 16 #include <future> 17 #include <cassert> 18 19 struct A 20 { 21 A() {} 22 A(const A&) {throw 10;} 23 }; 24 25 int main() 26 { 27 { 28 typedef int T; 29 T i = 3; 30 std::promise<T> p; 31 std::future<T> f = p.get_future(); 32 p.set_value(i); 33 ++i; 34 assert(f.get() == 3); 35 --i; 36 try 37 { 38 p.set_value(i); 39 assert(false); 40 } 41 catch (const std::future_error& e) 42 { 43 assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied)); 44 } 45 } 46 { 47 typedef A T; 48 T i; 49 std::promise<T> p; 50 std::future<T> f = p.get_future(); 51 try 52 { 53 p.set_value(i); 54 assert(false); 55 } 56 catch (int j) 57 { 58 assert(j == 10); 59 } 60 } 61 } 62