4 template TypeTuple(T
...) { alias TypeTuple
= T
; }
6 bool startsWith(string s
, string m
) { return s
[0 .. m
.length
] == m
; }
10 enum string castPrefix
= "cast(" ~ size_t
.stringof
~ ")";
13 static assert((int[10]).stringof
== "int[10]", T
.stringof
);
19 // index == IntegerExp
20 static assert((arr
[ 4 ]).stringof
== "arr[4]");
21 static assert((arr
[ 4U ]).stringof
== "arr[4]");
22 static assert((arr
[ 4L ]).stringof
== "arr[4]");
23 static assert((arr
[ 4LU]).stringof
== "arr[4]");
26 static assert((arr
[+4 ]).stringof
== "arr[4]");
27 static assert((arr
[+4U ]).stringof
== "arr[4]");
28 static assert((arr
[+4L ]).stringof
== "arr[4]");
29 static assert((arr
[+4LU]).stringof
== "arr[4]");
32 static assert((arr
[-4 ]).stringof
== "arr[" ~ castPrefix
~ "-4]");
33 static assert((arr
[-4U ]).stringof
== "arr[4294967292]");
34 static assert((arr
[int.min
] ).stringof
== "arr[" ~ castPrefix
~ "-2147483648]");
35 static if (is(size_t
== ulong))
37 static assert((arr
[-4L ]).stringof
== "arr[" ~ castPrefix
~ "-4L]");
38 static assert((arr
[-4LU]).stringof
== "arr[-4LU]");
40 // IntegerLiteral needs suffix if the value is greater than long.max
41 static assert((arr
[long.max
+ 0]).stringof
== "arr[9223372036854775807]");
42 static assert((arr
[long.max
+ 1]).stringof
== "arr[" ~ castPrefix
~ "(9223372036854775807L + 1L)]");
45 foreach (Int
; TypeTuple
!(byte, ubyte, short, ushort, int, uint, long, ulong))
48 enum string result1
= (arr
[p4
]).stringof
;
49 static assert(result1
== "arr[4]");
51 enum string result2
= (arr
[cast(Int
)+4]).stringof
;
52 static assert(result2
== "arr[4]");
54 foreach (Int
; TypeTuple
!(byte, short, int, long))
56 // keep "cast(Type)" in the string representation
59 static if (is(typeof({ size_t x
= m4
; })))
61 enum string result1
= (arr
[m4
]).stringof
;
62 static assert(result1
.startsWith("arr[" ~ castPrefix
));
65 static assert(!__traits(compiles
, arr
[m4
]));
67 enum string result2
= (arr
[cast(Int
)-4]).stringof
;
68 static assert(result2
.startsWith("arr[" ~ castPrefix
));
74 // lwr,upr == IntegerExp
75 static assert((arr
[4 .. 8 ]).stringof
== "arr[4..8]");
76 static assert((arr
[4U .. 8U ]).stringof
== "arr[4..8]");
77 static assert((arr
[4L .. 8L ]).stringof
== "arr[4..8]");
78 static assert((arr
[4LU .. 8LU]).stringof
== "arr[4..8]");
81 static assert((arr
[+4 .. +8 ]).stringof
== "arr[4..8]");
82 static assert((arr
[+4U .. +8U ]).stringof
== "arr[4..8]");
83 static assert((arr
[+4L .. +8L ]).stringof
== "arr[4..8]");
84 static assert((arr
[+4LU .. +8LU]).stringof
== "arr[4..8]");