C++ Logo

SG12

Advanced search

Subject: Re: [ub] Justification for < not being a total order on pointers?
From: Christopher Jefferson (chris_at_[hidden])
Date: 2013-10-16 16:23:16


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.


SG12 list run by herb.sutter at gmail.com