View source code Display the source code in std/typecons.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.typecons.nullable.op_assign - multiple declarations

Template Nullable.opAssign

Assigns value to the internally-held state. If the assignment succeeds, this becomes non-null.

Arguments

template opAssign();

Functions

Function name Description
opAssign

Parameters

NameDescription
value A value of type T to assign to this Nullable.

Example

If this Nullable wraps a type that already has a null value (such as a pointer), 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 instead using the version of Nullable that takes an additional nullValue template argument.

//Passes
Nullable!(int*) npi;
assert(npi.isNull);

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

Template 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.

Arguments

template opAssign();

Functions

Function name Description
opAssign

Parameters

NameDescription
value 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.

Example

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);

Authors

Andrei Alexandrescu, Bartosz Milewski, Don Clugston, Shin Fujishiro, Kenji Hara

License

Boost License 1.0.

Comments