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 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <future> |
| 11 | |
| 12 | // class promise<R> |
| 13 | |
| 14 | // promise& operator=(const promise& rhs) = delete; |
| 15 | |
| 16 | #include <future> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 17 | #include <cassert> |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 18 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 19 | #include "../test_allocator.h" |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 20 | |
| 21 | int main() |
| 22 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 23 | assert(test_alloc_base::count == 0); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 24 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 25 | std::promise<int> p0(std::allocator_arg, test_allocator<int>()); |
| 26 | std::promise<int> p(std::allocator_arg, test_allocator<int>()); |
| 27 | assert(test_alloc_base::count == 2); |
| 28 | p = p0; |
| 29 | assert(test_alloc_base::count == 1); |
| 30 | std::future<int> f = p.get_future(); |
| 31 | assert(test_alloc_base::count == 1); |
| 32 | assert(f.valid()); |
| 33 | try |
| 34 | { |
| 35 | f = p0.get_future(); |
| 36 | assert(false); |
| 37 | } |
| 38 | catch (const std::future_error& e) |
| 39 | { |
| 40 | assert(e.code() == make_error_code(std::future_errc::no_state)); |
| 41 | } |
| 42 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 43 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 44 | assert(test_alloc_base::count == 0); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 45 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 46 | std::promise<int&> p0(std::allocator_arg, test_allocator<int>()); |
| 47 | std::promise<int&> p(std::allocator_arg, test_allocator<int>()); |
| 48 | assert(test_alloc_base::count == 2); |
| 49 | p = p0; |
| 50 | assert(test_alloc_base::count == 1); |
| 51 | std::future<int&> f = p.get_future(); |
| 52 | assert(test_alloc_base::count == 1); |
| 53 | assert(f.valid()); |
| 54 | try |
| 55 | { |
| 56 | f = p0.get_future(); |
| 57 | assert(false); |
| 58 | } |
| 59 | catch (const std::future_error& e) |
| 60 | { |
| 61 | assert(e.code() == make_error_code(std::future_errc::no_state)); |
| 62 | } |
| 63 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 64 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 65 | assert(test_alloc_base::count == 0); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 66 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 67 | std::promise<void> p0(std::allocator_arg, test_allocator<void>()); |
| 68 | std::promise<void> p(std::allocator_arg, test_allocator<void>()); |
| 69 | assert(test_alloc_base::count == 2); |
| 70 | p = p0; |
| 71 | assert(test_alloc_base::count == 1); |
| 72 | std::future<void> f = p.get_future(); |
| 73 | assert(test_alloc_base::count == 1); |
| 74 | assert(f.valid()); |
| 75 | try |
| 76 | { |
| 77 | f = p0.get_future(); |
| 78 | assert(false); |
| 79 | } |
| 80 | catch (const std::future_error& e) |
| 81 | { |
| 82 | assert(e.code() == make_error_code(std::future_errc::no_state)); |
| 83 | } |
| 84 | assert(test_alloc_base::count == 1); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 85 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 86 | assert(test_alloc_base::count == 0); |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 87 | } |