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 // void promise<R&>::set_value(R& r); 19 20 #include <future> 21 #include <cassert> 22 23 int main() 24 { 25 { 26 typedef int& T; 27 int i = 3; 28 std::promise<T> p; 29 std::future<T> f = p.get_future(); 30 p.set_value(i); 31 int& j = f.get(); 32 assert(j == 3); 33 ++i; 34 assert(j == 4); 35 try 36 { 37 p.set_value(i); 38 assert(false); 39 } 40 catch (const std::future_error& e) 41 { 42 assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied)); 43 } 44 } 45 } 46