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
Name | Description |
---|---|
value | A value of type T to assign to this Nullable . |
Function Nullable.opAssign
If value is null, sets this to null, otherwise assigns
value
to the internally-held state. If the assignment
succeeds, this
becomes non-null.
Parameters
Name | Description |
---|---|
value | A value of type Nullable!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
Name | Description |
---|---|
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