Is NullableRef checked at compile time?

cy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 23 11:10:14 PDT 2016


I was squinting at the std.typecons.NullableRef code and it 
_looks_ like isNull is only checked at runtime (and not checked 
at all in release mode!) but D has surprised me before in its 
ability to pre-calculate stuff during compilation.

I was thinking of using something like this:

http://arsdnet.net/dcode/notnullsimplified.d

...which does the check once (during runtime) but after that it's 
compile-time verified not to have a null pointer. (Sort of like 
C++ references!) I think using NullableRef instead would have 
every instance of getting the pointer perform the check at 
runtime, even if it has already been verified as not null. That's 
correct, right? Yes I know, premature optimization etc, but I was 
just curious if a NotNull template might be a stronger 
declaration of a pointer's nullness.


More information about the Digitalmars-d-learn mailing list