Changeset 104333 in webkit
- Timestamp:
- Jan 6, 2012 1:57:22 PM (12 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r104330 r104333 1 2012-01-06 Sam Weinig <sam@webkit.org> 2 3 Add a DecayArray type trait as a first step towards merging OwnPtr and OwnArrayPtr 4 https://bugs.webkit.org/show_bug.cgi?id=75737 5 6 Reviewed by Anders Carlsson. 7 8 * wtf/TypeTraits.cpp: 9 * wtf/TypeTraits.h: 10 Added a DecayArray trait, that can convert T[] and T[3] -> T*. DecayArray 11 is composed of some helpers which are also exposed, Conditional<>, which 12 can provide one type or another based on a boolean predicate, IsArray<> 13 which can deduce array types, and RemoveExtent<>, which removes the extent 14 from an array type. 15 1 16 2012-01-06 Oliver Hunt <oliver@apple.com> 2 17 -
trunk/Source/JavaScriptCore/wtf/TypeTraits.cpp
r69236 r104333 140 140 COMPILE_ASSERT((IsSameType<int, RemoveReference<int&>::Type>::value), WTF_Test_RemoveReference_int_reference); 141 141 142 143 typedef int IntArray[]; 144 typedef int IntArraySized[4]; 145 146 COMPILE_ASSERT((IsArray<IntArray>::value), WTF_Test_IsArray_int_array); 147 COMPILE_ASSERT((IsArray<IntArraySized>::value), WTF_Test_IsArray_int_sized_array); 148 149 COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArray>::Type>::value), WTF_Test_RemoveExtent_int_array); 150 COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArraySized>::Type>::value), WTF_Test_RemoveReference_int_sized_array); 151 152 COMPILE_ASSERT((IsSameType<int*, DecayArray<IntArray>::Type>::value), WTF_Test_DecayArray_int_array); 153 COMPILE_ASSERT((IsSameType<int*, DecayArray<IntArraySized>::Type>::value), WTF_Test_DecayArray_int_sized_array); 154 155 COMPILE_ASSERT((IsSameType<int*, DecayArray<IntArray&>::Type>::value), WTF_Test_DecayArray_int_array_reference); 156 COMPILE_ASSERT((IsSameType<int*, DecayArray<IntArraySized&>::Type>::value), WTF_Test_DecayArray_int_sized_array_reference); 157 142 158 } // namespace WTF -
trunk/Source/JavaScriptCore/wtf/TypeTraits.h
r85945 r104333 36 36 // The following are provided in this file: 37 37 // 38 // Conditional<Predicate, If, Then>::Type 39 // 38 40 // IsInteger<T>::value 39 41 // IsPod<T>::value, see the definition for a note about its limitations 40 42 // IsConvertibleToInteger<T>::value 43 // 44 // IsArray<T>::value 41 45 // 42 46 // IsSameType<T, U>::value … … 47 51 // RemoveVolatile<T>::Type 48 52 // RemoveConstVolatile<T>::Type 53 // RemoveExtent<T>::Type 54 // 55 // DecayArray<T>::Type 49 56 // 50 57 // COMPILE_ASSERT's in TypeTraits.cpp illustrate their usage and what they do. 58 59 template <bool Predicate, class If, class Then> struct Conditional { typedef If Type; }; 60 template <class If, class Then> struct Conditional<false, If, Then> { typedef Then Type; }; 51 61 52 62 template<typename T> struct IsInteger { static const bool value = false; }; … … 105 115 }; 106 116 117 118 template <class T> struct IsArray { 119 static const bool value = false; 120 }; 121 122 template <class T> struct IsArray<T[]> { 123 static const bool value = true; 124 }; 125 126 template <class T, size_t N> struct IsArray<T[N]> { 127 static const bool value = true; 128 }; 129 130 107 131 template <typename T, typename U> struct IsSameType { 108 132 static const bool value = false; … … 181 205 template <typename T> struct RemoveReference<T&> { 182 206 typedef T Type; 207 }; 208 209 template <typename T> struct RemoveExtent { 210 typedef T Type; 211 }; 212 213 template <typename T> struct RemoveExtent<T[]> { 214 typedef T Type; 215 }; 216 217 template <typename T, size_t N> struct RemoveExtent<T[N]> { 218 typedef T Type; 219 }; 220 221 template <class T> struct DecayArray { 222 typedef typename RemoveReference<T>::Type U; 223 public: 224 typedef typename Conditional< 225 IsArray<U>::value, 226 typename RemoveExtent<U>::Type*, 227 typename RemoveConstVolatile<U>::Type 228 >::Type Type; 183 229 }; 184 230
Note: See TracChangeset
for help on using the changeset viewer.