...one of the most highly
regarded and expertly designed C++ library projects in the
world. — Herb Sutter and Andrei
The syntax is:
for_(init_statement, conditional_expression, step_statement) [ sequenced_statements ]
It is again very similar to the C++ for statement. Take note that the init_statement,
conditional_expression and step_statement are separated by the comma instead of the semi-colon
and each must be present (i.e.
for_(,,) is invalid). This is a case where the
actor can be useful.
Example: This code prints each element N times where N is the element's value. A newline terminates the printout of each value.
int iii; std::for_each(c.begin(), c.end(), ( for_(ref(iii) = 0, ref(iii) < arg1, ++ref(iii)) [ cout << arg1 << ", " ], cout << val("\n") ) );
As before, all these are lazily evaluated. The result of such statements
are in fact expressions that are passed on to STL's for_each function.
In the viewpoint of
what was passed is just a functor, no more, no less.