View mode: basic / threaded / horizontal-split · Log in · Help
November 24, 2012
Re: Converting a number to complex
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)
November 24, 2012
Re: Converting a number to complex
On 11/24/12 12:30, Philippe Sigaud wrote:
> 
>     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)

Then it's probably just my old compiler, gdc r748:ab99d67f04c2, using dmd 2.057, 
which thinks that that is-expression is always false.

artur
November 25, 2012
Re: Converting a number to complex
On Saturday, 24 November 2012 at 07:27:18 UTC, Philippe Sigaud 
wrote:
> It's an is() expression (you cited my tutorial, there is an 
> appendix on
> it). It recently became even more powerful, so the tutorial is 
> not accurate
> any more.

its time for another read through:)
Template constraints might make for a good talk at the conf...
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home