std.typecons.nullable.op_assign - multiple declarations
- Template Nullable.opAssign
- Template Nullable.opAssign
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
| Name | Description |
|---|---|
| value | A value of type T to assign to this . |
Example
If this 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 NullableT, and the resulting code will look very strange. It
is strongly recommended that this be avoided by instead using
the version of that takes an additional NullablenullValue
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
| Name | Description |
|---|---|
| value | A value of type T to assign to this .
If it is nullvalue, then the internal state of
this will be set to null. |
Example
If this wraps a type that already has a null value
(such as a pointer), and that null value is not given for
NullablenullValue, then assigning the null value to this
is no different than assigning any other value of type NullableT,
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