Who wore it better?
    Andrei Alexandrescu via Digitalmars-d 
    digitalmars-d at puremagic.com
       
    Fri Apr 15 10:24:19 PDT 2016
    
    
  
I grepped phobos for "inout" and picked a heavy one. Not even cherry 
picking here. You be the judges.
Before:
inout(T)[] overlap(T)(inout(T)[] r1, inout(T)[] r2) @trusted pure nothrow
{
     alias U = inout(T);
     static U* max(U* a, U* b) nothrow { return a > b ? a : b; }
     static U* min(U* a, U* b) nothrow { return a < b ? a : b; }
     auto b = max(r1.ptr, r2.ptr);
     auto e = min(r1.ptr + r1.length, r2.ptr + r2.length);
     return b < e ? b[0 .. e - b] : null;
}
After:
auto overlap(T, U)(T[] r1, U[] r2) @trusted pure nothrow
if (is(typeof(r1.ptr < r2.ptr) == bool))
{
     import std.algorithm : min, max;
     auto b = max(r1.ptr, r2.ptr);
     auto e = min(r1.ptr + r1.length, r2.ptr + r2.length);
     return b < e ? b[0 .. e - b] : null;
}
Who wore it better?
Andrei
    
    
More information about the Digitalmars-d
mailing list