C++ lambdas can create closures and can be passed around in your code. - C++ STL

C++ examples for STL:Lambda

Introduction

Using a Lambda to Print array Values

Demo Code

#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>

int main()//from  w ww.  java  2 s  . co m
{
    using MyArray = std::array<int, 5>;
    MyArray myArray{ 1, 2, 3, 4, 5 };

    std::for_each(myArray.cbegin(), myArray.cend(),
        [](auto&& number) {
            std::cout << number << std::endl;
        });

    return 0;
}

Result


Related Tutorials