Converting a number to complex

Philippe Sigaud philippe.sigaud at gmail.com
Sat Nov 24 03:30:16 PST 2012


On Sat, Nov 24, 2012 at 11:30 AM, Artur Skawina <art.08.09 at 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20121124/920d6ab0/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list