|
| 1 | +/** |
| 2 | + * TypeInfo support code. |
| 3 | + * |
| 4 | + * Copyright: Copyright Digital Mars 2004 - 2009. |
| 5 | + * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). |
| 6 | + * Authors: Walter Bright |
| 7 | + */ |
| 8 | + |
| 9 | +/* Copyright Digital Mars 2004 - 2009. |
| 10 | + * Distributed under the Boost Software License, Version 1.0. |
| 11 | + * (See accompanying file LICENSE or copy at |
| 12 | + * http://www.boost.org/LICENSE_1_0.txt) |
| 13 | + */ |
| 14 | +module rt.typeinfo.ti_A; |
| 15 | + |
| 16 | +private import rt.util.typeinfo; |
| 17 | + |
| 18 | +// cdouble[] |
| 19 | +class TypeInfo_Ar : Impl_TypeInfo_A!cdouble {} |
| 20 | + |
| 21 | +// cfloat[] |
| 22 | +class TypeInfo_Aq : Impl_TypeInfo_A!cfloat {} |
| 23 | + |
| 24 | +// creal[] |
| 25 | +class TypeInfo_Ac : Impl_TypeInfo_A!creal {} |
| 26 | + |
| 27 | +// double[] |
| 28 | +class TypeInfo_Ad : Impl_TypeInfo_A!double {} |
| 29 | + |
| 30 | +// idouble[] |
| 31 | +class TypeInfo_Ap : Impl_TypeInfo_A!idouble {} |
| 32 | + |
| 33 | +// float[] |
| 34 | +class TypeInfo_Af : Impl_TypeInfo_A!float {} |
| 35 | + |
| 36 | +// ifloat[] |
| 37 | +class TypeInfo_Ao : Impl_TypeInfo_A!ifloat {} |
| 38 | + |
| 39 | +// byte[] |
| 40 | +class TypeInfo_Ag : Impl_TypeInfo_A!byte {} |
| 41 | + |
| 42 | +// ubyte[] |
| 43 | +class TypeInfo_Ah : Impl_TypeInfo_A!ubyte {}; |
| 44 | + |
| 45 | +// void[] |
| 46 | +class TypeInfo_Av : Impl_TypeInfo_A!void {} |
| 47 | + |
| 48 | +// bool[] |
| 49 | +class TypeInfo_Ab : Impl_TypeInfo_A!bool {} |
| 50 | + |
| 51 | +// char[] |
| 52 | +class TypeInfo_Aa : Impl_TypeInfo_A!char {} |
| 53 | + |
| 54 | +// string |
| 55 | +class TypeInfo_Aya : Impl_TypeInfo_A!(immutable(char)) {} |
| 56 | + |
| 57 | +// const(char)[] |
| 58 | +class TypeInfo_Axa : Impl_TypeInfo_A!(const(char)) {} |
| 59 | + |
| 60 | + |
| 61 | +extern (C) void[] _adSort(void[] a, TypeInfo ti); |
| 62 | + |
| 63 | +// int[] |
| 64 | +class TypeInfo_Ai : Impl_TypeInfo_A!int {} |
| 65 | + |
| 66 | +unittest |
| 67 | +{ |
| 68 | + int[][] a = [[5,3,8,7], [2,5,3,8,7]]; |
| 69 | + _adSort(*cast(void[]*)&a, typeid(a[0])); |
| 70 | + assert(a == [[2,5,3,8,7], [5,3,8,7]]); |
| 71 | + |
| 72 | + a = [[5,3,8,7], [5,3,8]]; |
| 73 | + _adSort(*cast(void[]*)&a, typeid(a[0])); |
| 74 | + assert(a == [[5,3,8], [5,3,8,7]]); |
| 75 | +} |
| 76 | + |
| 77 | +unittest |
| 78 | +{ |
| 79 | + // Issue 13073: original code uses int subtraction which is susceptible to |
| 80 | + // integer overflow, causing the following case to fail. |
| 81 | + int[] a = [int.max, int.max]; |
| 82 | + int[] b = [int.min, int.min]; |
| 83 | + assert(a > b); |
| 84 | + assert(b < a); |
| 85 | +} |
| 86 | + |
| 87 | +// uint[] |
| 88 | +class TypeInfo_Ak : Impl_TypeInfo_A!uint {} |
| 89 | + |
| 90 | +unittest |
| 91 | +{ |
| 92 | + // Original test case from issue 13073 |
| 93 | + uint x = 0x22_DF_FF_FF; |
| 94 | + uint y = 0xA2_DF_FF_FF; |
| 95 | + assert(!(x < y && y < x)); |
| 96 | + uint[] a = [x]; |
| 97 | + uint[] b = [y]; |
| 98 | + assert(!(a < b && b < a)); // Original failing case |
| 99 | + uint[1] a1 = [x]; |
| 100 | + uint[1] b1 = [y]; |
| 101 | + assert(!(a1 < b1 && b1 < a1)); // Original failing case |
| 102 | +} |
| 103 | + |
| 104 | +// dchar[] |
| 105 | +class TypeInfo_Aw : Impl_TypeInfo_A!dchar {} |
| 106 | + |
| 107 | + |
| 108 | +// long[] |
| 109 | +class TypeInfo_Al : Impl_TypeInfo_A!long {} |
| 110 | + |
| 111 | +// ulong[] |
| 112 | +class TypeInfo_Am : Impl_TypeInfo_A!ulong {} |
| 113 | + |
| 114 | +// real[] |
| 115 | +class TypeInfo_Ae : Impl_TypeInfo_A!real {} |
| 116 | + |
| 117 | +// ireal[] |
| 118 | +class TypeInfo_Aj : Impl_TypeInfo_A!ireal {} |
| 119 | + |
| 120 | +// short[] |
| 121 | +class TypeInfo_As : Impl_TypeInfo_A!short {} |
| 122 | + |
| 123 | +// ushort[] |
| 124 | +class TypeInfo_At : Impl_TypeInfo_A!ushort {} |
| 125 | + |
| 126 | +// wchar[] |
| 127 | +class TypeInfo_Au : Impl_TypeInfo_A!wchar {} |
0 commit comments