Debian Codegraph @

libcxx/test/std/thread/futures/futures.promise/set_rvalue.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: c++03
10 // UNSUPPORTED: no-threads, no-exceptions
11
12 // <future>
13
14 // class promise<R>
15
16 // void promise::set_value(R&& r);
17
18 #include <future>
19 #include <memory>
20 #include <cassert>
21
22 #include "test_macros.h"
23
24 struct A
25 {
26 A() {}
27 A(const A&) = delete;
28 A(A&&) {throw 9;}
29 };
30
31 int main(int, char**)
32 {
33 {
34 typedef std::unique_ptr<int> T;
35 T i(new int(3));
36 std::promise<T> p;
37 std::future<T> f = p.get_future();
38 p.set_value(std::move(i));
39 assert(*f.get() == 3);
40 try
41 {
42 p.set_value(std::move(i));
43 assert(false);
44 }
45 catch (const std::future_error& e)
46 {
47 assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
48 }
49 }
50 {
51 typedef A T;
52 T i;
53 std::promise<T> p;
54 std::future<T> f = p.get_future();
55 try
56 {
57 p.set_value(std::move(i));
58 assert(false);
59 }
60 catch (int j)
61 {
62 assert(j == 9);
63 }
64 }
65
66 return 0;
67 }