24 #include <boost/lexical_cast.hpp> 36 using boost::lexical_cast;
46 typedef std::vector<int> VecI;
54 std::_Placeholder<1> _1;
58 buildTestNumberz (uint count)
61 numbers.reserve(count);
63 numbers.push_back(count--);
78 function1 (
int i,
int j)
80 return plainFunc(i+j);
84 function2 (
int i,
int j,
int& k)
91 #define _NL_ cout << endl; 92 #define ANNOUNCE(_LABEL_) cout << "---:" << STRINGIFY(_LABEL_) << endl; 119 NUM_ELMS = firstVal (arg, 10);
120 VecI container = buildTestNumberz (NUM_ELMS);
121 RangeI iterator(container.begin(), container.end());
140 CHECK (
int(NUM_ELMS) ==container[0]);
143 CHECK (
int(NUM_ELMS) ==container[0]);
146 CHECK (90+
int(NUM_ELMS) ==container[0]);
159 template<
typename CO>
164 function<bool(int)> func(plainFunc);
168 for_each (coll, func); _NL_
170 and_all (coll, plainFunc); _NL_
171 and_all (coll, &plainFunc); _NL_
172 and_all (coll, func); _NL_
174 has_any (coll, plainFunc); _NL_
175 has_any (coll, &plainFunc); _NL_
176 has_any (coll, func); _NL_
183 template<
typename CO>
188 function<bool(int,int)> fun1(function1);
190 for_each (coll, function1, 10, _1 ); _NL_
191 for_each (coll, &function1,10, _1 ); _NL_
192 for_each (coll, fun1, 10, _1 ); _NL_
194 and_all (coll, function1, 10, _1 ); _NL_
195 and_all (coll, &function1, 10, _1 ); _NL_
196 and_all (coll, fun1, 10, _1 ); _NL_
198 has_any (coll, function1, 10, _1 ); _NL_
199 has_any (coll, &function1, 10, _1 ); _NL_
200 has_any (coll, fun1, 10, _1 ); _NL_
202 for_each (coll, function1, _1, _1 ); _NL_
203 for_each (coll, &function1,_1, _1 ); _NL_
204 for_each (coll, fun1, _1, _1 ); _NL_
206 and_all (coll, function1, _1, _1 ); _NL_
207 and_all (coll, &function1, _1, _1 ); _NL_
208 and_all (coll, fun1, _1, _1 ); _NL_
210 has_any (coll, function1, _1, _1 ); _NL_
211 has_any (coll, &function1, _1, _1 ); _NL_
212 has_any (coll, fun1, _1, _1 ); _NL_
234 template<
typename CO>
238 ANNOUNCE (assign_to_input);
239 function<bool(int,int,int&)> fun2(function2);
241 for_each (coll, function2, 5, 5, _1 ); _NL_
242 for_each (coll, &function2,5, 5, _1 ); _NL_
244 and_all (coll, function2, 5, 5, _1 ); _NL_
245 and_all (coll, &function2, 5, 5, _1 ); _NL_
247 has_any (coll, function2, 5, 5, _1 ); _NL_
248 has_any (coll, &function2, 5, 5, _1 ); _NL_
252 for_each (coll,fun2, 5, 5, _1 ); _NL_
253 and_all (coll, fun2, 5, 5, _1 ); _NL_
254 has_any (coll, fun2, 5, 5, _1 ); _NL_
261 ANNOUNCE (assign_to_var);
262 for_each (coll, function2, -10, _1, ref(sum) ); _NL_
263 for_each (coll, &function2,-10, _1, ref(sum) ); _NL_
264 for_each (coll, fun2, -10, _1, ref(sum) ); _NL_
265 cout <<
"sum=" << sum << endl;
268 and_all (coll, function2, -10, _1, ref(sum) ); _NL_
269 and_all (coll, &function2, -10, _1, ref(sum) ); _NL_
270 and_all (coll, fun2, -10, _1, ref(sum) ); _NL_
271 cout <<
"sum=" << sum << endl;
274 has_any (coll, function2, -10, _1, ref(sum) ); _NL_
275 has_any (coll, &function2, -10, _1, ref(sum) ); _NL_
276 has_any (coll, fun2, -10, _1, ref(sum) ); _NL_
277 cout <<
"sum=" << sum << endl;
284 template<
typename CO>
290 for_each (coll,function1, 10, _1 ); _NL_
291 and_all (coll, function1, 10, _1 ); _NL_
292 has_any (coll, function1, 10, _1 ); _NL_
294 for_each (coll,function1, _1, _1 ); _NL_
295 and_all (coll, function1, _1, _1 ); _NL_
296 has_any (coll, function1, _1, _1 ); _NL_
300 for_each (coll,function2, _1, _1, ref(sum) ); _NL_
301 and_all (coll, function2, _1, _1, ref(sum) ); _NL_
302 has_any (coll, function2, _1, _1, ref(sum) ); _NL_
315 return plainFunc (sum_);
320 template<
typename CO>
329 for_each (coll, &Dummy::fun, dummy, _1 ); _NL_
330 and_all (coll, &Dummy::fun, dummy, _1 ); _NL_
331 has_any (coll, &Dummy::fun, dummy, _1 ); _NL_
333 for_each (coll, &Dummy::fun, &dummy, _1 ); _NL_
334 and_all (coll, &Dummy::fun, &dummy, _1 ); _NL_
335 has_any (coll, &Dummy::fun, &dummy, _1 ); _NL_
337 cout <<
"sum=" << dummy.sum_ << endl;
342 template<
typename CO>
351 CHECK (sum == (NUM_ELMS+1) * NUM_ELMS/2);
353 CHECK (!
and_all (coll, [] (uint elm) {
return elm - 1; }));
354 CHECK (
has_any (coll, [] (uint elm) {
return elm + 1; }));
360 template<
typename CO>
366 CHECK (
and_all (coll, [] (uint elm) {
return 0 < elm; }));
367 CHECK (!
and_all (coll, [] (uint elm) {
return 1 < elm; }));
369 CHECK (
has_any (coll, [] (uint elm) {
return 0 < elm; }));
370 CHECK (
has_any (coll, [
this](uint elm) {
return elm == NUM_ELMS; }));
371 CHECK (!
has_any (coll, [
this](uint elm) {
return elm > NUM_ELMS; }));
380 bool operation() {
return plainFunc (n_); }
392 std::vector<TestElm> elms;
393 for (uint i=0; i<6; ++i)
396 std::vector<TestElm*> elmPtrs;
397 for (uint i=0; i<6; ++i)
398 elmPtrs.push_back (& elms[i]);
401 for_each (elmPtrs, &TestElm::operation, _1 ); _NL_
402 and_all (elmPtrs, &TestElm::operation, _1 ); _NL_
403 has_any (elmPtrs, &TestElm::operation, _1 ); _NL_
406 for_each (elms, &TestElm::operation, _1 ); _NL_
407 and_all (elms, &TestElm::operation, _1 ); _NL_
408 has_any (elms, &TestElm::operation, _1 ); _NL_
428 ANNOUNCE (wrapped_container_passing);
430 #define SHOW_CONTAINER for_each (coll, plainFunc); _NL_ 432 int counter = NUM_ELMS;
433 auto assign_and_decrement = [&] (
int&
entry)
439 VecI
const& passByConstRef (coll);
441 for_each (passByConstRef, assign_and_decrement );
445 CHECK (0 == counter);
448 for_each (buildTestNumberz(NUM_ELMS), assign_and_decrement );
453 for_each (bySmartPtr, assign_and_decrement );
457 CHECK (-2*
int(NUM_ELMS) == counter);
458 CHECK (bySmartPtr->back() == counter+1);
461 const VecI *
const passByConstPointer (&coll);
463 for_each (passByConstPointer, assign_and_decrement );
void check_foreach_bind(CO coll)
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
Helper template(s) for creating Lumiera Forward Iterators.
void check_foreach_lambda(CO coll)
bool and_all(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
void check_ref_argument_bind(CO coll)
bool has_any(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
void check_invoke_on_each()
Simplistic test class runner.
void check_existence_quant(CO coll)
disable_if< can_IterForEach< Container >, FUN > for_each(Container const &coll, FUN doIt)
operate on all elements of a STL container.
void check_wrapped_container_passing(VecI coll)
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
bool has_any(IT i, IT end, FUN predicate)
Existential quantification: check if any element of a collection satisfies the given predicate...
void check_foreach_memFun(CO coll)
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
bool and_all(IT i, IT end, FUN predicate)
All quantification: check if all elements of a collection satisfy the given predicate.
Perform operations "for each element" of a collection.
void check_foreach_plain(CO coll)
void check_foreach_bind_const(CO const &coll)