blob: cdc37775012ce4887f0403189907198bbc448bf3 [file] [log] [blame]
Howard Hinnantf39daa82010-08-28 21:01:06 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantf39daa82010-08-28 21:01:06 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnantf39daa82010-08-28 21:01:06 +000011
12// <future>
13
14// class promise<R>
15
16// void promise<R&>::set_value(R& r);
17
18#include <future>
19#include <cassert>
20
21int main()
22{
23 {
24 typedef int& T;
25 int i = 3;
26 std::promise<T> p;
27 std::future<T> f = p.get_future();
28 p.set_value(i);
Howard Hinnant54da3382010-08-30 18:46:21 +000029 int& j = f.get();
30 assert(j == 3);
Howard Hinnantf39daa82010-08-28 21:01:06 +000031 ++i;
Howard Hinnant54da3382010-08-30 18:46:21 +000032 assert(j == 4);
Howard Hinnantf39daa82010-08-28 21:01:06 +000033 try
34 {
35 p.set_value(i);
36 assert(false);
37 }
38 catch (const std::future_error& e)
39 {
40 assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
41 }
42 }
43}