33 #include <boost/lexical_cast.hpp> 45 using boost::lexical_cast;
55 typedef std::vector<int> VecI;
65 std::_Placeholder<1> _1;
69 buildTestNumberz (uint count)
72 numbers.reserve(count);
74 numbers.push_back(count--);
89 function1 (
int i,
int j)
91 return plainFunc(i+j);
95 function2 (
int i,
int j,
int& k)
102 #define _NL_ cout << endl; 103 #define ANNOUNCE(_LABEL_) cout << "---:" << STRINGIFY(_LABEL_) << endl; 129 if (0 < arg.size()) NUM_ELMS = lexical_cast<uint> (arg[1]);
131 VecI container = buildTestNumberz (NUM_ELMS);
132 RangeI iterator(container.begin(), container.end());
151 CHECK (
int(NUM_ELMS) ==container[0]);
154 CHECK (
int(NUM_ELMS) ==container[0]);
157 CHECK (90+
int(NUM_ELMS) ==container[0]);
170 template<
typename CO>
175 function<bool(int)> func(plainFunc);
179 for_each (coll, func); _NL_
181 and_all (coll, plainFunc); _NL_
182 and_all (coll, &plainFunc); _NL_
183 and_all (coll, func); _NL_
185 has_any (coll, plainFunc); _NL_
186 has_any (coll, &plainFunc); _NL_
187 has_any (coll, func); _NL_
194 template<
typename CO>
199 function<bool(int,int)> fun1(function1);
201 for_each (coll, function1, 10, _1 ); _NL_
202 for_each (coll, &function1,10, _1 ); _NL_
203 for_each (coll, fun1, 10, _1 ); _NL_
205 and_all (coll, function1, 10, _1 ); _NL_
206 and_all (coll, &function1, 10, _1 ); _NL_
207 and_all (coll, fun1, 10, _1 ); _NL_
209 has_any (coll, function1, 10, _1 ); _NL_
210 has_any (coll, &function1, 10, _1 ); _NL_
211 has_any (coll, fun1, 10, _1 ); _NL_
213 for_each (coll, function1, _1, _1 ); _NL_
214 for_each (coll, &function1,_1, _1 ); _NL_
215 for_each (coll, fun1, _1, _1 ); _NL_
217 and_all (coll, function1, _1, _1 ); _NL_
218 and_all (coll, &function1, _1, _1 ); _NL_
219 and_all (coll, fun1, _1, _1 ); _NL_
221 has_any (coll, function1, _1, _1 ); _NL_
222 has_any (coll, &function1, _1, _1 ); _NL_
223 has_any (coll, fun1, _1, _1 ); _NL_
245 template<
typename CO>
249 ANNOUNCE (assign_to_input);
250 function<bool(int,int,int&)> fun2(function2);
252 for_each (coll, function2, 5, 5, _1 ); _NL_
253 for_each (coll, &function2,5, 5, _1 ); _NL_
255 and_all (coll, function2, 5, 5, _1 ); _NL_
256 and_all (coll, &function2, 5, 5, _1 ); _NL_
258 has_any (coll, function2, 5, 5, _1 ); _NL_
259 has_any (coll, &function2, 5, 5, _1 ); _NL_
263 for_each (coll,fun2, 5, 5, _1 ); _NL_
264 and_all (coll, fun2, 5, 5, _1 ); _NL_
265 has_any (coll, fun2, 5, 5, _1 ); _NL_
272 ANNOUNCE (assign_to_var);
273 for_each (coll, function2, -10, _1, ref(sum) ); _NL_
274 for_each (coll, &function2,-10, _1, ref(sum) ); _NL_
275 for_each (coll, fun2, -10, _1, ref(sum) ); _NL_
276 cout <<
"sum=" << sum << endl;
279 and_all (coll, function2, -10, _1, ref(sum) ); _NL_
280 and_all (coll, &function2, -10, _1, ref(sum) ); _NL_
281 and_all (coll, fun2, -10, _1, ref(sum) ); _NL_
282 cout <<
"sum=" << sum << endl;
285 has_any (coll, function2, -10, _1, ref(sum) ); _NL_
286 has_any (coll, &function2, -10, _1, ref(sum) ); _NL_
287 has_any (coll, fun2, -10, _1, ref(sum) ); _NL_
288 cout <<
"sum=" << sum << endl;
295 template<
typename CO>
301 for_each (coll,function1, 10, _1 ); _NL_
302 and_all (coll, function1, 10, _1 ); _NL_
303 has_any (coll, function1, 10, _1 ); _NL_
305 for_each (coll,function1, _1, _1 ); _NL_
306 and_all (coll, function1, _1, _1 ); _NL_
307 has_any (coll, function1, _1, _1 ); _NL_
311 for_each (coll,function2, _1, _1, ref(sum) ); _NL_
312 and_all (coll, function2, _1, _1, ref(sum) ); _NL_
313 has_any (coll, function2, _1, _1, ref(sum) ); _NL_
326 return plainFunc (sum_);
331 template<
typename CO>
340 for_each (coll, &Dummy::fun, dummy, _1 ); _NL_
341 and_all (coll, &Dummy::fun, dummy, _1 ); _NL_
342 has_any (coll, &Dummy::fun, dummy, _1 ); _NL_
344 for_each (coll, &Dummy::fun, &dummy, _1 ); _NL_
345 and_all (coll, &Dummy::fun, &dummy, _1 ); _NL_
346 has_any (coll, &Dummy::fun, &dummy, _1 ); _NL_
348 cout <<
"sum=" << dummy.sum_ << endl;
353 template<
typename CO>
362 CHECK (sum == (NUM_ELMS+1) * NUM_ELMS/2);
364 CHECK (!
and_all (coll, [] (uint elm) {
return elm - 1; }));
365 CHECK (
has_any (coll, [] (uint elm) {
return elm + 1; }));
371 template<
typename CO>
377 CHECK (
and_all (coll, [] (uint elm) {
return 0 < elm; }));
378 CHECK (!
and_all (coll, [] (uint elm) {
return 1 < elm; }));
380 CHECK (
has_any (coll, [] (uint elm) {
return 0 < elm; }));
381 CHECK (
has_any (coll, [] (uint elm) {
return elm == NUM_ELMS; }));
382 CHECK (!
has_any (coll, [] (uint elm) {
return elm > NUM_ELMS; }));
391 bool operation() {
return plainFunc (n_); }
403 std::vector<TestElm> elms;
404 for (uint i=0; i<6; ++i)
407 std::vector<TestElm*> elmPtrs;
408 for (uint i=0; i<6; ++i)
409 elmPtrs.push_back (& elms[i]);
412 for_each (elmPtrs, &TestElm::operation, _1 ); _NL_
413 and_all (elmPtrs, &TestElm::operation, _1 ); _NL_
414 has_any (elmPtrs, &TestElm::operation, _1 ); _NL_
417 for_each (elms, &TestElm::operation, _1 ); _NL_
418 and_all (elms, &TestElm::operation, _1 ); _NL_
419 has_any (elms, &TestElm::operation, _1 ); _NL_
439 ANNOUNCE (wrapped_container_passing);
441 #define SHOW_CONTAINER for_each (coll, plainFunc); _NL_ 443 int counter = NUM_ELMS;
444 auto assign_and_decrement = [&] (
int&
entry)
450 VecI
const& passByConstRef (coll);
452 for_each (passByConstRef, assign_and_decrement );
456 CHECK (0 == counter);
459 for_each (buildTestNumberz(NUM_ELMS), assign_and_decrement );
464 for_each (bySmartPtr, assign_and_decrement );
468 CHECK (-2*
int(NUM_ELMS) == counter);
469 CHECK (bySmartPtr->back() == counter+1);
472 const VecI *
const passByConstPointer (&coll);
474 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()
Simple 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)