Debian Codegraph @

gcc/testsuite/gdc.test/compilable/imports/test21098_phobos.d

raw
1 struct Nullable(T)
2 {
3 static struct DontCallDestructorT
4 {
5 T payload;
6 }
7
8 DontCallDestructorT _value;
9
10 string toString() const
11 {
12 Appender!string app;
13 formatValueImpl(app, _value);
14 return null;
15 }
16 }
17
18
19
20 struct Appender(A)
21 {
22 InPlaceAppender!A impl;
23 }
24
25 struct InPlaceAppender(T)
26 {
27 static void toStringImpl(const T[] data)
28 {
29 string app;
30 formatValue(app, data);
31 }
32 }
33
34
35
36 void formatValueImpl(Writer, T)(Writer, const(T)) {}
37
38 void formatValueImpl(Writer, T)(Writer w, T obj)
39 if (is(T == U[], U))
40 {
41 formatValue(w, obj[0]);
42 }
43
44 enum HasToStringResult
45 {
46 none,
47 bla
48 }
49
50 template hasToString(T)
51 {
52 static if (is(typeof(
53 (T val) {
54 val.toString(s);
55 })))
56 enum hasToString = HasToStringResult.bla;
57 else
58 enum hasToString = HasToStringResult.none;
59 }
60
61 void formatValueImpl(Writer, T)(ref Writer w, T val)
62 if (is(T == struct) || is(T == union))
63 {
64 static if (hasToString!T)
65 int dummy;
66 formatElement(w, val.tupleof);
67 }
68
69 void formatElement(Writer, T)(Writer w, T val)
70 {
71 formatValueImpl(w, val);
72 }
73
74 void formatValue(Writer, T)(Writer w, T val)
75 {
76 formatValueImpl(w, val);
77 }