-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path37.cpp
More file actions
62 lines (36 loc) · 1.73 KB
/
Copy path37.cpp
File metadata and controls
62 lines (36 loc) · 1.73 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
// LAMBDA FUNCTION, ALL_OF, ANY_OF AND NONE_OF FUNCTIONS
bool is_positive(int x){
return x>0;
}
int main() {
// lambda function
// cout<<[](int x, int y){return x+y;}(3, 4)<<endl;
// auto sum = [](int x, int y){return x+y;};
// cout<<sum(2,3)<<endl;
// all_of function returns true only if all of the elements return true otherwise false
// // vector<int> v = {2, 3, 4};
// vector<int> v = {2, -1, 4};
// // cout<<all_of(v.begin(),v.end(), is_positive);
// cout<<all_of(v.begin(),v.end(), [](int x){ return x > 0;}); // all elements positive
// any_of function returns true if any one element returns true, if all elements return false then only it will return false
// // vector<int> v = {-2, -3, 4};
// vector<int> v = {-2, -3, -4};
// cout<<any_of(v.begin(),v.end(), [](int x){ return x > 0;}); // any one positive
// none_of function returns true only when all elements return false
// // vector<int> v = {2 ,3 , 4}; //0
// vector<int> v = {-2 ,-3 , -4}; //1
// cout<<none_of(v.begin(), v.end(), [](int x){return x>0;}); // none of positive
// similarly we can do this for arrays as well
// // vector<int> v = {2, 3, 4}; //0
// vector<int> v = {2, 4}; //1
// cout<<all_of(v.begin(),v.end(), [](int x){ return x % 2 == 0;}); // all elements even
// // vector<int> v = {2, 3, 4}; //1
// vector<int> v = {3, 5}; //0
// cout<<any_of(v.begin(),v.end(), [](int x){ return x % 2 == 0;}); // any one element even
// vector<int> v = {2, 3, 4}; //0
// vector<int> v = {3, 5}; //1
// cout<<none_of(v.begin(),v.end(), [](int x){ return x % 2 == 0;}); // none of element even
return 0;
}