for_each (Since C++11)

#include <iostream>
int main()
{
    auto print = [](int num) { std::cout << num << std::endl; };
    std::array<int, 4> arr = {1, 2, 3, 4};
    std::for_each(arr.begin(), arr.end(), print);
    return 0;
}
Comments