forked from Drishty06/STL-Functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlamda_function.cpp
17 lines (16 loc) · 889 Bytes
/
lamda_function.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Used for: avoiding user defined function long syntax
// syntax: [_capture clause_] (_parameters_) {return _value_ ;}
// return value: just like the return value of UDF.
// code snippet:
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout<< [] (int x, int y) {return x+y;} (2,3); // here 2 and 3 are the values just like we used to pass to a UDF
//answer = 5
}
// this was a small code snippet but lambda functions can sometimes save a lot of time.
// there are some other benefits of lambda functions as well which is because of the capture clause
// along with this, we can use lambda functions for a comparators as well
// do checkout to following for the same : 1. https://www.geeksforgeeks.org/lambda-expression-in-c/
// 2. https://www.youtube.com/watch?v=o-WpVoRgSj4&list=PLauivoElc3gh3RCiQA82MDI-gJfXQQVnn&index=18