<br><br><div class="gmail_quote">On Wed, Aug 4, 2010 at 22:06, Steven Schveighoffer <span dir="ltr"><<a href="mailto:schveiguy@yahoo.com">schveiguy@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Wed, 04 Aug 2010 15:37:32 -0400, Simen kjaeraas <<a href="mailto:simen.kjaras@gmail.com" target="_blank">simen.kjaras@gmail.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
struct bar( T ) {<br>
auto baz( U )( U arg ) {<br>
bar!( typeof( this ) ) tmp;<br>
return tmp;<br>
}<br>
}<br>
<br>
void main( ) {<br>
bar!int n;<br>
n.baz( 3 );<br>
}<br>
<br>
This code fails with<br>
Error: recursive template expansion for template argument bar!(int)<br>
Now, I agree it is recursive, but it is not infinitely recursive, so<br>
there shouldn't really be a problem.<br>
Is this a bug? Is there a workaround?<br>
</blockquote>
<br></div></div>
It's lazily recursive. Meaning, it *is* infinitely recursive, but the compiler does not have to evaluate all the recursions until they are used.<br>
<br>
I'm not sure it should be disallowed, but it's definitely on the edge. Do you have some real-world case for this? If you want to get something like this fixed, you'll need a good example, not an academic one.<br>
<br>
-Steve<br>
</blockquote></div><br><div>I could get this to work, using a factory function:</div><div><br></div><div><div>import std.stdio;</div><div><br></div><div>struct Bar( T ) {</div><div> auto baz( U )( U arg ) {</div><div> return bar(this);</div>
<div> }</div><div>}</div><div><br></div><div>Bar!T bar(T)(T t)</div><div>{</div><div> return Bar!T();</div><div>}</div><div><br></div><div>void main( ) {</div><div> Bar!int n;</div><div> auto nn = n.baz( 3 );</div>
<div> writeln(typeof(n).stringof);</div><div> writeln(typeof(nn).stringof);</div><div>}</div></div><div><br></div><div>It's... fragile. Changes a few things here and there, and it's back to infinite recursion. </div>
<div><br></div><div><br></div><div><br></div><div>Philippe</div>