C++

Lambda functions


int main(int argc, char **argv)
{

std::string A = "Steve";
std::string B = "James";


// A + B declared outside of Lamdba so must be in capture list.
[A,B]( std::string a,std::string b) {
    std::cout << "Concatenated strings: "<< A << " " << B; << std::endl;

}(A,B);

}

you can also specify output or use a lambda function in line.


int main(int argc, char **argv)
{

// A + B declared outside of Lamdba so must be in capture list.
std::cout << []()->std::string{
    std::string A = "Steve";
    std::string B = "James";
    std::string C = (A + " " + B);
    return C;
}() << std::endl;


}

You can also name lambda functions as such:


test = [](){std::cout << "Hello" << std::endl"};

Note the capture list can capture everything of the parent scop by using [=] or [&] to capture everyhing by reference.