Function std.experimental.checkedint.Checked.opOpAssign
Defines operators +=, -=, *=, /=, %=, ^^=, &=, |=, ^=,
<<=, >>=, and >>>=.
If Hook defines hookOpOpAssign, opOpAssign forwards to
hook, where payload is a reference to
the internally held data so the hook can change it.
Otherwise, the operator first evaluates auto result =
opBinary!op(payload, rhs), which is subject to the hooks in
opBinary. Then, if result is less than Checked!(T, Hook) and if
Hook defines onLowerBound, the payload is assigned from hook. If result is greater than Checked!(T,
Hook) and if Hook defines onUpperBound, the payload is assigned
from hook.
If the right-hand side is also a Checked but with a different hook or underlying type, the hook and underlying type of this Checked takes precedence.
In all other cases, the built-in behavior is carried out.
Parameters
| Name | Description |
|---|---|
| op | The operator involved (without the "=", e.g. "+" for "+=" etc) |
| rhs | The right-hand side of the operator (left-hand side is this) |
Returns
A reference to this.
Example
static struct MyHook
{
static bool thereWereErrors;
static T onLowerBound(Rhs, T)(Rhs rhs, T bound)
{
thereWereErrors = true;
return bound;
}
static T onUpperBound(Rhs, T)(Rhs rhs, T bound)
{
thereWereErrors = true;
return bound;
}
}
auto x = checked!MyHook(byte .min);
x -= 1;
assert(MyHook .thereWereErrors);
MyHook .thereWereErrors = false;
x = byte .max;
x += 1;
assert(MyHook .thereWereErrors);
}