<div dir="ltr">On 16 October 2013 16:23, Christopher Jefferson <span dir="ltr">&lt;<a href="mailto:chris@bubblescope.net" target="_blank">chris@bubblescope.net</a>&gt;</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 &lt;<a href="mailto:gdr@microsoft.com">gdr@microsoft.com</a>&gt; wrote:<br>


<br>
&gt; |<br>
&gt; | So what about std::less&lt;void&gt;?  Should people be using it?<br>
&gt;<br>
&gt; What is wrong about it?<br>
&gt;<br>
<br>
</div>Just to clarify this problem (because I don&#39;t think anyone has<br>
described the problem in detail).<br>
<br>
Given two int* pointers x,y;<br>
<br>
std::less&lt;int*&gt;()(x,y) is defined and a total ordering.<br>
<br>
std::less&lt;&gt;()(x,y) invokes undefined behaviour, as it is defined as<br>
calling &#39;x&lt;y&#39;.<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&lt;&gt; is not a drop in replacement for std::less&lt;int*&gt;.<br></blockquote><div><br></div><div>std::less&lt;&gt; can be a drop in replacement for std::less&lt;int*&gt;.<br><br></div><div>In general though, std::less&lt;&gt;::operator()(T const&amp;, T const&amp;) is not a drop in replacement for std::less&lt;T&gt;::operator()(T const&amp;, T const&amp;), 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&lt;&gt; can take different types, so<br>
it can&#39;t just always delegate to std::less&lt;T&gt; 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&#39;t remember it coming up in Bristol when we discussed it.  It isn&#39;t the only place in the standard library that uses operator&lt; instead of std::less; I&#39;d rather see that addressed in one go.<br>

<br>I certainly have no plans to bring up any issues with less&lt;&gt;.<br><br>Then again, my advice to developers is to forget about less&lt;T&gt; (that route lies madness) and just write an operator&lt; for their class so they&#39;ll never see the problem.  However, this advice differs from the advice of Gaby and Sean.<br>

</div></div>-- <br> Nevin &quot;:-)&quot; Liber  &lt;mailto:<a href="mailto:nevin@eviloverlord.com" target="_blank">nevin@eviloverlord.com</a>&gt;  (847) 691-1404
</div></div>