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: libcpp-has-no-threads
10 // UNSUPPORTED: c++03
11
12 // <future>
13
14 // class promise<R>
15
16 // template <class Allocator>
17 // promise(allocator_arg_t, const Allocator& a);
18
19 #include <future>
20 #include <cassert>
21
22 #include "test_macros.h"
23 #include "test_allocator.h"
24 #include "min_allocator.h"
25
main(int,char **)26 int main(int, char**)
27 {
28 assert(test_alloc_base::alloc_count == 0);
29 {
30 std::promise<int> p(std::allocator_arg, test_allocator<int>(42));
31 assert(test_alloc_base::alloc_count == 1);
32 std::future<int> f = p.get_future();
33 assert(test_alloc_base::alloc_count == 1);
34 assert(f.valid());
35 }
36 assert(test_alloc_base::alloc_count == 0);
37 {
38 std::promise<int&> p(std::allocator_arg, test_allocator<int>(42));
39 assert(test_alloc_base::alloc_count == 1);
40 std::future<int&> f = p.get_future();
41 assert(test_alloc_base::alloc_count == 1);
42 assert(f.valid());
43 }
44 assert(test_alloc_base::alloc_count == 0);
45 {
46 std::promise<void> p(std::allocator_arg, test_allocator<void>(42));
47 assert(test_alloc_base::alloc_count == 1);
48 std::future<void> f = p.get_future();
49 assert(test_alloc_base::alloc_count == 1);
50 assert(f.valid());
51 }
52 assert(test_alloc_base::alloc_count == 0);
53 // Test with a minimal allocator
54 {
55 std::promise<int> p(std::allocator_arg, bare_allocator<void>());
56 std::future<int> f = p.get_future();
57 assert(f.valid());
58 }
59 {
60 std::promise<int&> p(std::allocator_arg, bare_allocator<void>());
61 std::future<int&> f = p.get_future();
62 assert(f.valid());
63 }
64 {
65 std::promise<void> p(std::allocator_arg, bare_allocator<void>());
66 std::future<void> f = p.get_future();
67 assert(f.valid());
68 }
69 // Test with a minimal allocator that returns class-type pointers
70 {
71 std::promise<int> p(std::allocator_arg, min_allocator<void>());
72 std::future<int> f = p.get_future();
73 assert(f.valid());
74 }
75 {
76 std::promise<int&> p(std::allocator_arg, min_allocator<void>());
77 std::future<int&> f = p.get_future();
78 assert(f.valid());
79 }
80 {
81 std::promise<void> p(std::allocator_arg, min_allocator<void>());
82 std::future<void> f = p.get_future();
83 assert(f.valid());
84 }
85
86 return 0;
87 }
88