| 1 |
|
| 2 |
template TT(T...) { alias T TT; } |
| 3 |
|
| 4 |
void TestOpAssign(Tx, Ux, ops)() |
| 5 |
{ |
| 6 |
foreach(T; Tx.x) |
| 7 |
foreach(U; Ux.x) |
| 8 |
foreach(op; ops.x) |
| 9 |
{ |
| 10 |
T a = cast(T)1; |
| 11 |
mixin("a " ~ op ~ " cast(U)1;"); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
void TestOpAssignAssign(Tx, Ux, ops)() |
| 16 |
{ |
| 17 |
foreach(T; Tx.x) |
| 18 |
foreach(U; Ux.x) |
| 19 |
foreach(op; ops.x) |
| 20 |
{ |
| 21 |
T a = cast(T)1; |
| 22 |
U b = cast(U)1; |
| 23 |
T r; |
| 24 |
mixin("r = a " ~ op ~ " cast(U)1;"); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
void TestOpAssignAuto(Tx, Ux, ops)() |
| 29 |
{ |
| 30 |
foreach(T; Tx.x) |
| 31 |
foreach(U; Ux.x) |
| 32 |
static if (U.sizeof <= T.sizeof) |
| 33 |
foreach(op; ops.x) |
| 34 |
{ |
| 35 |
T a = cast(T)1; |
| 36 |
U b = cast(U)1; |
| 37 |
mixin("auto r = a " ~ op ~ " cast(U)1;"); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
void TestOpAndAssign(Tx, Ux, ops)() |
| 42 |
{ |
| 43 |
foreach(T; Tx.x) |
| 44 |
foreach(U; Ux.x) |
| 45 |
static if (U.sizeof <= T.sizeof && T.sizeof >= 4) |
| 46 |
foreach(op; ops.x) |
| 47 |
{ |
| 48 |
T a = cast(T)1; |
| 49 |
U b = cast(U)1; |
| 50 |
mixin("a = a " ~ op[0..$-1] ~ " cast(U)1;"); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
struct boolean { alias TT!(bool) x; } |
| 55 |
struct integral { alias TT!(byte, ubyte, short, ushort, int, uint, long, ulong) x; } |
| 56 |
struct floating { alias TT!(float, double, real) x; } |
| 57 |
|
| 58 |
struct all { alias TT!("+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", ">>>=") x; } |
| 59 |
struct arith { alias TT!("+=", "-=", "*=", "/=", "%=") x; } |
| 60 |
struct bitwise { alias TT!("&=", "|=", "^=") x; } |
| 61 |
struct shift { alias TT!("<<=", ">>=", ">>>=") x; } |
| 62 |
struct addsub { alias TT!("+=", "-=") x; } |
| 63 |
struct muldivmod { alias TT!("*=", "/=", "%=") x; } |
| 64 |
struct nomod { alias TT!("+=", "-=", "*=", "/=") x; } |
| 65 |
|
| 66 |
void OpAssignCases(alias X)() |
| 67 |
{ |
| 68 |
X!(boolean, boolean, bitwise)(); |
| 69 |
|
| 70 |
X!(integral, boolean, all)(); |
| 71 |
X!(integral, integral, all)(); |
| 72 |
X!(integral, floating, arith)(); |
| 73 |
|
| 74 |
X!(floating, boolean, arith)(); |
| 75 |
X!(floating, integral, arith)(); |
| 76 |
X!(floating, floating, arith)(); |
| 77 |
} |
| 78 |
|
| 79 |
void OpReAssignCases(alias X)() |
| 80 |
{ |
| 81 |
X!(boolean, boolean, bitwise)(); |
| 82 |
|
| 83 |
X!(integral, boolean, all)(); |
| 84 |
X!(integral, integral, all)(); |
| 85 |
|
| 86 |
X!(floating, boolean, arith)(); |
| 87 |
X!(floating, integral, arith)(); |
| 88 |
X!(floating, floating, arith)(); |
| 89 |
} |
| 90 |
|
| 91 |
void main() |
| 92 |
{ |
| 93 |
OpAssignCases!TestOpAssign(); |
| 94 |
OpAssignCases!TestOpAssignAssign(); // was once disabled due to bug 7436 |
| 95 |
OpAssignCases!TestOpAssignAuto(); // https://issues.dlang.org/show_bug.cgi?id=5181 |
| 96 |
OpReAssignCases!TestOpAndAssign(); |
| 97 |
} |