Boost logo

Boost Users :

Subject: [Boost-users] [range] unique
From: Bill Buklis (boostusr_at_[hidden])
Date: 2012-02-22 19:31:05

This may simply be my lack of understanding of the range library as I'm
still just working my way through the algorithms, but is boost::unique
returning the correct result range?

Given that std::unique returns an iterator to the first non-unique value
you can do something like:

vec.erase( std::unique(vec.begin(), vec.end(), vec.end() );

However, boost::unique returns the range of the "unique" values. I would
expect instead that it would return the range of non-unique values so
that it matched the standard algorithm version, which effectively
returns the range of non-unique values. Correspondingly trying:

boost::erase( vec, boost::unique(vec) );

eliminates the complete opposite of what the standard version does. I
can get around this by calling:

vec.erase( boost::unique(vec).end(), vec.end() );

but this seems rather counter-intuitive to me.

Is this correct? Is this by intent? What is the benefit of having it
this way? The documentation doesn't mention anything at all about the
return range in the description. Since I'm still just beginning to use
the range library, I don't know all the tricks and benefits yet, so I ask.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at