【C++】template 統合スレ -- STL/Boost/Loki, etc.
レス数が900を超えています。1000を超えると表示できなくなるよ。
0916915
NGNGtemplate<class Collection>class Inserter {
private:
Collection *container;
public:
Inserter(Collection &c) { container = &c; }
void operator()(const typename Collection::value_type &v)
{
(*container).insert(v);
}
};
coll.insert の代わりに Inserter< set<string> >(coll) と書けば
できたけど、なんか納得いかないというか、イマイチGenericじゃない
気がしてる。実際、for_eachを手で展開して
istream_iterator<string> in(cin);
while (in != istream_iterator<string>())
coll.insert(*in++);
とすれば動くだけに、なんかクヤしい。
なんか良い手ないかしら?
レス数が900を超えています。1000を超えると表示できなくなるよ。