Lambda Function:
Basically, in C++ lambda expression are used to write the inline function.
-Return type of lambda expression are evaluated by compiler itself.
Syntax-
capture_clause(parameters)->return-type
{
definition of method
}
program:
#include < bits/stdc++.h>
using namespace std;
//Display vector function
void printVector(vector< int> v)
{
// lambda expression to print vector
for_each(v.begin(), v.end(), [](int i)
{
std::cout << i << " ";
});
cout << endl;
}
int main()
{
vector
printVector(v);
}
4 1 3 5 2 3 1 7