[Issue 9786] Allow [non-member|UFCS] implementation of operators

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 31 01:47:07 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9786



--- Comment #8 from timon.gehr at gmx.ch 2013-03-31 01:47:04 PDT ---
std.typecons.Proxy is incorrect because of this inconsistent behaviour of DMD:

import std.conv, std.typecons;

struct S{
    int x;
}

int front(ref S s){ return s.x; }
bool empty(ref S s){ return s.x>10; }
void popFront(ref S s){ s.x++; }

auto opBinary(string op)(S a, S b){ return S(mixin("a.x "~op~"b.x"));}

struct Capture(T){
    private T payload;
    mixin Proxy!payload;
}

auto ufcs(T)(T arg){
    Capture!T r;
    r.payload = arg;
    return r;
}

import std.stdio;

void main(){
    auto s = S(3);
    writeln(s.ufcs); // [3, 4, 5, 6, 7, 8, 9, 10]
    writeln(s.opBinary!"+"(s)); // S(6)
    //writeln(s.ufcs.opBinary!"+"(s.ufcs)); // error!
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list