1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
16 // template <class Allocator>
17 // promise(allocator_arg_t, const Allocator& a);
22 #include "test_macros.h"
23 #include "test_allocator.h"
24 #include "min_allocator.h"
28 test_allocator_statistics alloc_stats
;
29 assert(alloc_stats
.alloc_count
== 0);
31 std::promise
<int> p(std::allocator_arg
, test_allocator
<int>(42, &alloc_stats
));
32 assert(alloc_stats
.alloc_count
== 1);
33 std::future
<int> f
= p
.get_future();
34 assert(alloc_stats
.alloc_count
== 1);
37 assert(alloc_stats
.alloc_count
== 0);
39 std::promise
<int&> p(std::allocator_arg
, test_allocator
<int>(42, &alloc_stats
));
40 assert(alloc_stats
.alloc_count
== 1);
41 std::future
<int&> f
= p
.get_future();
42 assert(alloc_stats
.alloc_count
== 1);
45 assert(alloc_stats
.alloc_count
== 0);
47 std::promise
<void> p(std::allocator_arg
, test_allocator
<void>(42, &alloc_stats
));
48 assert(alloc_stats
.alloc_count
== 1);
49 std::future
<void> f
= p
.get_future();
50 assert(alloc_stats
.alloc_count
== 1);
53 assert(alloc_stats
.alloc_count
== 0);
54 // Test with a minimal allocator
56 std::promise
<int> p(std::allocator_arg
, bare_allocator
<void>());
57 std::future
<int> f
= p
.get_future();
61 std::promise
<int&> p(std::allocator_arg
, bare_allocator
<void>());
62 std::future
<int&> f
= p
.get_future();
66 std::promise
<void> p(std::allocator_arg
, bare_allocator
<void>());
67 std::future
<void> f
= p
.get_future();
70 // Test with a minimal allocator that returns class-type pointers
72 std::promise
<int> p(std::allocator_arg
, min_allocator
<void>());
73 std::future
<int> f
= p
.get_future();
77 std::promise
<int&> p(std::allocator_arg
, min_allocator
<void>());
78 std::future
<int&> f
= p
.get_future();
82 std::promise
<void> p(std::allocator_arg
, min_allocator
<void>());
83 std::future
<void> f
= p
.get_future();