Keyword to avoid not null references
Namespace
rswhite4 at googlemail.com
Sat Apr 21 15:48:25 PDT 2012
On Saturday, 21 April 2012 at 22:18:02 UTC, Adam D. Ruppe wrote:
> We can do not null in the library reasonably
> well. I have a basic one in github:
>
> https://github.com/D-Programming-Language/phobos/pull/477
So every time i want to avoid null references i have to write
"NotNull!(Foo) f" (or better, because it's a struct: "ref
NotNull!(Foo) f")? And therefore i must initialize them with
NotNull!(Foo) f = new Foo();? That would be a little annoying.
What if i needed in function bar only Foo f which can be null but
in quatz i need a not null Reference?
In my opinion the best way would be to initialize them with Foo f
= new Foo(); and if i pass them to bar, it will be implicit cast
to NotNull!(Foo). I think, that would be the best idea.
The only thing that disturbing me, is, that it is a struct and
therefore it passes by value instead as reference and that it is
more to write as just "@" or "@ref".
More information about the Digitalmars-d-learn
mailing list