Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2002-09-06 09:01:10


Peter Dimov wrote:
> Once you decouple std::less from operator<, you now need to always define a
> less<> specialization in terms of less<> whenever you would define an
> operator< in terms of operator<.

Right. This settles it for me. std::less should be an alias for
operator<. And, my belief is that if you want to put intervals in a
std::set, you need std::less to be a total ordering. A strict weak
ordering isn't good enough, unless you want to require the user to
always use a multiset, and I don't think we want to do that. Then there
are two choices that I see for the ordering of operator<. One is
lexicographic. The other is to use the midpoint as the primary sort and
the first element as the secondary sort (and the second point as the
tertiary -- otherwise integer ranges might become degenerate...)

Both give the same ordering in the case of non-overlapping intervals,
so the question is which to choose in the overlapping case. IMHO,
lexicographic isn't really that bad -- it can be intuited as 'starts
earlier', it's fast to compute, and makes no new requirements on the
base type. And as I argued before, if you're dealing with overlapping
intervals you'd better be thinking about it carefully anyway, though
the library should supply functions/comparators to make that job easier.

George Heintzelman
georgeh_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk