Nullable.opAssign

Assigns value to the internally-held state. If the assignment succeeds, this becomes non-null. No null checks are made. Note that the assignment may leave this in the null state.

struct Nullable(T, T nullValue)
void
opAssign
()
()

Parameters

value T

A value of type T to assign to this Nullable. If it is nullvalue, then the internal state of this Nullable will be set to null.

Examples

If this Nullable wraps a type that already has a null value (such as a pointer), and that null value is not given for nullValue, then assigning the null value to this Nullable is no different than assigning any other value of type T, and the resulting code will look very strange. It is strongly recommended that this be avoided by using T's "built in" null value for nullValue.

//Passes
enum nullVal = cast(int*) 0xCAFEBABE;
Nullable!(int*, nullVal) npi;
assert(npi.isNull);

//Passes?!
npi = null;
assert(!npi.isNull);

Meta

Suggestion Box / Bug Report