<div class="gmail_quote">On Fri, Aug 6, 2010 at 22:37, div0 <span dir="ltr"><<a href="mailto:div0@sourceforge.net">div0@sourceforge.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div class="h5">
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.</div></div></blockquote><div><br>Yes :o(<br>You need to add a second template parameter for the function arguments and add a template constrait like so:<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
struct Group {<br>
int i1;<br>
<br>
Group opBinary(string op, U) (U x)<br>
if(op == "+" && is(U: int))<br>
{<br>
// do somehting<br>
return this;<br>
}<br>
<br>
Group opBinary(string op, U) (U rhs)<br>
if(op == "+" && is(U: Group))<br>
{<br>
// do something<br>
return this;<br>
}<br>
}<br><br></blockquote><div><br>In some cases, you might factor things a bit:<br><br>Group opBinary(string op, U)(U u) if (op == "+")<br>{<br> common code for all U's;<br><br> static if (some test on U)<br>
some code;<br> else<br> other code;<br>}<br><br>Maybe some code is common between the Group case and the int case. I'm not sure it's more readable this way...<br><br>Philippe<br><br></div></div>