forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.42.cpp
26 lines (21 loc) · 775 Bytes
/
14.42.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
#include <functional>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
int main() {
using namespace std::placeholders;
std::vector<int> vi { 1000, 2000, 3000, 4000, 5000 };
std::cout << std::count_if(vi.begin(), vi.end(),
std::bind(std::greater<int>(), _1, 1024)) << std::endl;
std::vector<std::string> vs { "pooh", "pooh", "abc", "pooh" };
std::cout << *std::find_if(vs.begin(), vs.end(),
std::bind(std::not_equal_to<std::string>(), _1, "pooh")) << std::endl;
std::transform(vi.begin(), vi.end(), vi.begin(),
std::bind(std::multiplies<int>(), _1, 2));
//std::for_each(vi.begin(), vi.end(), [](int &i) { i *= 2; });
for (const auto &i : vi)
std::cout << i << ' ';
std::cout << std::endl;
return 0;
}