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 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() 26 { 27 assert(test_alloc_base::count == 0); 28 { 29 std::promise<int> p(std::allocator_arg, test_allocator<int>()); 30 assert(test_alloc_base::count == 1); 31 std::future<int> f = p.get_future(); 32 assert(test_alloc_base::count == 1); 33 assert(f.valid()); 34 } 35 assert(test_alloc_base::count == 0); 36 { 37 std::promise<int&> p(std::allocator_arg, test_allocator<int>()); 38 assert(test_alloc_base::count == 1); 39 std::future<int&> f = p.get_future(); 40 assert(test_alloc_base::count == 1); 41 assert(f.valid()); 42 } 43 assert(test_alloc_base::count == 0); 44 { 45 std::promise<void> p(std::allocator_arg, test_allocator<void>()); 46 assert(test_alloc_base::count == 1); 47 std::future<void> f = p.get_future(); 48 assert(test_alloc_base::count == 1); 49 assert(f.valid()); 50 } 51 assert(test_alloc_base::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