#include <iostream>
#include <string>
#include <vector>
#include <functional>
class MianShiZhe {
public:
virtual std::string info() = 0;
};
class Age18_22 : public MianShiZhe {
public:
Age18_22(std::string name,std::string info):name_(name),info_(info){}
std::string info() {
return name_ + ":" + info_;
}
private:
std::string name_;
std::string info_;
};
class Age22_26 : public MianShiZhe {
public:
Age22_26(std::string name,std::string info):name_(name),info_(info){}
std::string info() {
return name_ + ":" + info_;
}
private:
std::string name_;
std::string info_;
};
class Age26_40 : public MianShiZhe {
public:
Age26_40(std::string name,std::string info):name_(name),info_(info){}
std::string info() {
return name_ + ":" + info_;
}
private:
std::string name_;
std::string info_;
};
class SaiXuan {
public:
virtual std::vector<MianShiZhe*> SaiJianLi(std::vector<MianShiZhe*> ) = 0;
};
using TiaoJian = std::function<bool(MianShiZhe*)>;
class MianShiGuan : public SaiXuan {
public:
MianShiGuan(TiaoJian tiaojian):tiaojian_(tiaojian){}
std::vector<MianShiZhe*> SaiJianLi(std::vector<MianShiZhe*> jianli) {
std::vector<MianShiZhe*> temp;
for (auto mianshizhe:jianli) {
if(tiaojian_(mianshizhe)) {
temp.emplace_back(mianshizhe);
}
}
return temp;
}
private:
TiaoJian tiaojian_;
};
int main() {
std::vector<MianShiZhe*> gangwei;
gangwei.emplace_back(new Age18_22("xiaoli","19,gaozhong,1nian"));
gangwei.emplace_back(new Age26_40("xiaosi","18,yanjiusheng,1nian"));
gangwei.emplace_back(new Age22_26("xiaomi","24,benke,2nian"));
SaiXuan* zuzhang = new MianShiGuan([](MianShiZhe* jianli){
auto info = jianli->info();
return info.npos != info.find("2nian");
});
auto ret = zuzhang->SaiJianLi(gangwei);
for(auto i:ret) {
std::cout << i->info() << std::endl;
}
}