OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return a == b.get(); | 191 return a == b.get(); |
192 } | 192 } |
193 }; | 193 }; |
194 | 194 |
195 // Default hash function for each type. | 195 // Default hash function for each type. |
196 template <typename T> | 196 template <typename T> |
197 struct DefaultHash; | 197 struct DefaultHash; |
198 | 198 |
199 // Actual implementation of DefaultHash. | 199 // Actual implementation of DefaultHash. |
200 // | 200 // |
201 // The case of |isIntegral| == false is not implemented. If you see a compile | 201 // The case of |isIntegralOrEnum| == false is not implemented. If you see a |
202 // error saying DefaultHashImpl<T, false> is not defined, that's because the | 202 // compile error saying DefaultHashImpl<T, false> is not defined, that's because |
203 // default hash functions for T are not defined. You need to implement them | 203 // the default hash functions for T are not defined. You need to implement them |
204 // yourself. | 204 // yourself. |
205 template <typename T, bool isIntegral> | 205 template <typename T, bool isIntegralOrEnum> |
206 struct DefaultHashImpl; | 206 struct DefaultHashImpl; |
207 | 207 |
208 template <typename T> | 208 template <typename T> |
209 struct DefaultHashImpl<T, true> { | 209 struct DefaultHashImpl<T, true> { |
210 using Hash = IntHash<typename std::make_unsigned<T>::type>; | 210 using Hash = IntHash<T>; |
211 }; | 211 }; |
212 | 212 |
213 // Canonical implementation of DefaultHash. | 213 // Canonical implementation of DefaultHash. |
214 template <typename T> | 214 template <typename T> |
215 struct DefaultHash : DefaultHashImpl<T, std::is_integral<T>::value> {}; | 215 struct DefaultHash |
| 216 : DefaultHashImpl<T, std::is_integral<T>::value || std::is_enum<T>::value> { |
| 217 }; |
216 | 218 |
217 // Specializations of DefaultHash follow. | 219 // Specializations of DefaultHash follow. |
218 template <> | 220 template <> |
219 struct DefaultHash<float> { | 221 struct DefaultHash<float> { |
220 using Hash = FloatHash<float>; | 222 using Hash = FloatHash<float>; |
221 }; | 223 }; |
222 template <> | 224 template <> |
223 struct DefaultHash<double> { | 225 struct DefaultHash<double> { |
224 using Hash = FloatHash<double>; | 226 using Hash = FloatHash<double>; |
225 }; | 227 }; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 using Hash = PairHash<T, U>; | 284 using Hash = PairHash<T, U>; |
283 }; | 285 }; |
284 | 286 |
285 } // namespace WTF | 287 } // namespace WTF |
286 | 288 |
287 using WTF::DefaultHash; | 289 using WTF::DefaultHash; |
288 using WTF::IntHash; | 290 using WTF::IntHash; |
289 using WTF::PtrHash; | 291 using WTF::PtrHash; |
290 | 292 |
291 #endif // WTF_HashFunctions_h | 293 #endif // WTF_HashFunctions_h |
OLD | NEW |