Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / thread / futures / futures.promise / set_value_const.pass.cpp
blobc4c89550272a5a5fb2f3f433dddb88b069cb3398
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
12 // <future>
14 // class promise<R>
16 // void promise::set_value(const R& r);
18 #include <future>
19 #include <cassert>
21 #include "test_macros.h"
23 struct A
25 A() {}
26 A(const A&) {
27 TEST_THROW(10);
31 int main(int, char**)
34 typedef int T;
35 T i = 3;
36 std::promise<T> p;
37 std::future<T> f = p.get_future();
38 p.set_value(i);
39 ++i;
40 assert(f.get() == 3);
41 #ifndef TEST_HAS_NO_EXCEPTIONS
42 --i;
43 try
45 p.set_value(i);
46 assert(false);
48 catch (const std::future_error& e)
50 assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
52 #endif
55 typedef A T;
56 T i;
57 std::promise<T> p;
58 std::future<T> f = p.get_future();
59 #ifndef TEST_HAS_NO_EXCEPTIONS
60 try
62 p.set_value(i);
63 assert(false);
65 catch (int j)
67 assert(j == 10);
69 #endif
72 return 0;