Spec#, nullables and more
Walter Bright
newshound2 at digitalmars.com
Fri Nov 5 17:34:33 PDT 2010
Adam D. Ruppe wrote:
> A non-nullable type is basically just:
>
> struct NotNull(T) {
> T _payload;
> alias _payload this;
> invariant() {
> assert(_payload !is null);
> }
> }
>
> If we could disable the default constructor, this approach might just work. Sure,
> the checks here would be at runtime, but you'd have them without having to
> manually write the assert each time.
All that does is reinvent the null pointer seg fault. The hardware does this for
you for free.
A null pointer is what's known as a "white hole", all attempts to access the
object are rejected.
More information about the Digitalmars-d
mailing list