Ron Natalie wrote in news:411f77a4$0$2489$9a6e19ea@news.newshosting.com
in comp.lang.c++:
[color=blue]
>
> "Rob Williscroft" <rtw@freenet.co.uk> wrote in message[color=green][color=darkred]
>> > Hopefully, you know that operator<() is not well defined for
>> > pointers that are not pointing into the same array.
>> >[/color]
>>
>> However std::less< T * > is (20.3.3/8):
>>
>> int
>> main()
>> {
>> list< Something * > things;
>> things.pushBack( new Something( 10 ) );
>> things.pushBack( new Something( 20 ) );
>> things.sort( std::less< Something * >() );
>> }
>>[/color]
>
> Unfortunately, the above code doesn't have well defined behavior,[/color]
Yes it does, the citation is above.
[color=blue]
> as I
> said. Applying < to pointers only is well defined when the pointer
> values refer to elements of the same array. In your case the
> pointers are two unrelated values (different calls to new). It's
> quite legal that:
>
> Something* a = new Something(10);
> Something* b = new Something(20);
>
> a < b ; // true
> b < a; // also true.
>[/color]
Such a computer would have a == b return an undetermined value.
[color=blue]
> This is going to spell havoc for sorting algorithms,
>[/color]
The real problem is strict weak ordering:
a < b && b < c
Doesn't imply:
a < c
But std::less< T * > is *required* to be specialized to overcome
this limitation with operator <.
Rob.
--
http://www.victim-prime.dsl.pipex.com/