-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_test.cpp
More file actions
56 lines (45 loc) · 1.15 KB
/
lambda_test.cpp
File metadata and controls
56 lines (45 loc) · 1.15 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
///
/// @file
// Created by Praveenkumar Karunakaran on 24.04.19,
///
#include <iostream>
#include <vector>
#include <algorithm>
#include <typeinfo>
#include <array>
using namespace std;
namespace ct
{
/*
auto find_first_multiple(const vector<int>& vi,const int& i)
{
return find_if(begin(vi),end(vi),[i](int x){return x%i==0;});
}
*/
template<typename T,typename Container>
auto find_first_multiple(const Container& C,const T& i)
{
return find_if(begin(C),end(C),[i](T x){return x%i==0;});
}
}
int main ()
{
using namespace ct;
vector<int> vi{3, 5, 4, 12, 15, 7, 9};
int vi1[]= {3, 5, 4, 12, 15, 7, 9};
for (int i= 2; i < 10; ++i) {
auto it= find_first_multiple(vi1, i);
if ( it != end(vi1))
cout << "The first multiple of " << i << " is " << *it << endl;
else
cout << "There is no multiple of " << i << endl;
}
for (int i= 2; i < 10; ++i) {
auto it= find_first_multiple(vi, i);
if ( it != end(vi))
cout << "The first multiple of " << i << " is " << *it << endl;
else
cout << "There is no multiple of " << i << endl;
}
return 0;
}