![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Templates and The Standard Library - slide 34 : 39 |
In C++ for-each is an algorithm, not a control structure like foreach in C#
C++ 2011 has introduced a 'range based for loop' similar to foreach in C#
// The C++ Programming Language, 3ed, page 524. // Possible definition of the for_each function template. template <class In, class Op> Op for_each(In first, In last, Op f){ while (first != last) f(*first++); return f; }
![]() | Implementation and sample use of for-each on a list of integers. |