<div dir="ltr">On 16 October 2013 16:23, Christopher Jefferson <span dir="ltr"><<a href="mailto:chris@bubblescope.net" target="_blank">chris@bubblescope.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 16 October 2013 16:06, Gabriel Dos Reis <<a href="mailto:gdr@microsoft.com">gdr@microsoft.com</a>> wrote:<br>
<br>
> |<br>
> | So what about std::less<void>? Should people be using it?<br>
><br>
> What is wrong about it?<br>
><br>
<br>
</div>Just to clarify this problem (because I don't think anyone has<br>
described the problem in detail).<br>
<br>
Given two int* pointers x,y;<br>
<br>
std::less<int*>()(x,y) is defined and a total ordering.<br>
<br>
std::less<>()(x,y) invokes undefined behaviour, as it is defined as<br>
calling 'x<y'.<br></blockquote><div><br></div><div>It does not invoke ub, as there are weasel words forcing this to work correctly for pointers. <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Therefore std::less<> is not a drop in replacement for std::less<int*>.<br></blockquote><div><br></div><div>std::less<> can be a drop in replacement for std::less<int*>.<br><br></div><div>In general though, std::less<>::operator()(T const&, T const&) is not a drop in replacement for std::less<T>::operator()(T const&, T const&), even though it is intended to be. This is problematic.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This is also hard to fix, as std::less<> can take different types, so<br>
it can't just always delegate to std::less<T> for the actual type T<br>
being compared.<br></blockquote><div><br></div><div>Well, it could for the case I wrote above, but that would be more than an editorial change to C++14, and definitely a breaking change after C++14 ships.<br></div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I was under the impression this problem was generally known, but had<br>
been ignored for some reason I did not know, as I do not attend<br>
meetings.<br></blockquote><div><br></div><div>I don't remember it coming up in Bristol when we discussed it. It isn't the only place in the standard library that uses operator< instead of std::less; I'd rather see that addressed in one go.<br>
<br>I certainly have no plans to bring up any issues with less<>.<br><br>Then again, my advice to developers is to forget about less<T> (that route lies madness) and just write an operator< for their class so they'll never see the problem. However, this advice differs from the advice of Gaby and Sean.<br>
</div></div>-- <br> Nevin ":-)" Liber <mailto:<a href="mailto:nevin@eviloverlord.com" target="_blank">nevin@eviloverlord.com</a>> (847) 691-1404
</div></div>