|
Boost : |
Subject: Re: [boost] RangeEx review
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-03-01 09:52:33
Phil Endecott wrote:
> - It would be good if the docs were explicit about this being a thin
> wrapper around your existing std::sort, and identifying those algorithms
> that are not so thin.
Actually, I believe sort(c) calls c.sort() if it exists.
So it's not just std::sort.
> You then have this example for sorting and removing duplicates:
>
> boost::erase( vec, boost::unique<boost::return_found_end>(
> boost::sort(vec) ) );
>
> Err... yuk. Why can't I write:
>
> unique(vec);
>
> Or maybe
>
> unique(sort(vec));
>
> or
>
> sort(vec);
> unique(vec);
>
> My point is that std::unique only has its "move duplicates to the end"
> behaviour because the conventional interface with a pair of iterators
> doesn't let you change the size of the container. Now that we have a
> unique() that takes a container we don't need that restriction.
Not a container, a range.
You can't remove elements from a range, only move those to the end and
change the end.
However, uniqued(vec) returns a new lazy range without duplicates (if
the range is sorted), and unique_copy(vec) returns a new range without
duplicates.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk