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 63 64 65 66 67 68 69 70 71 72 73 74
| #include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <binders.h> #include <functional>
using namespace std;
int main() { vector<int> ivec{1, 3, 2, 0, 3, 5, 12, 4, 4, 4, 6, 6, 7, 6, 20}; vector<string> svec{"apple", "test", "god", "dog", "dog", "json", "orange"};
cout << *std::adjacent_find(ivec.begin(), ivec.end()) << endl; cout << *std::adjacent_find(svec.begin(), svec.end()) << endl; cout << *std::adjacent_find(svec.begin(), svec.end(), [](const string & left, const string & right) { return left.size() == right.size(); }) << endl;
cout << std::count(ivec.begin(), ivec.end(), 3) << endl; cout << std::count_if(ivec.begin(), ivec.end(), std::bind(std::less<int>(), std::placeholders::_1, 10)) << endl;
cout << std::boolalpha << std::binary_search(ivec.begin(), ivec.end(), 400) << endl;
cout << *std::lower_bound(ivec.begin(), ivec.end(), 8) << endl; cout << *std::upper_bound(ivec.begin(), ivec.end(), 8) << endl; auto pairIt = std::equal_range(ivec.begin(), ivec.end(), 6); cout << *pairIt.first << endl; cout << *pairIt.second << endl;
cout << *std::find(ivec.begin(), ivec.end(), 12) << endl; cout << *std::find_if(ivec.begin(), ivec.end(), std::bind(std::greater<int>(), std::placeholders::_1, 12)) << endl;
std::vector<int> ivec1{12, 20}; cout << "search:" << *std::search(ivec.begin(), ivec.end(), ivec1.begin(), ivec1.end()) << endl; cout << "search_n:" << *std::search_n(ivec.begin(), ivec.end(), 2, 6) << endl;
return 0; }
|