blob: baa89cb12b1c4dd9f7c081df7aca712c05d9359d [file] [log] [blame]
Howard Hinnant99be8232010-09-03 18:39:25 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant99be8232010-09-03 18:39:25 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant99be8232010-09-03 18:39:25 +000011
12// <future>
13
14// class shared_future<R>
15
16// ~shared_future();
17
18#include <future>
19#include <cassert>
20
Dan Albert1d4a1ed2016-05-25 22:36:09 -070021#include "../test_allocator.h"
Howard Hinnant99be8232010-09-03 18:39:25 +000022
23int main()
24{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070025 assert(test_alloc_base::count == 0);
Howard Hinnant99be8232010-09-03 18:39:25 +000026 {
27 typedef int T;
28 std::shared_future<T> f;
29 {
30 std::promise<T> p(std::allocator_arg, test_allocator<T>());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070031 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000032 f = p.get_future();
Dan Albert1d4a1ed2016-05-25 22:36:09 -070033 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000034 assert(f.valid());
35 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070036 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000037 assert(f.valid());
38 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070039 assert(test_alloc_base::count == 0);
Howard Hinnant99be8232010-09-03 18:39:25 +000040 {
41 typedef int& T;
42 std::shared_future<T> f;
43 {
44 std::promise<T> p(std::allocator_arg, test_allocator<int>());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070045 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000046 f = p.get_future();
Dan Albert1d4a1ed2016-05-25 22:36:09 -070047 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000048 assert(f.valid());
49 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070050 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000051 assert(f.valid());
52 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070053 assert(test_alloc_base::count == 0);
Howard Hinnant99be8232010-09-03 18:39:25 +000054 {
55 typedef void T;
56 std::shared_future<T> f;
57 {
58 std::promise<T> p(std::allocator_arg, test_allocator<T>());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070059 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000060 f = p.get_future();
Dan Albert1d4a1ed2016-05-25 22:36:09 -070061 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000062 assert(f.valid());
63 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070064 assert(test_alloc_base::count == 1);
Howard Hinnant99be8232010-09-03 18:39:25 +000065 assert(f.valid());
66 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070067 assert(test_alloc_base::count == 0);
Howard Hinnant99be8232010-09-03 18:39:25 +000068}