- Good website to learn lambda in c++:
https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp
https://en.cppreference.com/w/cpp/language/lambda
https://www.geeksforgeeks.org/lambda-expression-in-c/
https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11
https://linuxhint.com/lambda-expressions-in-c/
[ captureClause ] ( parameters ) -> returnType
{
statements;
}
#include <iostream>
using namespace std;
bool isGreater = [](int a, int b){ return a > b; }
int main() {
cout << isGreater(5, 2) << endl; // Output: 1
return 0;
}
//lambda function for sorting vector ascending
sort(vec.begin(),vec.end(),[](int &a, int &b){
return a<b;
});
//lambda function for sorting vector of vector ascending based on first value
sort(vec.begin(),vec.end(),[](vector<int> &a, vector<int> &b){
return a[0]<b[0];
});