
Boost : 
From: Peter Dimov (pdimov_at_[hidden])
Date: 20060711 08:25:20
Martin Bonner wrote:
>> Consider the progression:
>>
>> complex<double>
>> struct { double x, double y; }
>> pair<double, double>
>> tuple<double, double>
>> vector<double>
>> vector<char>
>> string
>>
>> If we take the "feel" of operator< out of the equation, where should
>> we draw the line, and based on what?
>
> complex<double> should not have an operator <() because it models a
> mathematical concept (complex number) for which "less than" does not
> make sense.
How would you make a std::set of complex<>?
> struct, pair, and tuple should not have an operator < because they are
> essentially unordered collections of data (I know that the elements of
> pair are called first and second, but it seems to me that they are
> essentially arbitrary labels).
How do you make a std::set of structs, pairs, or tuples?
> vector is an interesting case. Some vectors are used to store lists
> of things (in which case ordering makes sense), but others are used to
> model things like mathematical vectors (in which case we are back to
> the complex case, and < does not make sense).
OK, do you define an operator< for vector or not? You don't know a priori
what it will be used to hold.
> string definitely should have operator <() because it models the real
> world concept (string of letters and other characters) for which "less
> than" definitely makes sense.
Still, there are several different "less than"s, all of which make sense.
Based on the principle that operator< should be defined only if it's unique,
string should not have operator<.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk