[DAG] TransformFPLoadStorePair - early out if we're not loading a simple type
[llvm-project.git] / libcxx / test / std / thread / futures / futures.task / futures.task.members / ctor_func_alloc.pass.cpp
blob1b2177ed8f44445c278e4541d2183eed251dac72
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-threads
11 // packaged_task allocator support was removed in C++17 (LWG 2921)
12 // REQUIRES: c++11 || c++14
14 // <future>
16 // class packaged_task<R(ArgTypes...)>
18 // template <class F, class Allocator>
19 // explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
21 #include <future>
22 #include <cassert>
24 #include "test_macros.h"
25 #include "test_allocator.h"
26 #include "min_allocator.h"
28 class A
30 long data_;
32 public:
33 static int n_moves;
34 static int n_copies;
36 explicit A(long i) : data_(i) {}
37 A(A&& a) : data_(a.data_) {++n_moves; a.data_ = -1;}
38 A(const A& a) : data_(a.data_) {++n_copies;}
40 long operator()(long i, long j) const {return data_ + i + j;}
43 int A::n_moves = 0;
44 int A::n_copies = 0;
46 int func(int i) { return i; }
48 int main(int, char**)
50 test_allocator_statistics alloc_stats;
52 std::packaged_task<double(int, char)> p(std::allocator_arg,
53 test_allocator<A>(&alloc_stats), A(5));
54 assert(alloc_stats.alloc_count > 0);
55 assert(p.valid());
56 std::future<double> f = p.get_future();
57 p(3, 'a');
58 assert(f.get() == 105.0);
59 assert(A::n_copies == 0);
60 assert(A::n_moves > 0);
62 assert(alloc_stats.alloc_count == 0);
63 A::n_copies = 0;
64 A::n_moves = 0;
66 A a(5);
67 std::packaged_task<double(int, char)> p(std::allocator_arg,
68 test_allocator<A>(&alloc_stats), a);
69 assert(alloc_stats.alloc_count > 0);
70 assert(p.valid());
71 std::future<double> f = p.get_future();
72 p(3, 'a');
73 assert(f.get() == 105.0);
74 assert(A::n_copies > 0);
75 assert(A::n_moves >= 0);
77 assert(alloc_stats.alloc_count == 0);
78 A::n_copies = 0;
79 A::n_moves = 0;
81 A a(5);
82 std::packaged_task<int(int)> p(std::allocator_arg, test_allocator<A>(&alloc_stats), &func);
83 assert(alloc_stats.alloc_count > 0);
84 assert(p.valid());
85 std::future<int> f = p.get_future();
86 p(4);
87 assert(f.get() == 4);
89 assert(alloc_stats.alloc_count == 0);
90 A::n_copies = 0;
91 A::n_moves = 0;
93 A a(5);
94 std::packaged_task<int(int)> p(std::allocator_arg, test_allocator<A>(&alloc_stats), func);
95 assert(alloc_stats.alloc_count > 0);
96 assert(p.valid());
97 std::future<int> f = p.get_future();
98 p(4);
99 assert(f.get() == 4);
101 assert(alloc_stats.alloc_count == 0);
102 A::n_copies = 0;
103 A::n_moves = 0;
105 std::packaged_task<double(int, char)> p(std::allocator_arg,
106 bare_allocator<void>(), A(5));
107 assert(p.valid());
108 std::future<double> f = p.get_future();
109 p(3, 'a');
110 assert(f.get() == 105.0);
111 assert(A::n_copies == 0);
112 assert(A::n_moves > 0);
114 A::n_copies = 0;
115 A::n_moves = 0;
117 std::packaged_task<double(int, char)> p(std::allocator_arg,
118 min_allocator<void>(), A(5));
119 assert(p.valid());
120 std::future<double> f = p.get_future();
121 p(3, 'a');
122 assert(f.get() == 105.0);
123 assert(A::n_copies == 0);
124 assert(A::n_moves > 0);
126 A::n_copies = 0;
127 A::n_moves = 0;
129 return 0;