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