]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/compilable/test15019.d
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / compilable / test15019.d
1 // https://issues.dlang.org/show_bug.cgi?id=15019
2 // dmd -m32 -c all.d
3
4 import std.string;
5
6 struct Color()
7 {
8 static fromHex(char[] s)
9 {
10 import std.conv;
11 s.to!ubyte;
12 }
13 }
14
15 Color!() RGB ;
16
17 struct Matrix(T, int R, int C)
18 {
19 Vector!(T, C) row_t;
20 T[C] v; // all elements
21
22 /// Covnerts to pretty string.
23 string toString() const
24 {
25 try
26 return format("%s", v);
27 catch
28 assert(false); // should not happen since format is right
29 }
30 }
31
32 // GLSL is a big inspiration here
33 // we defines types with more or less the same names
34 template mat2x2(T) { Matrix!(T, 2, 2) mat2x2; }
35 template mat3x3(T) { Matrix!(T, 3, 3) mat3x3; }
36 template mat4x4(T) { Matrix!(T, 4, 4) mat4x4; }
37
38 alias mat2x2 mat2;
39 alias mat3x3 mat3; // shorter names for most common matrices
40 alias mat4x4 mat4;
41
42 string definePostfixAliases(string type)
43 {
44 return "alias " ~ type ~ "!byte " ~ type ~ "b;\n"
45 "alias " ~ type ~ "!ubyte " ~ type ~ "ub;\n"
46 "alias " ~ type ~ "!short " ~ type ~ "s;\n"
47 "alias " ~ type ~ "!ushort " ~ type ~ "us;\n"
48 "alias " ~ type ~ "!int " ~ type ~ "i;\n"
49 "alias " ~ type ~ "!uint " ~ type ~ "ui;\n"
50 "alias " ~ type ~ "!long " ~ type ~ "l;\n"
51 "alias " ~ type ~ "!ulong " ~ type ~ "ul;\n"
52 "alias " ~ type ~ "!float " ~ type ~ "f;\n"
53 "alias " ~ type ~ "!double " ~ type ~ "d;\n";
54 }
55
56 // define a lot of type names
57 mixin(definePostfixAliases("mat2"));
58 mixin(definePostfixAliases("mat3"));
59 mixin(definePostfixAliases("mat4"));
60 import std.string;
61
62 struct Vector(T, int N)
63 {
64 T[N] v;
65
66 string toString()
67 {
68 try
69 return format("%s", v);
70 catch
71 assert(false);
72 }
73 }
74