On Fri, Aug 6, 2010 at 22:37, div0 <d...@sourceforge.net> wrote: > Personally, I'm with you and I would expect that the compiler should > example the function parameters after the template string parameter but it > doesn't. >
Yes :o( You need to add a second template parameter for the function arguments and add a template constrait like so: > struct Group { > int i1; > > Group opBinary(string op, U) (U x) > if(op == "+" && is(U: int)) > { > // do somehting > return this; > } > > Group opBinary(string op, U) (U rhs) > if(op == "+" && is(U: Group)) > { > // do something > return this; > } > } > > In some cases, you might factor things a bit: Group opBinary(string op, U)(U u) if (op == "+") { common code for all U's; static if (some test on U) some code; else other code; } Maybe some code is common between the Group case and the int case. I'm not sure it's more readable this way... Philippe