Why this code can't take advantage from CTFE?

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 3 07:34:51 PST 2016


This code:

import std.stdio;

int very_very_long_function(in int k)
{
         if (!__ctfe) writeln("Can't use ctfe!");
         return k/2;
}

void main()
{
         enum first = very_very_long_function(10);
         writeln("First is ", first);

         auto second = very_very_long_function(12);
         writeln("Second is ", second);

         auto third = first;
         third += 1;
         writeln("Third is ", third);
}

Why second init doesn't work with CTFE? It could be something 
like third, but with one less copy. What am I missing?


More information about the Digitalmars-d-learn mailing list