On 03/11/10 03:21, Robert Jacques wrote:

struct BinaryOp(L,string op,R) {
     pragma(msg,"Instansiating " ~ typeof(this).stringof);
     BinaryOp!(typeof(this),s,R1) opBinary(string s,R1)(R1 r) {
         pragma(msg,"Instansiating BinaryOp.opBinary ~L.stringof ~ op ~
R1.stringof);
         return typeof(return)();
     }
}

struct Leaf {
     BinaryOp!(typeof(this),s,R) opBinary(string s,R)(R r) {
         pragma(msg,"Instansiating leaf.opBinary(" ~ R.stringof ~ ")");
         return typeof(return)();
     }
};

void main() {
     Leaf v1,v2,v3;
     pragma(msg,"");
     pragma(msg,"======= This Compiles ======");
     v1*(v2*v3);
     pragma(msg,"");
     pragma(msg,"======= This Doesn't ======");
       (v1*v2)*v3;
}
Output:
======= This Compiles ======
Instansiating BinaryOp!(Leaf,s,Leaf)
Instansiating leaf.opBinary(Leaf)
Instansiating BinaryOp!(Leaf,s,BinaryOp!(Leaf,s,Leaf))
Instansiating leaf.opBinary(BinaryOp!(Leaf,s,Leaf))

======= This Doesn't ======
Error: recursive template expansion for template argument
BinaryOp!(Leaf,s,Leaf)

Thanks, the workaround seems to work. I've reported the bug:

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

Reply via email to