std.array suggestion

Don Clugston dac at nospam.com.au
Fri Mar 10 07:11:00 PST 2006


Oskar Linde wrote:
> Stewart Gordon wrote:
>> Oskar Linde wrote:
>>> It is also in many cases simpler to define a ordering predicate than 
>>> a 3-valued ordering. The name wrongOrder just helps as a reminder of 
>>> what the predicate should return.
>> <snip>
>>
>> If that's so, I wonder why so many things have stuck with the 
>> three-valued ordering.
> 
> A comparison operator is not the same thing as an ordering predicate.
> Consider sorting phone-book entries (Sorted by first city, then surname 
> and finally first name):
> 
> bool phoneBookOrder(Record a, Record b) {
>     return a.city > b.city ||
>                a.surname > b.surname ||
>                a.name > b.name;
> }
> 
> Forcing the user to write three-valued ordering functions for this is 
> both unnecessary (the sorthing function will not use all 3 values), 
> harder to get right (try it yourself) and probably less efficient.
> 
> Instead of wrongOrder, I could name the predicate lessThan and swap its 
> arguments. This is what C++ STL uses and may be more logical.

I like wrongOrder. It clearly states that it's a < rather than a <= 
comparison. Also, 'lessThan' sounds rather formal, whereas wrongOrder 
sounds more general.



More information about the Digitalmars-d mailing list