• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // UNSUPPORTED: libcpp-has-no-threads
11 // UNSUPPORTED: c++98, c++03
12 
13 // <future>
14 
15 // class promise<R>
16 
17 // template <class Allocator>
18 //   promise(allocator_arg_t, const Allocator& a);
19 
20 #include <future>
21 #include <cassert>
22 
23 #include "test_allocator.h"
24 #include "min_allocator.h"
25 
main()26 int main()
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