#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class GreaterThen20 {

public:
bool operator()(int value) {
return value > 20;
}
};

void test01() {

vector<int> v;
v.push_back(10);
v.push_back(20);
v.push_back(30);
v.push_back(40);
v.push_back(50);

vector<int>::iterator position = find_if(v.begin(), v.end(), GreaterThen20());
if (position != v.end()) {
cout << "找到大于 20 的数: " << *position << endl;
} else {
cout << "未找到" << endl;
}
}

class MyCompare {

public:
bool operator()(const int value1, const int value2) {
return (value1 > value2);
}

};

void test02() {
vector<int> v;
v.push_back(10);
v.push_back(20);
v.push_back(30);
v.push_back(40);
v.push_back(50);

sort(v.begin(), v.end(), MyCompare());

// 匿名函数: lambda 表达式 [](){};
for_each(v.begin(), v.end(), [](int value) {cout << value << " "; });
}


int main() {

//test01();

test02();

return EXIT_SUCCESS;
}