Boost logo

Boost Users :

From: Jiri Palecek (jpalecek_at_[hidden])
Date: 2006-01-31 07:57:29


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<set<X> >::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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net