C++14 Generalized Lamda is an enhancement over C++11 Lamda feature. In previous article Lambda expression in C++11and C++14 we have discussed c++11 Lamda expression.  Let us see below simple example code and imagine what could be an issue.

The above code will print vector elements. The vector is containing integers, accordingly we have defined our lamda expression [](int n){ cout<<n<<endl;}. In The lamda syntax expression the (int n) has integer type parameter. So for the different parameters we have to modified lamda expression.

Lambda expression in C++11and C++14

In the above program if vector contains float or double data type the lamda expression would be [](float n){cout<<n<<endl;}. But there is C++14 enhancement over c++11 lamda. C++14  introduces generalized lamda expression. Basically we can use auto key word in C++14 lamda expression.  See below code using generalized lamda.

Note: the above code will compile as




Related Contents to follow