Boost logo

Boost :

From: John E. Potter (jpotter_at_[hidden])
Date: 2000-12-01 07:57:57

On Wed, 29 Nov 2000, Matthew Austern wrote:

> Or to be more precise about what I'm claiming to be legal:
> - It's required that T must be EqualityComparable.

Can we agree that is a bug?

> - I don't think it's required that the operator== that find()
> uses must be the same one that's used when comparing
> one T to another.

Or even that the other one exist.

> (This is where I see a difference
> between find() and lower_bound(). For lower_bound, the
> algorithm requires a relationship between the comparison
> used for sorting the list and the comparison used for
> the earch.)

Agreed. T does not need to be less than comparable.

Requires: For each iterator i in [first, last) if *i < value or
comp(*i, value) != false, then for each iterator j in [first, i]
*j < value or comp(*j, value) != false, otherwise for each iterator
j in [i, last) ! (*j < value) or comp(*j, value) == false.

That is what is required, is it standard-easy enough? Is the otherwise
part redundant?

If you want to extract this from lower_bound and its counterpart from
upper_bound and generalize to include equal_range and binary_search
in the union which allows the compare in either direction, it should
not be much of a hardship on the user. I generally write both of
the operators simply because it is quicker than figuring out which
one I need for lower_bound. If I should find upper_bound useful later,
it is ready. Those who like to use a function pointer rather than a
function object may object to the extra requirement on lower_bound
and upper_bound.


Boost list run by bdawes at, gregod at, cpdaniel at, john at