C++ allows us to use inline functions like we use in Python .
Let's see the expression of Lambda Functions :
auto lambdas = [ capture clause ] (parameters) -> return-type {
definition of method ...
}
Implementation of Simple Lambda Function:
#include "iostream"
#include "vector"
int main(){
auto lambda = [](int value) -> int{
return value;
};
std::cout << "value : " << lambda(10) << std::endl ;
return 0;
};
Passing Lambda Functions into another Function and passing Values :
#include "iostream"
#include "vector"
void ForEachFunc( const std::vector<int>& values , int(*func)(int) ){
for (auto i : values){
std::cout << "Value : " << func(i) << std::endl;
};
};
int main(){
std::vector<int> values = {1,4,5,2,3,6};
auto lambda = [](int value) -> int{
return value;
};
ForEachFunc(values , lambda);
return 0;
};
If You like my posts then please Follow Me .