Boost logo

Boost :

From: Guillaume Melquiond (guillaume.melquiond_at_[hidden])
Date: 2006-07-11 10:28:46


Le mardi 11 juillet 2006 à 15:34 +0300, Peter Dimov a écrit :
> > Any set of computer data can be ordered. I don't think it means that
> > they should all have an operator<.
>
> Yes of course. So which types should have an operator< and which should not?

In my humble opinion, only types which model mathematical types for
which mathematicians have defined a "natural" order. For example,
std::complex types model the complex numbers which do not have a natural
ordering. std::vector types model the word monoids which have a natural
ordering (the lexicographic one) as long as the base type is totally
ordered.

But this point of view only gives a small intuition. Sometimes it may be
difficult to take a decision. For example, if you consider that std::set
types model typed sets, then they should not have an operator<. But as a
matter of fact they don't (in the STL): they model ordered typed sets,
so it is not clear anymore that operator< should not be defined for
them.

Back to the topic of operator< for smart_ptr, I think it was a mistake
for the STL to use std::less as the default parameter for ordered
containers. It would have been better to define some kind of total_order
template class (that would have defaulted to being std::less). For
smart_ptr, the situation would then be clear: no operator< but a
specialization of total_order. With respect to the current STL, I don't
have a strong opinion on whether smart pointers should define or not
operator<.

Best regards,

Guillaume


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