Boost logo

Boost Users :

Subject: Re: [Boost-users] best way to remove duplicates from forwardIterator [startIter, endIter]
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-02-26 11:48:21


>
> Thanks Ovanes,
> This would be better that what i have currently. However the bigger
> problem was to avoid explicitly creating storage. As Dave mentioned if
> sort was supported over forward iterators (and not bidirectional
> iterators) then duplicate removal could have been expressed more
> directly.
> -sandeep

Sandeep,

that with storage depends on how you are going to solve your problem. You
might use boost::iterator_adaptor to put an iterator ontop of your
ForwardIterator range and deal with iteratos only. That might be cheaper
instead of createing set of value_types create a set of iterators.
Overloading your own less then operator might compare
boost::iterator_adaper-specialization instances which are than stored in
std::set. Set will only contain iterators and not real object instances.
This assumes that your input range lives long enough.

Or you can intorduce a filter_iterator which might implement a sort of lazy
unique iterator. So it might contain a set with objects already iterated
though and decide whether to skip to the next element when incremented or
not.

Hope that helps,
Ovanes



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