On Sat, 28 Jul 2012 10:20:56 +0200, Namespace <[email protected]> wrote:

This is a NotNull I just implemented. It is designed to create a strict
division between things that can be null, and those that cannot. The idea
being that the programmer should be aware of it when he needs to convert
between them, and whole call graphs can more easily be made free of
null checks.

Foo f = new Foo();
some_function(NotNull!Foo(f)); <-explicit conversion and because it's a struct it's better to deliver it by ref.

The conversion from a pointer to a struct containing a pointer should be
without cost when compiling with optimizations on. The effect is exactly
the same as with a pointer, which I hope you don't habitually pass by
reference.


A struct as solution to avoid not null references is a bad solution. It is a nice play tool but as solution it is crap. To pack my object into a struct with ensures that it is not null, what's the difference if i use only structs and avoid classes? Why should i initialize first my object and put it then into a struct if i can even use only structs?
That isn't comprehensible to me.

Huh? I believe you have misunderstood something here. The struct is a form
of smart pointer. It behaves like a pointer does, and lets you have
polymorphism, inheritance and all that stuff that comes with classes.
Granted, I have found a few issues with the version I posted (mostly to do
with subclassing). Most have been fixed in this version, but some are
unfixable until issue 1528 has been resolved.

--
Simen

Attachment: NotNull.d
Description: Binary data

Reply via email to