-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambdaa.cpp
More file actions
36 lines (23 loc) · 733 Bytes
/
lambdaa.cpp
File metadata and controls
36 lines (23 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
using std::cout;
int main()
{
//simple lambda
auto fun = [](){cout<< "Hello From lamba\n"; };
//annonymus fun
[](){cout << "Hello from annonymus\n"; }();
//with arg
[](int a, int b){cout<<"a + b = "<<a+b <<'\n'; }(6,4);
//returning lambda
cout<<"The Sum is :" << [](int a, int b) -> int { return a+b; }(8,9)<<'\n';
// capture
int a{7}; int b{3};
[a,b](){cout << "A and B are : "<<a <<" "<<b <<'\n'; }();
// capture all
[=](){cout << "A and B are : "<<a <<" "<<b <<'\n'; }();
//capture all by ref
[&](){cout << "A+1 and B+1 are : "<<a++ <<" "<<b++ <<'\n'; }();
cout<<"New A and B are : "<<a <<" "<<b <<'\n';
fun();
return 0;
}