Function std.experimental.checkedint.Checked.opOpAssign
Defines operators +=
, -=
, *=
, /=
, %=
, ^^=
, &=
, |=
, ^=
,
<<=
, >>=
, and >>>=
.
ref Checked opOpAssign(string op, Rhs)
(
const Rhs rhs
) return
if (isIntegral!Rhs || isFloatingPoint!Rhs || is(Rhs == bool));
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
.
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);
}