Debian Codegraph @

libcxx/test/std/thread/futures/futures.promise/set_lvalue.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03
11
12 // <future>
13
14 // class promise<R>
15
16 // void promise<R&>::set_value(R& r);
17
18 #include <future>
19 #include <cassert>
20
21 #include "test_macros.h"
22
23 int main(int, char**)
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 #ifndef TEST_HAS_NO_EXCEPTIONS
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 #endif
46 }
47
48 return 0;
49 }