Lumiera  0.pre.03
»edit your freedom«
UtilForeach_test Class Reference

Description

Test:
Invoking an operation for each element of a collection.

Covers the various flavours of these convenience helpers: They might operate either on a STL container (providing begin() and end() functions), or at a "Lumiera Forward Iterator", which is incremented and dereferenced for each value it yields, until exhaustion.

Moreover for each of these cases, there are additional overloads allowing to create a bind-expression on-the fly. As a further variation of this scheme, an predicate can be evaluated for each element, either with universal quantisation (results are && combined), or with existential quantisation.

Definition at line 123 of file util-foreach-test.cpp.

Classes

struct  Dummy
 
struct  TestElm
 

Private Member Functions

template<typename CO >
void check_existence_quant (CO coll)
 
template<typename CO >
void check_foreach_bind (CO coll)
 
template<typename CO >
void check_foreach_bind_const (CO const &coll)
 
template<typename CO >
void check_foreach_lambda (CO coll)
 
template<typename CO >
void check_foreach_memFun (CO coll)
 
template<typename CO >
void check_foreach_plain (CO coll)
 
void check_invoke_on_each ()
 
template<typename CO >
void check_ref_argument_bind (CO coll)
 
void check_wrapped_container_passing (VecI coll)
 
void run (Arg arg)
 

Member Function Documentation

◆ check_foreach_plain()

void check_foreach_plain ( CO  coll)
inlineprivate
Test:
invoke a simple free function, given as reference, function pointer or functor.

The invoked test function will print its argument

Definition at line 172 of file util-foreach-test.cpp.

◆ check_foreach_bind()

void check_foreach_bind ( CO  coll)
inlineprivate
Test:
bind additional parameters on-the-fly, including the possibility to use a placeholder to denote the position of the variable parameter

Definition at line 196 of file util-foreach-test.cpp.

◆ check_ref_argument_bind()

void check_ref_argument_bind ( CO  coll)
inlineprivate
Test:
under some circumstances, it is even possible to take a ref to the data in the input sequence, or to a summation variable.

In the example performed here, the function to be applied takes the 3rd argument by reference and assigns the sum of first and second argument to this parameter. If we us a bind variable at that position, we end up assigning by reference to the values contained in the collection.

Note
in case of invoking this test with a Lumiera Forward Iterator, the changes go through to the original container, in spite of passing the iterator by value. This behaviour is correct, as an iterator is an reference-like object

Definition at line 247 of file util-foreach-test.cpp.

◆ check_foreach_bind_const()

void check_foreach_bind_const ( CO const &  coll)
inlineprivate
Test:
the input sequence can be also taken from a const container (for iterators this obviously doesn't make sense

Definition at line 297 of file util-foreach-test.cpp.

◆ check_foreach_memFun()

void check_foreach_memFun ( CO  coll)
inlineprivate
Test:
bind a member function to be invoked for each element

Definition at line 333 of file util-foreach-test.cpp.

◆ check_foreach_lambda()

void check_foreach_lambda ( CO  coll)
inlineprivate
Test:
use lambda-expressions, to be invoked for each element

Definition at line 355 of file util-foreach-test.cpp.

◆ check_existence_quant()

void check_existence_quant ( CO  coll)
inlineprivate
Test:
verify the logic of universal and existential quantisation.

Using lambda expressions as predicates

Definition at line 373 of file util-foreach-test.cpp.

◆ check_invoke_on_each()

void check_invoke_on_each ( )
inlineprivate
Test:
the binding can also be used to dispatch an operation on each element within a object collection: here the parameter is used as this pointer to specify the object instance

Definition at line 399 of file util-foreach-test.cpp.

◆ check_wrapped_container_passing()

void check_wrapped_container_passing ( VecI  coll)
inlineprivate
Test:
pass the collection to be iterated in various ways
  • anonymous temporary
  • smart pointer
  • pointer
  • const&
Note
We do modifications using a lambda expression with a side-effect. The container passed in is always modified, disregarding const! (In case of the anonymous temporary the modifications get discarded after reaching the end of the for_each expression

Definition at line 437 of file util-foreach-test.cpp.

+ Inheritance diagram for UtilForeach_test:
+ Collaboration diagram for UtilForeach_test:

The documentation for this class was generated from the following file: