#include<iostream>
#include<list>
#include <algorithm>
#include <vector>
#include <memory>
using namespace std;
class Cperson
{
public:
Cperson(int ag){age=ag;}
~Cperson(void){age=0;
}
/*bool isreal(Cperson callback){
return this->age==callback.age;
} */
bool operator() (Cperson callback)
{
cout << "callback.age "<<callback.age << endl;
return this->age==callback.age;
}
public:
int age; // 年龄
};
int main()
{
Cperson* person1 =new Cperson(7);
Cperson* person2 =new Cperson(2);
Cperson* person3 =new Cperson(3);
//Cperson stu1(1);
list<Cperson*> lst;
lst.push_back(person1);
lst.push_back(person2);
lst.push_back(person3);
auto it = find(lst.begin(),lst.end(),person1);//find返回的是指针的指针
Cperson it1 = **it;
if (it != lst.end()) {
//cout << it1.age << endl;
}
vector<int> lstint;
lstint.push_back(8);
lstint.push_back(9);
lstint.push_back(10);
auto it2 = find(lstint.begin(),lstint.end(),8);
if (it2 != lstint.end()) {
//cout << *it2 << endl; //find返回的是对象的指针
}
Cperson person4(11),person5(12),person6(13);
list<Cperson> lstperson;
lstperson.push_back(person4);
lstperson.push_back(person5);
lstperson.push_back(person6);
//auto it = find(lstperson.begin(),lstperson.end(),person4); //报错,对象无法==比较
auto it3 = find_if(lstperson.begin(),lstperson.end(),[person5](Cperson callback)->bool {return person5.age==callback.age; });
Cperson it33 = *it3;
if (it3 != lstperson.end()) {
cout << "lamdba "<<it33.age << endl;
}
auto it4 = find_if(lstperson.begin(),lstperson.end(),person5);
Cperson it44 = *it4;
if (it4!= lstperson.end()) {
cout << "operator "<<it44.age << endl;
}
auto it5 = find_if(lstperson.begin(),lstperson.end(),Cperson(person6));
Cperson it55 = *it5;
if (it4!= lstperson.end()) {
cout << "fun "<<it55.age << endl;
}
for_each(lstperson.begin(),lstperson.end(),person6);
for_each(lstperson.begin(),lstperson.end(),[](Cperson callback)->bool {return callback.age; });
delete person1;
delete person2;
delete person3;
//*it =20;
//cout << it1.age << endl;
return 0;
}