How do you put log calls in constructors when they may be created in a static context?
aliak
something at something.com
Thu Aug 9 23:18:35 UTC 2018
On Thursday, 9 August 2018 at 20:02:41 UTC, Jonathan M Davis
wrote:
> On Thursday, August 9, 2018 7:15:58 AM MDT aliak via
> Digitalmars-d-learn wrote:
>> [...]
>
> It's failing, because you got the condition backwards. __ctfe
> is true during CTFE and false during runtime. Your code has
>
> if(__ctfe)
> writeln("log it");
>
> which means that it will attempt to run writeln at compile
> time, whereas if you used
>
> if(!__ctfe)
> writeln("log it");
>
> it would skip it at compile time. The problem isn't that
> writeln is being compiled in. The problem is that it's being
> encountered when CTFE is running the code. So, a static if is
> unnecessary. You just need to get the condition right.
>
> - Jonathan M Davis
Haha doh! Backwards it was. Thanks!
More information about the Digitalmars-d-learn
mailing list