Hello,
I have recently tried to implement merging of more lists (or union of more
sets). The (somewhat silly) approach would be
set<X> ret,ret2;
for(list::iterator it=sets.begin(),end=sets.end();it!=end;++it) {
set_union(ret.begin(),ret.end(),it->begin(),it->end(),inserter(ret2));
ret.clear();
swap(ret,ret2);
}
and ret is the result. However, it seems to me that these temporaries
are unnecessary. So I wonder wheter there could/should be some class of
iterators that implemented some STL algorithms. There is already an
iterator that could replace the unary version of transform (transform_iterator)
In my case, I'm talking about some merge_iterator that would merge two
sorted sequences (being an input iterator). That is,
copy(merger(a.begin(),a.end(),b.begin(),b.end()),ostream_iterator(cout))
would be equivalent to
merge(a.begin(),a.end(),b.begin(),b.end(),ostream_iterator(cout))
and similarly for set_union etc.
Is it possible to have such iterators?
Sincirely
Jiri Palecek