std.experimental.checkedint should support chain assignment.

Cf. bug #21169.
This commit is contained in:
H. S. Teoh 2020-08-17 10:19:56 -07:00 committed by The Dlang Bot
parent f97c2c05be
commit 34a14509d2

View file

@ -351,12 +351,14 @@ if (isIntegral!T || is(T == Checked!(U, H), U, H))
/** /**
Assignment operator. Has the same constraints as the constructor. Assignment operator. Has the same constraints as the constructor.
*/ */
void opAssign(U)(U rhs) if (is(typeof(Checked!(T, Hook)(rhs)))) ref Checked opAssign(U)(U rhs) return
if (is(typeof(Checked!(T, Hook)(rhs))))
{ {
static if (isIntegral!U) static if (isIntegral!U)
payload = rhs; payload = rhs;
else else
payload = rhs.payload; payload = rhs.payload;
return this;
} }
/// ///
@system unittest @system unittest
@ -368,6 +370,14 @@ if (isIntegral!T || is(T == Checked!(U, H), U, H))
assert(a == 4242); assert(a == 4242);
} }
///
@system unittest
{
Checked!long a, b;
a = b = 3;
assert(a == 3 && b == 3);
}
// opCast // opCast
/** /**
Casting operator to integral, `bool`, or floating point type. If `Hook` Casting operator to integral, `bool`, or floating point type. If `Hook`