Re: Enum and CTFE function call

2018-08-14 Thread Everlast via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 16:54:09 UTC, ixid wrote: On Tuesday, 14 August 2018 at 13:38:16 UTC, Everlast wrote: etc Thanks all for the comprehensive responses. I was not clearly separating CTFE and the compilation of the function in thinking about it. Much clearer now. Yeah, if you

Re: Enum and CTFE function call

2018-08-14 Thread ixid via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 13:38:16 UTC, Everlast wrote: etc Thanks all for the comprehensive responses. I was not clearly separating CTFE and the compilation of the function in thinking about it. Much clearer now.

Re: Enum and CTFE function call

2018-08-14 Thread Everlast via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 09:12:30 UTC, ixid wrote: This will not compile as it says n is not known at compile time: auto fun(int n) { static foreach(i;0..n) mixin(i.to!string ~ ".writeln;"); return; } enum value = 2; void main() { fun(value); }

Re: Enum and CTFE function call

2018-08-14 Thread Michael via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 11:25:06 UTC, Jonathan M Davis wrote: On Tuesday, August 14, 2018 4:03:11 AM MDT Michael via Digitalmars-d-learn wrote: [...] CTFE is triggered when a value must be known at compile-time. So, if you have something like [...] That is much clearer now, thanks

Re: Enum and CTFE function call

2018-08-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 14, 2018 4:03:11 AM MDT Michael via Digitalmars-d-learn wrote: > The page does state that enums should trigger CTFE though. CTFE is triggered when a value must be known at compile-time. So, if you have something like enum a = foo(); foo gets called at compile-time, because

Re: Enum and CTFE function call

2018-08-14 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 09:17:41 UTC, ixid wrote: On Tuesday, 14 August 2018 at 09:12:30 UTC, ixid wrote: This will not compile as it says n is not known at compile time... This does work if 'value' is changed to immutable and fun to accept it. So it still seems like a missed

Re: Enum and CTFE function call

2018-08-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 14, 2018 3:12:30 AM MDT ixid via Digitalmars-d-learn wrote: > This will not compile as it says n is not known at compile time: > > auto fun(int n) { > static foreach(i;0..n) > mixin(i.to!string ~ ".writeln;"); > return; > } > > enum value = 2; > > > void main() { >

Re: Enum and CTFE function call

2018-08-14 Thread Michael via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 09:17:41 UTC, ixid wrote: On Tuesday, 14 August 2018 at 09:12:30 UTC, ixid wrote: This will not compile as it says n is not known at compile time... This does work if 'value' is changed to immutable and fun to accept it. So it still seems like a missed

Re: Enum and CTFE function call

2018-08-14 Thread ixid via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 09:12:30 UTC, ixid wrote: This will not compile as it says n is not known at compile time... This does work if 'value' is changed to immutable and fun to accept it. So it still seems like a missed opportunity as enum shouldn't be able to change either.

Enum and CTFE function call

2018-08-14 Thread ixid via Digitalmars-d-learn
This will not compile as it says n is not known at compile time: auto fun(int n) { static foreach(i;0..n) mixin(i.to!string ~ ".writeln;"); return; } enum value = 2; void main() { fun(value); } But making it a template parameter fun(int n)() and