CTFE question

Danny Arends Danny.Arends at gmail.com
Tue Aug 28 04:13:39 PDT 2012


I have the following code:

------------------------------------

import std.stdio;
import std.metastrings;

pure int[] testCTFE(){
   int[] r;
   pragma(msg, "Testing CTFE");
   foreach(i; 0 .. 360){
     r ~= i;
     pragma(msg, Format!("Loop: %d",i));
   }
   pragma(msg, "Done CTFE test");
   return r;
}

immutable CTFEdata = testCTFE();

void main(string[] args){ }

----------------------------------

I expected this would compile and during compilation print:
Loop: 1 Loop:2, etc
However, I get a compilation error:

ctfe.d(9): Error: variable i cannot be read at compile time

Is this a bug or am I doing something wrong ??

Danny Arends
http://www.dannyarends.nl


More information about the Digitalmars-d-learn mailing list