chris jefferson wrote:

>I realise that according to the C++ standard it isn't legal to compare
>two pointers which are not from the same array. Is anyone aware of
>anything in g++ which would actually forbid this, and if there is any
>way of checking if will be valid?
>
In my opinion we should first close read ยง5.9 and 5.10. My reading is
that in general the result of pointer comparisons can be "only"
unspecified. Logically, this means that you can "trust" the result only
when both pointers point to elements of the same array.

Then, as far as *our* library (and compiler) are concerned, there is the
interesting example of basic_string::_M_disjunct: with Nathan's
substantive insight we came to the conclusion that such kind of
comparisons can be always meaningful to do (at the C++ library level) if
we use std::less<>() & co. Maybe Nathan has something to add...

Paolo.

Reply via email to