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 26 int main(int, char**) 27 { 28 test_allocator_statistics alloc_stats; 29 assert(alloc_stats.alloc_count == 0); 30 { 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); 35 assert(f.valid()); 36 } 37 assert(alloc_stats.alloc_count == 0); 38 { 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); 43 assert(f.valid()); 44 } 45 assert(alloc_stats.alloc_count == 0); 46 { 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); 51 assert(f.valid()); 52 } 53 assert(alloc_stats.alloc_count == 0); 54 // Test with a minimal allocator 55 { 56 std::promise<int> p(std::allocator_arg, bare_allocator<void>()); 57 std::future<int> f = p.get_future(); 58 assert(f.valid()); 59 } 60 { 61 std::promise<int&> p(std::allocator_arg, bare_allocator<void>()); 62 std::future<int&> f = p.get_future(); 63 assert(f.valid()); 64 } 65 { 66 std::promise<void> p(std::allocator_arg, bare_allocator<void>()); 67 std::future<void> f = p.get_future(); 68 assert(f.valid()); 69 } 70 // Test with a minimal allocator that returns class-type pointers 71 { 72 std::promise<int> p(std::allocator_arg, min_allocator<void>()); 73 std::future<int> f = p.get_future(); 74 assert(f.valid()); 75 } 76 { 77 std::promise<int&> p(std::allocator_arg, min_allocator<void>()); 78 std::future<int&> f = p.get_future(); 79 assert(f.valid()); 80 } 81 { 82 std::promise<void> p(std::allocator_arg, min_allocator<void>()); 83 std::future<void> f = p.get_future(); 84 assert(f.valid()); 85 } 86 87 return 0; 88 } 89