Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 9 | // |
| 10 | // UNSUPPORTED: libcpp-has-no-threads |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 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 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 22 | #include "../test_allocator.h" |
Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 23 | #include "min_allocator.h" |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 24 | |
| 25 | int main() |
| 26 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 27 | assert(test_alloc_base::count == 0); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 28 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 29 | std::promise<int> p(std::allocator_arg, test_allocator<int>()); |
| 30 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 31 | std::future<int> f = p.get_future(); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 32 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 33 | assert(f.valid()); |
| 34 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 35 | assert(test_alloc_base::count == 0); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 36 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 37 | std::promise<int&> p(std::allocator_arg, test_allocator<int>()); |
| 38 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 39 | std::future<int&> f = p.get_future(); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 40 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 41 | assert(f.valid()); |
| 42 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 43 | assert(test_alloc_base::count == 0); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 44 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 45 | std::promise<void> p(std::allocator_arg, test_allocator<void>()); |
| 46 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 47 | std::future<void> f = p.get_future(); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 48 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 49 | assert(f.valid()); |
| 50 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 51 | assert(test_alloc_base::count == 0); |
Eric Fiselier | 4d2413c | 2014-10-23 06:24:45 +0000 | [diff] [blame] | 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 | } |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 84 | } |