Compile-time optimization

monarch_dodra monarchdodra at gmail.com
Wed Jul 24 02:56:40 PDT 2013


On Tuesday, 23 July 2013 at 17:41:01 UTC, Ali Çehreli wrote:
> On 07/23/2013 09:21 AM, JS wrote:
>
> > string join(T...)(T t)    // Note join has a variadic
> parameter
> > {
> >      ctfe {
>
> Are you aware of version(ctfe)?

Hum... really? I don't think that exists. Either that, or I'm 
using it wrong. Could you provide an example?

What you do have is "if (__ctfe)" though...

//----
import std.stdio;

int foo()
{
     version (poop)
         return 1;
     else
         return 0;
}

void main(string[] args)
{
     enum a = foo();
     auto b = foo();
     writeln(a, " ", b);
}
//----
Prints: 0 0

//----
import std.stdio;

int foo()
{
     if (__ctfe)
         return 1;
     else
         return 0;
}

void main(string[] args)
{
     enum a = foo();
     auto b = foo();
     writeln(a, " ", b);
}
//----
Prints: 1 0


More information about the Digitalmars-d mailing list