18 void CurryTest::testBasic ()
20 auto sum = [] (
int a,
int b,
int c) {
return a + b + c; };
21 QCOMPARE (
Curry (sum) (1) (2) (3), 6);
23 auto stored =
Curry (sum);
24 QCOMPARE (stored (1) (2) (3), 6);
25 QCOMPARE (stored (0) (2) (3), 5);
27 auto storedApplied =
Curry (sum) (0);
28 QCOMPARE (storedApplied (2) (3), 5);
31 void CurryTest::testMoveArgs ()
33 auto func = [] (std::unique_ptr<int> a, std::unique_ptr<int> b) {
return *a + *b; };
34 QCOMPARE (
Curry (func) (std::make_unique<int> (1)) (std::make_unique<int> (2)), 3);
36 auto curried =
Curry (func) (std::make_unique<int> (1));
37 QCOMPARE (std::move (curried) (std::make_unique<int> (2)), 3);
40 void CurryTest::testMoveFun ()
42 auto ptr = std::make_unique<int> (10);
43 auto func = [ptr = std::move (ptr)] (std::unique_ptr<int> a, std::unique_ptr<int> b) {
return *ptr + *a + *b; };
44 QCOMPARE (
Curry (std::move (func)) (std::make_unique<int> (1)) (std::make_unique<int> (2)), 13);
47 void CurryTest::testRValueFun ()
49 auto sum = [] (
int&& a,
int&& b,
int&& c) {
return a + b + c; };
50 QCOMPARE (
Curry (sum) (1) (2) (3), 6);
53 void CurryTest::testRefModifications ()
57 auto func = [] (
int& a,
int& b) { ++a; ++b;
return a + b; };
58 QCOMPARE (
Curry (func) (a) (b), 13);
68 static inline int DefConstrs_ = 0;
69 static inline int CopyConstrs_ = 0;
70 static inline int CopyAssignments_ = 0;
71 static inline int MoveConstrs_ = 0;
72 static inline int MoveAssignments_ = 0;
73 static inline int Dtors_ = 0;
80 Counter (
const Counter&)
90 Counter& operator= (
const Counter&)
96 Counter& operator= (Counter&&)
109 void CurryTest::testNoExtraCopiesByValue ()
111 using C1 = Counter<struct Tag1>;
112 using C2 = Counter<struct Tag2>;
114 auto func = [] (C1, C2) {
return 0; };
115 QCOMPARE (
Curry (func) (C1 {}) (C2 {}), 0);
117 QCOMPARE (C1::CopyConstrs_, 0);
118 QCOMPARE (C2::CopyConstrs_, 0);
119 QCOMPARE (C1::CopyAssignments_, 0);
120 QCOMPARE (C2::CopyAssignments_, 0);
122 QCOMPARE (C1::MoveConstrs_, 2);
123 QCOMPARE (C2::MoveConstrs_, 1);
124 QCOMPARE (C1::MoveAssignments_, 0);
125 QCOMPARE (C2::MoveAssignments_, 0);
128 void CurryTest::testNoExtraCopiesByRef ()
130 using C1 = Counter<struct Tag1>;
131 using C2 = Counter<struct Tag2>;
133 auto func = [] (C1&&, C2&&) {
return 0; };
134 QCOMPARE (
Curry (func) (C1 {}) (C2 {}), 0);
136 QCOMPARE (C1::CopyConstrs_, 0);
137 QCOMPARE (C2::CopyConstrs_, 0);
138 QCOMPARE (C1::CopyAssignments_, 0);
139 QCOMPARE (C2::CopyAssignments_, 0);
141 QCOMPARE (C1::MoveConstrs_, 1);
142 QCOMPARE (C2::MoveConstrs_, 0);
143 QCOMPARE (C1::MoveAssignments_, 0);
144 QCOMPARE (C2::MoveAssignments_, 0);
147 void CurryTest::testNoExtraCopiesByConstRef ()
149 using C1 = Counter<struct Tag1>;
150 using C2 = Counter<struct Tag2>;
152 auto func = [] (
const C1&,
const C2&) {
return 0; };
153 QCOMPARE (
Curry (func) (C1 {}) (C2 {}), 0);
155 QCOMPARE (C1::CopyConstrs_, 0);
156 QCOMPARE (C2::CopyConstrs_, 0);
157 QCOMPARE (C1::CopyAssignments_, 0);
158 QCOMPARE (C2::CopyAssignments_, 0);
160 QCOMPARE (C1::MoveConstrs_, 1);
161 QCOMPARE (C2::MoveConstrs_, 0);
162 QCOMPARE (C1::MoveAssignments_, 0);
163 QCOMPARE (C2::MoveAssignments_, 0);
166 void CurryTest::testNoExtraCopiesByConstRefToExisting ()
168 using C1 = Counter<struct Tag1>;
169 using C2 = Counter<struct Tag2>;
171 auto func = [] (
const C1&,
const C2&) {
return 0; };
174 QCOMPARE (
Curry (func) (c1) (c2), 0);
176 QCOMPARE (C1::CopyConstrs_, 0);
177 QCOMPARE (C2::CopyConstrs_, 0);
178 QCOMPARE (C1::CopyAssignments_, 0);
179 QCOMPARE (C2::CopyAssignments_, 0);
181 QCOMPARE (C1::MoveConstrs_, 0);
182 QCOMPARE (C2::MoveConstrs_, 0);
183 QCOMPARE (C1::MoveAssignments_, 0);
184 QCOMPARE (C2::MoveAssignments_, 0);