another cool RTInfo trick - i want in runtime
Adam D. Ruppe
destructionator at gmail.com
Thu Jan 16 15:56:13 PST 2014
This is a bit of a side discussion because the RTInfo can't
*change* the type, it can only look at it. It is more like a
centralized place to static asserts or maybe static data than an
AST macro.
But...
On Thursday, 16 January 2014 at 19:32:10 UTC, Namespace wrote:
> 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:
That's a lot of the benefit: the type system forces you to handle
it sooner rather than later, so you can see where the invalid
state came from.
> NotNull!A na = NotNull!A(new A());
This could be easily automated though with a helper function:
NotNull!T create(T, Args...)(Args args) {
return assumeNotNull(new T(args));
}
// use it! notice that it is notnull already
auto na = create!A();
And then you can just use it.
> Also it is far more readable and easier to write as a contract
That's what I tend to do now but the advantage of NotNull!() is
catching it earlier.
More information about the Digitalmars-d
mailing list