On Monday, 18 June 2018 13:36:39 PDT Brian Bi wrote:
> Why can't we just change the standard so that the built-in < operator for
> T* also provides a strict total order? It would take about 5 minutes to
> write up a paper, which is why I'm sure it would have been done by now if
> there wasn't a good reason not to.
The reason is that you're not *supposed* to order pointers for different
arrays. And the reason for that is that on some systems only a portion of the
pointer representation needs to be compared to determine the ordering, if it
is in the same array.
Think of 16-bit segmented DOS builds, with 32-bit far pointers. Aside from the
Huge Memory Model, all objects (including arrays) are limited to 64kB in size,
so the segment portion of the pointer remains the same for any pointer.
Iteration only requires modifying the offset portion.
Ordering in that system requires only to compare the 16-bit offsets, not the
entire 32-bit representation. Considering it's a build for a 16-bit platform
with 16-bit CMP instructions, a 32-bit comparison would mean an extra jump,
something you don't want in the general case. That logic is only required in
std::less, so it's kept there.
--
Thiago Macieira - thiago (AT)
macieira.info - thiago (AT)
kde.org
Software Architect - Intel Open Source Technology Center