std.sumtype.SumType.opAssign - multiple declarations
Function SumType.opAssign
Assigns a value to a SumType.
If any of the SumType's members other than the one being assigned
to contain pointers or references, it is possible for the assignment
to cause memory corruption (see the
["Memory corruption" example](#memory-corruption) below for an
illustration of how). Therefore, such assignments are considered
@system.
An individual assignment can be @trusted if the caller can
guarantee that there are no outstanding references to any SumType
members that contain pointers or references at the time the
assignment occurs.
Examples
Memory corruption
This example shows how assignment to a SumType can be used to
cause memory corruption in @system code. In @safe code, the
assignment s = 123 would not be allowed.
SumType!(int*, int) s = new int;
s .tryMatch!(
(ref int* p) {
s = 123; // overwrites `p`
return *p; // undefined behavior
}
);
Function SumType.opAssign
Copies the value from another SumType into this one.
See the value-assignment overload for details on @safety.
Copy assignment is @disabled if any of Types is non-copyable.
Function SumType.opAssign
Moves the value from another SumType into this one.
See the value-assignment overload for details on @safety.
Authors
Paul Backus
License
Boost License 1.0