NotNull

NotNull ensures a null value can never be stored.

* You must initialize it when declared

* You must never assign the null literal to it (this is a compile time error)

* If you assign a null value at runtime to it, it will immediately throw an Error at the point of assignment.

NotNull!T can be substituted for T at any time, but T cannot become NotNull without some attention: either declaring NotNull!T, or using the convenience function, notNull.

struct NotNull (
T
) if (
__traits(compiles, )
) {}

Constructors

this
this(T value)

constructs with a runtime not null check (via assert())

Alias This

_notNullDataHelper

Members

Functions

opAssign
NotNull!T opAssign(NotNull!T rhs)

.

Examples

int myInt;
NotNull!(int *) not_null = &myInt;
// you can now use variable not_null anywhere you would
// have used a regular int*, but with the assurance that
// it never stored null.
Suggestion Box / Bug Report