null dereference exception vs. segfault?

bearophile bearophileHUGS at lycos.com
Mon Aug 2 16:08:32 PDT 2010


Pelle:

> struct NotNull(T) if(is(typeof(T.init !is null))) {

Is this enough?
struct NotNull(T) if (is(T.init is null)) {


>      this(T t) {
>          enforce(t !is null, "Cannot create NotNull from null");

enforce() is bad, use Design by Contract instead (a precondition with an assert inside).

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list