Debian Codegraph @

gcc/testsuite/gdc.test/compilable/b19294.d

raw
1 alias MT = MyStruct!int;
2
3 struct MyStruct(T)
4 {
5 T x;
6
7 this(T y)
8 {
9 x = y;
10 }
11
12 MyStruct!T opBinary(string op)(MyStruct!T y) const
13 {
14 alias C = typeof(return);
15 auto w = C(this.x);
16 return w.opOpAssign!(op)(y);
17 }
18
19 MyStruct!T opBinaryRight(string op)(MyStruct!T y) const
20 {
21 return opBinary!(op)(y);
22 }
23
24 ref MyStruct opOpAssign(string op, T)(const MyStruct!T z)
25 {
26 mixin ("x "~op~"= z.x;");
27 return this;
28 }
29
30 MyStruct!T opBinary(string op)(T y) const
31 {
32 alias C = typeof(return);
33 auto w = C(this.x);
34 return w.opOpAssign!(op)(y);
35 }
36
37 MyStruct!T opBinaryRight(string op)(T y) const
38 {
39 return opBinary!(op)(y);
40 }
41
42 ref MyStruct opOpAssign(string op, T)(const T z)
43 {
44 mixin ("x "~op~"= z;");
45 return this;
46 }
47 }
48
49 void test()
50 {
51 MT s = MyStruct!int(1);
52 MT[] arr = [s, 2 * s, 3 * s, 4 * s, 5 * s, 6 * s];
53 MT[] result = new MT[arr.length];
54
55 result[] = arr[] + s;
56 result[] = s + arr[];
57
58 result[] = arr[] - s;
59 result[] = s - arr[];
60
61 result[] = arr[] * s;
62 result[] = s * arr[];
63
64 result[] = arr[] / s;
65 result[] = s / arr[];
66
67 result[] = arr[] ^^ s;
68 result[] = s ^^ arr[];
69 }