| 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: no-exceptions |
| 10 | // UNSUPPORTED: no-threads |
| 11 | // UNSUPPORTED: c++03 |
| 12 | |
| 13 | // <future> |
| 14 | |
| 15 | // class future<R> |
| 16 | |
| 17 | // ~future(); |
| 18 | |
| 19 | #include <future> |
| 20 | #include <cassert> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | #include "test_allocator.h" |
| 24 | |
| 25 | int main(int, char**) |
| 26 | { |
| 27 | test_allocator_statistics alloc_stats; |
| 28 | assert(alloc_stats.alloc_count == 0); |
| 29 | { |
| 30 | typedef int T; |
| 31 | std::future<T> f; |
| 32 | { |
| 33 | std::promise<T> p(std::allocator_arg, test_allocator<T>(&alloc_stats)); |
| 34 | assert(alloc_stats.alloc_count == 1); |
| 35 | f = p.get_future(); |
| 36 | assert(alloc_stats.alloc_count == 1); |
| 37 | assert(f.valid()); |
| 38 | } |
| 39 | assert(alloc_stats.alloc_count == 1); |
| 40 | assert(f.valid()); |
| 41 | } |
| 42 | assert(alloc_stats.alloc_count == 0); |
| 43 | { |
| 44 | typedef int& T; |
| 45 | std::future<T> f; |
| 46 | { |
| 47 | std::promise<T> p(std::allocator_arg, test_allocator<int>(&alloc_stats)); |
| 48 | assert(alloc_stats.alloc_count == 1); |
| 49 | f = p.get_future(); |
| 50 | assert(alloc_stats.alloc_count == 1); |
| 51 | assert(f.valid()); |
| 52 | } |
| 53 | assert(alloc_stats.alloc_count == 1); |
| 54 | assert(f.valid()); |
| 55 | } |
| 56 | assert(alloc_stats.alloc_count == 0); |
| 57 | { |
| 58 | typedef void T; |
| 59 | std::future<T> f; |
| 60 | { |
| 61 | std::promise<T> p(std::allocator_arg, test_allocator<T>(&alloc_stats)); |
| 62 | assert(alloc_stats.alloc_count == 1); |
| 63 | f = p.get_future(); |
| 64 | assert(alloc_stats.alloc_count == 1); |
| 65 | assert(f.valid()); |
| 66 | } |
| 67 | assert(alloc_stats.alloc_count == 1); |
| 68 | assert(f.valid()); |
| 69 | } |
| 70 | assert(alloc_stats.alloc_count == 0); |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |