... 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.
Line 11 declares and initializes the
values and line 15 displays its contents. Lines 19–20 call the