#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <functional>
using namespace std;
//类
struct tmp1{
int t;
void operator()(int i){
cout<<i<<endl;
}
}t;
struct tmp2{
int t;
tmp2(int x=0):t(x){}
void operator()(int i){
if(i<t)cout<<i<<endl;
}
};
struct tmp3{
int i;
tmp3(int a):i(a){}
void func(int t){
if(i<t)cout<<i<<endl;
}
bool operator<(tmp3 &t){
return i<t.i;
}
};
//函数
void f1(int i){
cout<<i<<endl;
}
void f2(int i,int t){
if(i<t)cout<<i<<endl;
}
void f3(tmp3 i,tmp3 t){
if(i<t)cout<<i.i<<endl;
}
//模版
template<typename T, T t>
void print(T i) {
if(i<t)cout<<i<< endl;
}
int main(){
array<int,8> test = {3,5,7,11,13,17,19,23};
//for_each(test.begin(),test.end(),f1);
//for_each(test.begin(),test.end(),t);for_each(test.begin(),test.end(),[](int i){cout<<i<<endl;});
//for_each(test.begin(),test.end(),bind2nd(ptr_fun(f2),15));//输出小于15的数
//for_each(test.begin(),test.end(),tmp2(15));//输出小于15的数
//容器中存的是结构体的处理方法
vector<tmp3> t3;
t3.push_back(tmp3(23));
t3.push_back(tmp3(33));
//for_each(t3.begin(),t3.end(),bind2nd(ptr_fun(f3),30));
//for_each(t3.begin(),t3.end(),bind2nd(mem_fun_ref(&tmp3::func),30));//输出小于30的两个类中的数
//使用模版的处理
for_each(test.begin(),test.end(),print<int,15>);//输出小于15的数
return 0;
}