<br><br><div class="gmail_quote">On Sat, Nov 24, 2012 at 11:30 AM, Artur Skawina <span dir="ltr"><<a href="mailto:art.08.09@gmail.com" target="_blank">art.08.09@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 11/24/12 08:27, Philippe Sigaud wrote:<br>
> What's even nicer with an is() expr is that the introspection info is accessible when used inside a static if. So with Artur's code, CT can be seen inside the true branch of the static if.<br>
<br>
</div>Actually, static-ifs do not create a scope, so 'CT' leaks and is accessible<br>
after it's defined, not just inside the static-if branch:<br></blockquote><div><br></div><div>You're right, I didn't think it through. Time to update my tutorial, then :)</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Unfortunately the is-expressions don't handle aliases properly, at least<br>
with my old compiler here. So this does not work:<br>
<br>
   template isTempInst(alias TEMPL, T) {<br>
      static if (is(T _ == TEMPL!CT, CT))<br>
         enum isTempInst = true;<br>
      else<br>
         enum isTempInst = false;<br>
   }</blockquote><div><br></div><div>Works for me:</div><div><br></div><div><br></div><div>template isTempInst(alias TEMPL, T)</div><div>{</div><div>    static if (is(T _ == TEMPL!CT, CT...))</div><div>        enum isTempInst = true;</div>
<div>    else</div><div>        enum isTempInst = false;</div><div>}</div><div>   </div><div>void main()</div><div>{</div><div><br></div><div>    Tuple!(int,string) t = tuple(1, "abc");</div><div>    writeln(typeof(t).stringof);</div>
<div>    writeln(isTempInst!(Tuple, typeof(t)));</div><div>}</div><div><br></div><div>(DMD 2.060)</div><div> </div></div>