<div dir="ltr"><div>is not bad</div><div><br></div><a href="https://godbolt.org/g/bSfubs">https://godbolt.org/g/bSfubs</a><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 3, 2017 at 3:19 PM, SrMordred via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">//D compiled with gdc 5.2 -O3<br>
<br>
auto test(int[] arr, int cmp)<br>
{<br>
    int[] r;<br>
    foreach(v ; arr)<br>
        if(v == cmp)r~=v;<br>
    return r;<br>
}<br>
// 51 lines of assembly<br>
<br>
auto test(int[] arr, int cmp)<br>
{<br>
  return arr.filter!((v)=>v==cmp).array<wbr>;<br>
}<br>
//1450 lines... what?<br>
<br>
Ok let me look also at c++:<br>
//gcc 7.2 -O3<br>
<br>
vector<int> test(vector<int>& arr, int cmp) {<br>
    vector<int> r;<br>
    for(auto v : arr)<br>
        if(v == cmp)r.push_back(v);<br>
    return r;<br>
}<br>
//152 lines. more than D :)<br>
<br>
vector<int> test(vector<int>& arr, int cmp) {<br>
    vector<int> r;<br>
    std::copy_if (arr.begin(), arr.end(), std::back_inserter(r),<br>
     [cmp](int i){return i==cmp;} );<br>
    return r;<br>
}<br>
<br>
//150 lines. That what i expected earlier with D.<br>
<br>
Hmm. let me be 'fair' and use std.container.array just for curiosity:<br>
<br>
auto test(ref Array!int arr, int cmp)<br>
{<br>
    Array!int r;<br>
    foreach(v ; arr)<br>
        if(v == cmp)r.insert(v);<br>
    return r;<br>
}<br>
<br>
//5542 lines... what??<br>
<br>
Someone interested to discuss about this?<br>
<br>
Or point me some grotesque mistake.<br>
</blockquote></div><br></div>