another cool RTInfo trick - i want in runtime

Namespace rswhite4 at googlemail.com
Thu Jan 16 11:34:56 PST 2014


> All right, it wasn't you, it was Andrej Mitrovic on my thread 
> http://forum.dlang.org/thread/pdshwedjqgquoibxhrxa@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 { }
----


More information about the Digitalmars-d mailing list