|
Boost : |
From: John E. Potter (jpotter_at_[hidden])
Date: 2000-11-25 11:21:51
On Sat, 25 Nov 2000, John Maddock wrote:
> >lower_bound(ForIter first, ForIter last, T value)
> >
> >The standard says T must be LessThanComparable. As I mentioned
> >before, this is somewhat irrelevant unless we also add the
> >requirement that iterator_traits<ForIter>::value_type is
> >the same type as T... but I don't think we want to add that.
>
> That isn't required: we only require that T be convertible to
> iterator_traits<ForIter>::value_type,
We are talking about lower_bound? The only requirement to write the
algorithm is iterator_traits<ForwardIterator>::value_type < T. Since
there is only one object of type T available to the algorithm, it is
nonsense to require T to be less than comparable. Conversions are
evil and requiring one is bad. It is much more likely that value_type
could be converted to T anyway.
> if someone wants to add extra
> signatures to the comparison operator to avoid unnecessary coversions then
> that's OK, but I don't see LessThanComparable2<A,B> as being required here
> (although it can't do any harm).
Requiring anything that is not required does much harm. It makes the
library harder to use for no reason. It is possible to write lower_bound
using T < value_type and value_type < value_type and maybe even T < T,
but the streight forward algorithm uses none of them and is optimal.
Please stop trying to check concepts that do not exist. If the
standard has a meaningless requirement, fix the standard, do not break
the library.
John
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk