Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2000-09-04 10:26:31


> >I want to be able to compare ref's that hold values of the same type via
> >operator<, hence the default semantics. Also, the ability to use ref as a
> >map key is a good thing, IMHO.
> >
> >(This applies to any as well.)
>
> This is why map and set take an optional function object type to make
> the comparison criteria explicit.

If you use std::map and std::set as a map (associative array) and a set,
while considering the fact that they are based on an ordering an
implementation detail, a map<any, T> is more intuitive than map<any, T,
ordering>.

> >As an aside, what are the reasons that type_info::op< is spelled
before()?
>
> Because it does not represent a magnitude-based comparison. It conforms
> to the principle of least astonishment, for the simple reason that
> operator< implies an obvious, total-ordering comparison for a type.

std::string::op< does not represent a magnitude-based comparison either.

less<T*> is required to provide an ordering suitable for map and set,
although there is no obvious, total-ordering comparison on pointers that
point to different objects.

> The
> same applies to ref<>, except that ref<> spells before() -- incorrectly,
> IMHO -- as operator< ;-)

Not exactly. ref(int(4)) < ref(int(5)) doesn't have anything to do with
before().

--
Peter Dimov
Multi Media Ltd.

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