mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
97 lines
2.3 KiB
D
97 lines
2.3 KiB
D
|
|
template TT(T...) { alias T TT; }
|
|
|
|
void TestOpAssign(Tx, Ux, ops)()
|
|
{
|
|
foreach(T; Tx.x)
|
|
foreach(U; Ux.x)
|
|
foreach(op; ops.x)
|
|
{
|
|
T a = cast(T)1;
|
|
mixin("a " ~ op ~ " cast(U)1;");
|
|
}
|
|
}
|
|
|
|
void TestOpAssignAssign(Tx, Ux, ops)()
|
|
{
|
|
foreach(T; Tx.x)
|
|
foreach(U; Ux.x)
|
|
foreach(op; ops.x)
|
|
{
|
|
T a = cast(T)1;
|
|
U b = cast(U)1;
|
|
T r;
|
|
mixin("r = a " ~ op ~ " cast(U)1;");
|
|
}
|
|
}
|
|
|
|
void TestOpAssignAuto(Tx, Ux, ops)()
|
|
{
|
|
foreach(T; Tx.x)
|
|
foreach(U; Ux.x)
|
|
static if (U.sizeof <= T.sizeof)
|
|
foreach(op; ops.x)
|
|
{
|
|
T a = cast(T)1;
|
|
U b = cast(U)1;
|
|
mixin("auto r = a " ~ op ~ " cast(U)1;");
|
|
}
|
|
}
|
|
|
|
void TestOpAndAssign(Tx, Ux, ops)()
|
|
{
|
|
foreach(T; Tx.x)
|
|
foreach(U; Ux.x)
|
|
static if (U.sizeof <= T.sizeof && T.sizeof >= 4)
|
|
foreach(op; ops.x)
|
|
{
|
|
T a = cast(T)1;
|
|
U b = cast(U)1;
|
|
mixin("a = a " ~ op[0..$-1] ~ " cast(U)1;");
|
|
}
|
|
}
|
|
|
|
struct boolean { alias TT!(bool) x; }
|
|
struct integral { alias TT!(byte, ubyte, short, ushort, int, uint, long, ulong) x; }
|
|
struct floating { alias TT!(float, double, real) x; }
|
|
|
|
struct all { alias TT!("+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", ">>>=") x; }
|
|
struct arith { alias TT!("+=", "-=", "*=", "/=", "%=") x; }
|
|
struct bitwise { alias TT!("&=", "|=", "^=") x; }
|
|
struct shift { alias TT!("<<=", ">>=", ">>>=") x; }
|
|
struct addsub { alias TT!("+=", "-=") x; }
|
|
struct muldivmod { alias TT!("*=", "/=", "%=") x; }
|
|
struct nomod { alias TT!("+=", "-=", "*=", "/=") x; }
|
|
|
|
void OpAssignCases(alias X)()
|
|
{
|
|
X!(boolean, boolean, bitwise)();
|
|
|
|
X!(integral, boolean, all)();
|
|
X!(integral, integral, all)();
|
|
X!(integral, floating, arith)();
|
|
|
|
X!(floating, boolean, arith)();
|
|
X!(floating, integral, arith)();
|
|
X!(floating, floating, arith)();
|
|
}
|
|
|
|
void OpReAssignCases(alias X)()
|
|
{
|
|
X!(boolean, boolean, bitwise)();
|
|
|
|
X!(integral, boolean, all)();
|
|
X!(integral, integral, all)();
|
|
|
|
X!(floating, boolean, arith)();
|
|
X!(floating, integral, arith)();
|
|
X!(floating, floating, arith)();
|
|
}
|
|
|
|
void main()
|
|
{
|
|
OpAssignCases!TestOpAssign();
|
|
OpAssignCases!TestOpAssignAssign(); // was once disabled due to bug 7436
|
|
OpAssignCases!TestOpAssignAuto(); // https://issues.dlang.org/show_bug.cgi?id=5181
|
|
OpReAssignCases!TestOpAndAssign();
|
|
}
|