All right, it wasn't you, it was Andrej Mitrovic on my thread http://forum.dlang.org/thread/pdshwedjqgquoibxh...@forum.dlang.org#post-mailman.1977.1381065059.1719.digitalmars-d-learn:40puremagic.com

The problem on a library NotNull struct is: nobody will use it, because it requires NotNull on both sides, by the caller and by the callee:

----
class A { }

void safe_foo(NotNull!A na) { }

void main() {
    NotNull!A na = NotNull!A(new A());
    safe_foo(na);
}
----

Which is a lot more effor than:

----
class A { }

void safe_foo(@safe_ref A na) { }

void main() {
    A a = new A();
    safe_foo(a);
}
----

because it moves the check to the callee.

Also it is far more readable and easier to write as a contract like:
----
void safe _foo(A a) in {
    assert(a !is null);
} body { }
----

Reply via email to