View source code
Display the source code in std/typecons.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

std.typecons.Nullable.opAssign - multiple declarations

Function Nullable.opAssign

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

void opAssign (
  T value
);

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

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

void opAssign (
  T value
);

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.