Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 lambda function - how to pass parameter

Tags:

People also ask

How do you pass a lambda function as a parameter?

Passing Lambda Expressions as Arguments You can pass lambda expressions as arguments to a function. If you have to pass a lambda expression as a parameter, the parameter type should be able to hold it. If you pass an integer as an argument to a function, you must have an int or Integer parameter.

What is the correct syntax for lambda expression in C++11?

Lambdas can both capture variables and accept input parameters. A parameter list (lambda declarator in the Standard syntax) is optional and in most aspects resembles the parameter list for a function. auto y = [] (int first, int second) { return first + second; };

Can lambda functions take parameters?

A lambda function can have any number of parameters, but the function body can only contain one expression.

What does [=] mean in lambda function?

The [=] you're referring to is part of the capture list for the lambda expression. This tells C++ that the code inside the lambda expression is initialized so that the lambda gets a copy of all the local variables it uses when it's created.


I used lambda function to pass it to std::condition_variable wait() function, but that is not the case. I use lambda functions that don't receive any parameters, and everything is absolutely clear for me. But I totally don't understand how is used lamdba function that have parameters list. Show lambda with parameters are used? How to pass parameters to them?