Who wore it better?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 15 13:05:30 PDT 2016


On 04/15/2016 03:13 PM, Steven Schveighoffer wrote:
> On 4/15/16 2:48 PM, Andrei Alexandrescu wrote:
>> On 4/15/16 2:46 PM, Steven Schveighoffer wrote:
>>> inout(T)[] overlap(T)(inout(T)[] r1, inout(T)[] r2) @trusted pure
>>> nothrow
>>> {
>>>      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;
>>> }
>>
>> Is that better or worse than the one without inout? -- Andrei
>
> Better. It generates one implementation for all 9 combinations of
> mutability. Yours generates 9 identical binary functions.

A valid but weak argument. There's been long talk about eliminating 
binary identical functions in the front end (some linkers already do 
it). That would be the real solution that would help cases unrelated to 
inout, too.

> And yours possibly depends on a bug:
> https://issues.dlang.org/show_bug.cgi?id=15930

Red herring. Fixing the bug shouldn't break that code.


Andrei




More information about the Digitalmars-d mailing list