On Sat, Nov 24, 2012 at 11:30 AM, Artur Skawina <art.08.09@gmail.com> wrote:
On 11/24/12 08:27, Philippe Sigaud wrote:
> 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.

Actually, static-ifs do not create a scope, so 'CT' leaks and is accessible
after it's defined, not just inside the static-if branch:

You're right, I didn't think it through. Time to update my tutorial, then :)

 
Unfortunately the is-expressions don't handle aliases properly, at least
with my old compiler here. So this does not work:

   template isTempInst(alias TEMPL, T) {
      static if (is(T _ == TEMPL!CT, CT))
         enum isTempInst = true;
      else
         enum isTempInst = false;
   }

Works for me:


template isTempInst(alias TEMPL, T)
{
    static if (is(T _ == TEMPL!CT, CT...))
        enum isTempInst = true;
    else
        enum isTempInst = false;
}
   
void main()
{

    Tuple!(int,string) t = tuple(1, "abc");
    writeln(typeof(t).stringof);
    writeln(isTempInst!(Tuple, typeof(t)));
}

(DMD 2.060)