【C++】template 統合スレ -- STL/Boost/Loki, etc.
■ このスレッドは過去ログ倉庫に格納されています
0483デフォルトの名無しさん
NGNGstd::setのメンバ関数のfindは使えないけど、こんなのはどうだ。
struct person {
int id;
std::string name;
person(int i, char* str) : id(i), name(str) {}
bool operator==(int i) const {
return id == i;
}
};
// 中略
int main()
{
PersonSet ps;
ps.insert(person(1, "def"));
ps.insert(person(5, "abc"));
PersonSet::iterator it = std::find(ps.begin(), ps.end(), 5);
std::cout << it->id << ' ' << it->name << std::endl;
}
■ このスレッドは過去ログ倉庫に格納されています