@@ -342,9 +342,7 @@ private class TypeInfoGeneric(T) : TypeInfo
342
342
343
343
override void swap (void * p1, void * p2)
344
344
{
345
- T t;
346
-
347
- t = * cast (T * )p1;
345
+ auto t = * cast (T * ) p1;
348
346
* cast (T * )p1 = * cast (T * )p2;
349
347
* cast (T * )p2 = t;
350
348
}
@@ -360,6 +358,30 @@ private class TypeInfoGeneric(T) : TypeInfo
360
358
override @property uint flags() const { return 2 ; }
361
359
}
362
360
361
+ unittest
362
+ {
363
+ assert (typeid (int ).toString == " int" );
364
+ double a = 42 , b = 43 ;
365
+ assert (typeid (double ).equals(&a, &a));
366
+ assert (! typeid (double ).equals(&a, &b));
367
+ assert (typeid (double ).compare(&a, &a) == 0 );
368
+ assert (typeid (double ).compare(&a, &b) == - 1 );
369
+ assert (typeid (double ).compare(&b, &a) == 1 );
370
+
371
+ short c = 42 , d = 43 ;
372
+ assert (typeid (short ).equals(&c, &c));
373
+ assert (! typeid (short ).equals(&c, &b));
374
+ assert (typeid (short ).compare(&c, &c) == 0 );
375
+ assert (typeid (short ).compare(&c, &d) == - 1 );
376
+ assert (typeid (short ).compare(&d, &c) == 1 );
377
+
378
+ assert (typeid (int ).initializer.ptr is null );
379
+ assert (typeid (int ).initializer.length == int .sizeof);
380
+
381
+ typeid (short ).swap(&d, &c);
382
+ assert (c == 43 && d == 42 );
383
+ }
384
+
363
385
private class TypeInfoArrayGeneric (T) : TypeInfo_Array
364
386
{
365
387
static if (is (T == ifloat )) private alias Real = float ;
@@ -426,6 +448,22 @@ private class TypeInfoArrayGeneric(T) : TypeInfo_Array
426
448
}
427
449
}
428
450
451
+ unittest
452
+ {
453
+ assert (typeid (int []) == typeid (int []));
454
+ assert (typeid (int []) != typeid (uint []));
455
+ assert (typeid (int []).toString == " int[]" );
456
+
457
+ double [] a = [ 1 , 2 , 3 ], b = [ 2 , 3 ];
458
+
459
+ assert (typeid (double []).equals(&a, &a));
460
+ assert (! typeid (double []).equals(&a, &b));
461
+
462
+ assert (typeid (double []).compare(&a, &a) == 0 );
463
+ assert (typeid (double []).compare(&a, &b) == - 1 );
464
+ assert (typeid (double []).compare(&b, &a) == 1 );
465
+ }
466
+
429
467
// //////////////////////////////////////////////////////////////////////////////
430
468
// Predefined TypeInfos
431
469
// //////////////////////////////////////////////////////////////////////////////
0 commit comments