5 /******************************************************/
9 assert(typeid(int) == typeid(int));
10 assert(typeid(int) != typeid(uint));
13 /******************************************************/
21 printf("%d arguments\n", _arguments.length);
22 for (int i = 0; i < _arguments.length; i++)
24 writeln(_arguments[i].toString());
26 if (_arguments[i] is typeid(int))
28 int j = va_arg!int(_argptr);
32 else if (_arguments[i] == typeid(long))
34 long j = va_arg!long(_argptr);
35 printf("\t%lld\n", j);
38 else if (_arguments[i] is typeid(double))
40 double d = va_arg!double(_argptr);
44 else if (_arguments[i] is typeid(FOO3))
46 FOO3 f = va_arg!FOO3(_argptr);
66 /******************************************************/
73 assert(!(ti is null));
74 ti = typeid(double[]);
75 assert(!(ti is null));
77 assert(!(ti is null));
79 ti = typeid(ifloat[]);
80 assert(!(ti is null));
81 ti = typeid(idouble[]);
82 assert(!(ti is null));
84 assert(!(ti is null));
86 ti = typeid(cfloat[]);
87 assert(!(ti is null));
88 ti = typeid(cdouble[]);
89 assert(!(ti is null));
91 assert(!(ti is null));
94 assert(!(ti is null));
96 assert(!(ti is null));
98 assert(!(ti is null));
101 /******************************************************/
105 TypeInfo ti = typeid(void*);
106 assert(!(ti is null));
107 assert(ti.tsize==(void*).sizeof);
108 assert(ti.toString()=="void*");
111 /******************************************************/
115 TypeInfo ti = typeid(bool*);
116 assert(!(ti is null));
117 assert(ti.tsize==(bool*).sizeof);
118 assert(ti.toString()=="bool*");
121 /******************************************************/
125 TypeInfo ti = typeid(byte*);
126 assert(!(ti is null));
127 assert(ti.tsize==(byte*).sizeof);
128 assert(ti.toString()=="byte*");
131 /******************************************************/
135 TypeInfo ti = typeid(byte[]);
136 assert(!(ti is null));
137 assert(ti.tsize==(byte[]).sizeof);
138 assert(ti.toString()=="byte[]");
141 /******************************************************/
145 TypeInfo ti = typeid(short*);
146 assert(!(ti is null));
147 assert(ti.tsize==(short*).sizeof);
148 assert(ti.toString()=="short*");
151 /******************************************************/
155 TypeInfo ti = typeid(ushort*);
156 assert(!(ti is null));
157 assert(ti.tsize==(ushort*).sizeof);
158 assert(ti.toString()=="ushort*");
161 /******************************************************/
165 TypeInfo ti = typeid(int*);
166 assert(!(ti is null));
167 assert(ti.tsize==(int*).sizeof);
168 assert(ti.toString()=="int*");
171 /******************************************************/
175 TypeInfo ti = typeid(uint*);
176 assert(!(ti is null));
177 assert(ti.tsize==(uint*).sizeof);
178 assert(ti.toString()=="uint*");
181 /******************************************************/
185 TypeInfo ti = typeid(ulong*);
186 assert(!(ti is null));
187 assert(ti.tsize==(ulong*).sizeof);
188 assert(ti.toString()=="ulong*");
191 /******************************************************/
195 TypeInfo ti = typeid(long*);
196 assert(!(ti is null));
197 assert(ti.tsize==(long*).sizeof);
198 assert(ti.toString()=="long*");
201 /******************************************************/
205 TypeInfo ti = typeid(float*);
206 assert(!(ti is null));
207 assert(ti.tsize==(float*).sizeof);
208 assert(ti.toString()=="float*");
211 /******************************************************/
215 TypeInfo ti = typeid(ifloat*);
216 assert(!(ti is null));
217 assert(ti.tsize==(ifloat*).sizeof);
218 assert(ti.toString()=="ifloat*");
221 /******************************************************/
225 TypeInfo ti = typeid(cfloat*);
226 assert(!(ti is null));
227 assert(ti.tsize==(cfloat*).sizeof);
228 assert(ti.toString()=="cfloat*");
231 /******************************************************/
235 TypeInfo ti = typeid(double*);
236 assert(!(ti is null));
237 assert(ti.tsize==(double*).sizeof);
238 assert(ti.toString()=="double*");
241 /******************************************************/
245 TypeInfo ti = typeid(idouble*);
246 assert(!(ti is null));
247 assert(ti.tsize==(idouble*).sizeof);
248 assert(ti.toString()=="idouble*");
251 /******************************************************/
255 TypeInfo ti = typeid(cdouble*);
256 assert(!(ti is null));
257 assert(ti.tsize==(cdouble*).sizeof);
258 assert(ti.toString()=="cdouble*");
261 /******************************************************/
265 TypeInfo ti = typeid(real*);
266 assert(!(ti is null));
267 assert(ti.tsize==(real*).sizeof);
268 assert(ti.toString()=="real*");
271 /******************************************************/
275 TypeInfo ti = typeid(ireal*);
276 assert(!(ti is null));
277 assert(ti.tsize==(ireal*).sizeof);
278 assert(ti.toString()=="ireal*");
281 /******************************************************/
285 TypeInfo ti = typeid(creal*);
286 assert(!(ti is null));
287 assert(ti.tsize==(creal*).sizeof);
288 assert(ti.toString()=="creal*");
291 /******************************************************/
295 TypeInfo ti = typeid(char*);
296 assert(!(ti is null));
297 assert(ti.tsize==(char*).sizeof);
298 assert(ti.toString()=="char*");
301 /******************************************************/
305 TypeInfo ti = typeid(wchar*);
306 assert(!(ti is null));
307 assert(ti.tsize==(wchar*).sizeof);
308 assert(ti.toString()=="wchar*");
311 /******************************************************/
315 TypeInfo ti = typeid(dchar*);
316 assert(!(ti is null));
317 assert(ti.tsize==(dchar*).sizeof);
318 assert(ti.toString()=="dchar*");
321 /******************************************************/
327 TypeInfo ti = typeid(MyEnum);
328 assert(!(ti is null));
329 assert(ti.tsize==(MyEnum).sizeof);
330 assert(ti.toString()=="testtypeid.MyEnum");
333 /******************************************************/
337 alias void function() func;
338 TypeInfo ti = typeid(func);
340 assert(ti.tsize == func.sizeof);
343 /******************************************************/
347 alias int delegate() del;
348 TypeInfo ti = typeid(del);
350 assert(ti.tsize == del.sizeof);
353 /******************************************************/
357 TypeInfo ti = typeid(void);
358 assert(!(ti is null));
359 assert(ti.tsize == void.sizeof);
360 assert(ti.toString()=="void");
363 /******************************************************/
365 class Foo32 { int x = 3; }
366 class Bar32 { long y = 4; }
368 void printargs(int x, ...)
370 printf("%d arguments\n", _arguments.length);
371 for (int i = 0; i < _arguments.length; i++)
373 writeln(_arguments[i].toString());
375 if (_arguments[i] == typeid(int))
377 int j = va_arg!int(_argptr);
380 else if (_arguments[i] == typeid(long))
382 long j = va_arg!long(_argptr);
383 printf("\t%lld\n", j);
385 else if (_arguments[i] == typeid(double))
387 double d = va_arg!double(_argptr);
390 else if (_arguments[i] == typeid(Foo32))
392 Foo32 f = va_arg!Foo32(_argptr);
396 else if (_arguments[i] == typeid(Bar32))
398 Bar32 b = va_arg!Bar32(_argptr);
409 Foo32 f = new Foo32();
410 Bar32 b = new Bar32();
413 printargs(1, 2, 3L, 4.5, f, b);
416 /******************************************************/
422 /******************************************************/
428 auto a = typeid(C).info;
431 /******************************************************/
435 auto ti = typeid(shared(int));
437 auto sti = cast(TypeInfo_Shared)ti;
440 // allow both next and base as field names in TypeInfo_Const
441 static if (is(typeof(&sti.base) == TypeInfo*))
442 assert(sti.base == typeid(int));
444 assert(sti.next == typeid(int));
447 /******************************************************/
452 assert(typeid(i++) == typeid(int));
454 assert(typeid(i + 1) == typeid(int));
457 /******************************************************/
465 //writeln(typeid(A));
466 assert(typeid(a) == typeid(B37));
469 /******************************************************/
475 TypeInfo ti = typeid(cent*);
476 assert(!(ti is null));
477 assert(ti.tsize==(cent*).sizeof);
478 assert(ti.toString()=="cent*");
482 /******************************************************/
486 static if (is(ucent))
488 TypeInfo ti = typeid(ucent*);
489 assert(!(ti is null));
490 assert(ti.tsize==(ucent*).sizeof);
491 assert(ti.toString()=="ucent*");
495 /******************************************************/
502 assert(typeid(i++) == typeid(cent));
504 assert(typeid(i + 1) == typeid(cent));
508 /******************************************************/
516 auto x = typeid(c); // NG
517 auto y = typeid(this.c); // ok
528 /******************************************************/
540 Foo10451*[] foos = [];
542 foos = new Foo10451*[2];
545 /******************************************************/
548 struct S11010 { S11010* p; }
550 class C11010 { C11010 p; }
551 class D11010 : C11010 {}
559 assert(cast(TypeInfo_Pointer)ti !is null);
560 assert(ti.toString() == "testtypeid.S11010*");
562 C11010 c = new C11010();
565 assert(cast(TypeInfo_Class)ti !is null);
566 assert(ti.toString() == "testtypeid.D11010");
569 /******************************************************/
583 assert(typeid(S).getHash(&s1) == typeid(S).getHash(&s2)); // should succeed
588 bool thrown(T)(lazy T cond)
590 import core.exception;
600 size_t toHash() const nothrow @safe
602 // all getHash call should reach here
611 assert(thrown(typeid(S).getHash(&s))); // OK
613 assert(thrown(typeid(S[1]).getHash(&ssa))); // OK
614 S[] sda = [S(), S()];
615 assert(thrown(typeid(S[]).getHash(&sda))); // OK
618 assert(thrown(typeid(T).getHash(&t))); // OK <- NG
620 assert(thrown(typeid(T[1]).getHash(&tsa))); // OK <- NG
621 T[] tda = [T(), T()];
622 assert(thrown(typeid(T[]).getHash(&tda))); // OK <- NG
625 /******************************************************/
630 auto tid = typeid(null);
631 auto iz = tid.initializer();
632 assert(iz.length == typeof(null).sizeof);
633 assert(iz.ptr is null || *(cast(void**)iz.ptr) is null);
636 /******************************************************/