<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 7, 2014 at 2:10 PM, Arthur O'Dwyer <span dir="ltr"><<a href="mailto:arthur.j.odwyer@gmail.com" target="_blank">arthur.j.odwyer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Fri, Mar 7, 2014 at 1:51 PM, Benjamin Kramer<br>
<<a href="mailto:benny.kra@googlemail.com">benny.kra@googlemail.com</a>> wrote:<br>
><br>
> [C++11] Revert uses of lambdas with array_pod_sort.<br>
><br>
> Looks like GCC implements the lambda->function pointer conversion differently.<br>
<br>
</div><div class="">> -    llvm::array_pod_sort(DeferredLocs.begin(), DeferredLocs.end(),<br>
> -                         [](const DeferredLocsTy::value_type *p1,<br>
> -                            const DeferredLocsTy::value_type *p2) {<br>
> -      if (p1->second->getLocStart() != p2->second->getLocStart())<br>
> -        return p1->second->getLocStart() < p2->second->getLocStart() ? -1 : 1;<br>
> -      return 0;<br>
> -    });<br>
> +    llvm::array_pod_sort(DeferredLocs.begin(), DeferredLocs.end(), SrcCmp);<br>
<br>
</div>Incidentally, I like the bag-of-idioms<br>
<br>
    auto *byLocation =<br>
        +[](const DeferredLocsTy::value_type *p1, const<br>
DeferredLocsTy::value_type *p2) -> int {<br>
            return (p1->second->getLocStart() <<br>
p2->second->getLocStart() ? -1 : (p1->second->getLocStart() ><br>
p2->second->getLocStart());<br>
        };<br>
    llvm::array_pod_sort(DeferredLocs.begin(), DeferredLocs.end(), byLocation);<br>
<br>
That is,<br>
- Name the out-of-line lambda after the predicate it implements (in<br>
this case sorting "byLocation")<br>
- I bet you'll find compilers are happier with the explicitly<br>
function-pointer'ized "+[]" than with "[]" alone<br></blockquote><div><br></div><div>I bet the opposite. MSVC (non-conformingly) gives lambdas three conversions to function pointers with different calling conventions, and this won't compile there.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- The spaceship operator <=> is equivalent to (a < b) ? -1 : (a > b)<br></blockquote><div><br></div><div>The more usual idiom of</div><div><br></div><div>  if (!=)</div><div>    return <</div><div><br></div>
<div>naturally extends to lexicographical comparisons of multiple things. I don't see how to do that with (a<b?-1:a>b).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

However, FWIW and IMHO, I don't think lambdas are obviously desirable<br>
here. This looks a lot like "C++11isms for C++11isms' sake", not<br>
anything that would actually improve compiler speed or stability.<br>
<br>
my two cents,<br>
–Arthur<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>