C++ Logo

sg12

Advanced search

Re: [ub] Justification for < not being a total order on pointers?

From: Christopher Jefferson <chris_at_[hidden]>
Date: Wed, 16 Oct 2013 22:23:16 +0100
On 16 October 2013 16:06, Gabriel Dos Reis <gdr_at_[hidden]> wrote:

> |
> | So what about std::less<void>? Should people be using it?
>
> What is wrong about it?
>

Just to clarify this problem (because I don't think anyone has
described the problem in detail).

Given two int* pointers x,y;

std::less<int*>()(x,y) is defined and a total ordering.

std::less<>()(x,y) invokes undefined behaviour, as it is defined as
calling 'x<y'.

Therefore std::less<> is not a drop in replacement for std::less<int*>.

This is also hard to fix, as std::less<> can take different types, so
it can't just always delegate to std::less<T> for the actual type T
being compared.

I was under the impression this problem was generally known, but had
been ignored for some reason I did not know, as I do not attend
meetings.

Received on 2013-10-16 23:23:17