-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlambdas.cpp
More file actions
36 lines (33 loc) · 870 Bytes
/
lambdas.cpp
File metadata and controls
36 lines (33 loc) · 870 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
//*****************************************************************************
//
// Author: Michael Price
// License: Attribution-NonCommercial-NoDerivs 3.0 Unported
// http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode
//
//*****************************************************************************
#ifndef WIN32
namespace std {
class out {}; out cout; int endl;
out& operator<<(out & o, int t) { return o; }
}
#endif // WIN32
template <typename TyContainer, typename TyPred>
void print_if (const TyContainer & container,
TyPred && predicate)
{
for (auto thing : container)
{
if (predicate(thing))
{
std::cout << thing << std::endl;
}
}
}
void printapalooza ()
{
int some_ints[5] = {0, 1, 2, 3, 4};
print_if(some_ints, [] (int i)
{
return i%2;
});
}