Thread overview | |||||
---|---|---|---|---|---|
|
July 16, 2010 Re: Anyone know why this CTFE isn't working? | ||||
---|---|---|---|---|
| ||||
Sorry about the html
On Fri, 16 Jul 2010 11:46:48 +0200, Rory McGuire <rmcguire@neonova.co.za> 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()
|
July 16, 2010 Re: Anyone know why this CTFE isn't working? | ||||
---|---|---|---|---|
| ||||
On Friday 16 July 2010 02:46:48 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());
> }
Make s an enum and it'll work. As it is, it's a local variable created at runtime rather than a constant at compile-time. So, use
enum s = State("adf");
- Jonathan M Davis
|
July 16, 2010 Re: Anyone know why this CTFE isn't working? | ||||
---|---|---|---|---|
| ||||
On Fri, 16 Jul 2010 12:05:02 +0200, Jonathan M Davis <jmdavisprog@gmail.com> wrote:
> On Friday 16 July 2010 02:46:48 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());
>> }
>
> Make s an enum and it'll work. As it is, it's a local variable created at
> runtime rather than a constant at compile-time. So, use
>
> enum s = State("adf");
>
>
> - Jonathan M Davis
Thanks
worked
|
Copyright © 1999-2021 by the D Language Foundation