Mental wrote:I didn't know how to pass a brace-block into a function...what are inline function templates?
That's basically a closure, which is not supported in C++. But you can get the same effect using function objects. An inline function template is a function that takes template parameters and is inlined at compile time so there's no function call overhead.
<tt>std::for_each</tt> is generally implemented as
Code: Select alltemplate <class Iterator, class Function>
inline for_each(Iterator first, Iterator last, Function f)
{
for ( ; first != last; ++first)
f(*first);
return f;
}
This applies <TT>f</TT> to each element in the sequence defined by [<tt>first</tt>, <TT>last</TT>). Since the type of iterator is a template parameter, this function works on native arrays (where the iterators are simply pointers) or on containers (where the iterators are objects with <TT>*</TT>, <TT>!=</TT>, and pre-<TT>++</TT> defined). Further, since the type of the function is a paremeter, it works on any function reference of a function object. (A function object is an object which has the application operator, <TT>()</TT>, defined.)