Re: Is NullableRef checked at compile time?

2016-05-23 Thread ag0aep6g via Digitalmars-d-learn

On 05/23/2016 08:10 PM, cy wrote:

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.


NullableRef is little more than a plain pointer. In particular, it 
allows nulling the reference. Guarding against null dereferences doesn't 
seem to be on its agenda at all.



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.


Notice the different name. The goals of NotNull and NullableRef seem to 
be entirely different.


Also note that NotNull uses `assert` for the check, too. So there's no 
check with -release either. Can easily change that to `enforce`, of course.


Re: Is NullableRef checked at compile time?

2016-05-23 Thread Levi Maclean via Digitalmars-d-learn

On Monday, 23 May 2016 at 18:10:14 UTC, cy wrote:
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.


[...]


NullableRef is checked at compile time only if you "hold the 
door".^^


Is NullableRef checked at compile time?

2016-05-23 Thread cy via Digitalmars-d-learn
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.