#include<iostream>#include<vector>#include<algorithm>//all_oftemplate<typenameT>classTest_std_algorithm{public:voidadd_vector_para(const T& a){
vec.push_back(a);}voidtest_all_of(){//all_of return true if pred returns true for all the elements in the range [first, last) or if the range is empty, and false otherwise.
std::cout << std::all_of(vec.begin(), vec.end(),[](T& i){return i %2;})<< std::endl;}voidtest_any_of(){//any_of return true if pred returns true for any of the element in the range [first, last) and false otherwise.
std::cout << std::any_of(vec.begin(), vec.end(),[](T& i){return i %2;})<< std::endl;}voidtest_sort(){//sort sorts the elements in the range [first, last) into ascending order.for(T& i : vec){
std::cout << i <<" ";}
std::cout << std::endl;
std::sort(vec.begin(), vec.end());for(T& i : vec){
std::cout << i <<" ";}
std::cout << std::endl;}voidtest_sort_gen_func(){
vec.push_back(10);for(T& i : vec){
std::cout << i <<" ";}
std::cout << std::endl;
std::sort(vec.begin(), vec.end(),::myclass_sort());for(T& i : vec){
std::cout << i <<" ";}
std::cout << std::endl;}voidtest_sort_func(){//sort func
vec.push_back(1);for(T& i : vec){
std::cout << i <<" ";}
std::cout << std::endl;
std::sort(vec.begin(), vec.end(),::myfunction_sort);for(T& i : vec){
std::cout << i <<" ";}
std::cout << std::endl;}voidtest_binary_search(){//sorted sequence//binary_search return true if any element in the range [first, last) is equivalent to val, and false otherwise
std::cout << std::binary_search(vec.begin(), vec.end(),2)<< std::endl;}private:
std::vector<T> vec;};boolmyfunction_sort(int& i,int& j){return(i < j);}//泛函数 重载()运算符实现structmyclass_sort{booloperator()(int& i,int& j){return(i < j);}};intmain(){//由于匿名函数的原因,测试all_of, any_of时,请用重载过%运算符的数据类型
Test_std_algorithm<int> test_std;for(int i =1; i <10; i++){
test_std.add_vector_para(i);}
test_std.add_vector_para(5);//test_std.test_all_of();//test_std.test_any_of();//test_std.test_binary_search();//test_std.test_sort();//test_std.test_sort_func();
test_std.test_sort_gen_func();system("pause");return0;}