... call with each element in the range. The function must have one parameter of the container’s element type. for_each passes the current element’s value as the function’s argument, then the function performs a task using that value. As you’ll see momentarily, this example’s for_each calls each receive as their third argument a lambda representing a function that receives one argument and performs a task with that argument’s value. If the function’s parameter is a non-const reference and the iterators passed to for_each refer to non-const data, the function can modify the element.

16.3.2 Lambda with an Empty Introducer

Line 11 declares and initializes the array of ints named values and line 15 displays its contents. Lines 19–20 call the for_each ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.