forked from teseoch/CPP-Fall-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path112-lambda4.cpp
40 lines (34 loc) · 964 Bytes
/
112-lambda4.cpp
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
#include <iostream>
#include <vector>
#include <functional>
void for_each(std::vector<int> const &V, std::function<void(int)> element_function)
{
for (auto x : V)
element_function(x);
}
/* Given a vector of ints and an element, return true if the provided
element appears in the vector and false otherwise. */
bool search(std::vector<int> const &V, int element)
{
//Task write this function without any loops
}
int main()
{
std::vector<int> V{6, 10, 17};
std::cout << "Does V contain 6? ";
if (search(V, 6))
std::cout << "Yes." << std::endl;
else
std::cout << "No." << std::endl;
std::cout << "Does V contain 10? ";
if (search(V, 10))
std::cout << "Yes." << std::endl;
else
std::cout << "No." << std::endl;
std::cout << "Does V contain 187? ";
if (search(V, 187))
std::cout << "Yes." << std::endl;
else
std::cout << "No." << std::endl;
return 0;
}