Enum and CTFE function call
Michael
michael at toohuman.io
Tue Aug 14 10:03:11 UTC 2018
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 opportunity as enum
> shouldn't be able to change either.
From the examples on this page:
https://tour.dlang.org/tour/en/gems/compile-time-function-evaluation-ctfe
It looks to me like it might be a slight issue with the function
being void, in that you need to explicitly ensure that n is
immutable. For the example on the page above, they assign the
result of the function to a static variable, and so the function
is evaluated at compile-time, but without assigning the value to
a static variable, it is evaluated at runtime. I guess in this
case the compiler may just be being cautious?
The page does state that enums should trigger CTFE though.
More information about the Digitalmars-d-learn
mailing list