Spec#, nullables and more

Adam D. Ruppe destructionator at gmail.com
Fri Nov 5 17:12:54 PDT 2010


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.

(Though, having to write NotNull! each time isn't that much of a gain over the
asserts, but maybe it would help.)


More information about the Digitalmars-d mailing list