How to enforce compile time evaluation (and test if it was done at compile time)

Christian Köstlin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 1 01:19:53 PST 2017


On 01/03/2017 00:09, Joseph Rushton Wakeling wrote:
> On Tuesday, 28 February 2017 at 00:22:28 UTC, sarn wrote:
>>> If you ever have doubts, you can always use something like this to
>>> check:
>>>
>>> assert (__ctfe);
>>
>> Sorry, "enforce" would more appropriate if you're really checking.
> 
> if (!__ctfe) assert(false);
> 
> ... might be the best option.  That shouldn't be compiled out even in
> -release builds.
thats a nice idea! is this happening because of assert(false) being
always part of release builds (as mentioned here:
https://dlang.org/spec/contracts.html#assert_contracts) or because the
if would have no instructions anymore if this is removed.

cK



More information about the Digitalmars-d-learn mailing list