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.