Debian Codegraph @

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

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 Hello
5 World
6 from
7 CTFE
8 Hello[1 .. 3] = el
9 S.str
10 abcdefghij[2 .. 6] = cdef
11 ---
12 */
13
14 struct S
15 {
16 string str = "S.str";
17 alias str this;
18 }
19
20 int greeting(scope const char[][] values) pure nothrow @safe @nogc
21 {
22 const string newline = "\n";
23
24 foreach (const val; values)
25 {
26 __ctfeWrite(val);
27 __ctfeWrite(newline);
28 }
29
30 // Test slices
31 const val = values[0];
32 __ctfeWrite(val[]);
33 __ctfeWrite(['[','1',' ','.','.',' ','3',']',' ','=',' ']);
34 __ctfeWrite(val[1 .. 3]);
35 __ctfeWrite(newline);
36
37 S s;
38 __ctfeWrite(s);
39 __ctfeWrite(newline);
40
41 // Test mutable slices
42 char[10] buffer;
43 fill(buffer); // Avoid potential shortcuts for literals
44 __ctfeWrite(buffer[0 .. $]);
45 __ctfeWrite("[2 .. 6] = ");
46 __ctfeWrite(buffer[2 .. 6]);
47 __ctfeWrite(newline);
48
49 return 0;
50 }
51
52 void fill(ref char[10] buffer) pure nothrow @safe @nogc
53 {
54 foreach (const idx, ref ch; buffer)
55 ch = cast(char)('a' + idx);
56 }
57
58 enum forceCTFE = greeting(["Hello", "World", "from", "CTFE"]);