Anyone know why this CTFE isn't working?

Rory McGuire rmcguire at neonova.co.za
Fri Jul 16 03:12:38 PDT 2010


On Fri, 16 Jul 2010 11:58:57 +0200, Lars T. Kyllingstad  
<public at kyllingen.nospamnet> wrote:

> On Fri, 16 Jul 2010 11:46:48 +0200, Rory McGuire wrote:
>
>> import std.stdio;
>>
>> struct State {
>>   string s; string getString() { return s; } static State opCall(string
>>   s) {
>>   State ret;
>>   ret.s = s;
>>   return ret;
>>   }
>> }
>>
>> void main() {
>>   auto s = State("adf");
>>   pragma(msg, s.getString());
>> }
>>
>> dmd Output: (line 14 is the pragma statement)
>>
>> struct.d(14): Error: variable s cannot be read at compile time
>> struct.d(14): Error: cannot evaluate s.getString() at compile time
>> s.getString()
>
> It's not working because s isn't a compile-time quantity.  Try:
>
>   enum s = State("adf");
>
> -Lars

Awesome thanks, worked.

So is the difference that "auto s" is a Struct which can change whereas  
"enum s" is a constant?
If it is a constant its just "s" that is constant right?

Thanks Lars


-Rory


More information about the Digitalmars-d-learn mailing list