How do I check if a function got CTFE?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 2 11:02:29 PDT 2014
On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote:
> I'd like to check if a function got CTFE, ie, the compiler was
> able to replace my foo(s); by the computed value at
> compile-time.
You have to explicitly force ctfe with context, it is never done
automatically, and if it fails, the build will fail and you get a
compile time error.
So if you write
enum f = foo();
or
static f = foo();
or similar initializations and the build succeeds, you know it
got ctfe'd. Otherwise, it wasn't.
More information about the Digitalmars-d-learn
mailing list