C++ Lambda Expressions Generic Lambdas

Introduction

We can use auto parameters in lambda functions now.

The type of the parameter will be deduced from the value supplied to a lambda function.

This is also called a generic lambda:

#include <iostream> 

int main() //from  w w w .  ja v a 2 s  .co m
{ 
    auto mylambda = [](auto p) {std::cout << "Lambda parameter: " << p << '\n'; }; 
    mylambda(123); 
    mylambda(3.14); 
} 



PreviousNext

Related