forcing compile time function execution

Artur Skawina art.08.09 at gmail.com
Tue Dec 27 15:20:49 PST 2011


On 12/27/11 23:10, Timon Gehr wrote:

> I don't think your example helps your point a lot. Compiling in error checking code is a matter of debug/release mode, not a matter of compile-time vs runtime. Assertions are always checked in CTFE and always stripped from runtime release code.


I remembered about the contracts after already writing my version... But then realized it's completely irrelevant where the ctfed "code" goes - you don't want unnecessary bloat both in release *and* debug builds.
And compiletime error checks is not something you want to disable in release builds. If anything you want more of them. As long as they are completely "free" runtime-wise. Which ctfe makes possible.

Runtime error checking is different, yes. But anything the compiler can check for itself should never be disabled, other than maybe for *devel* builds, if it affects compile times. Nothing worse than a bug *only* in a release build.

> template POW2MASK(alias N) if(!(N&N-1)) {
>     enum POW2MASK = N-1;
> }

This i didn't think of. Calling the ctfe functions from template constraints. Solves the issue at least for simple templates. I'm not sure if separating the checks from useful code will work for every case, but for the rest the wrapper might be acceptable.

Thank you,

artur


More information about the Digitalmars-d mailing list