Re: [PATCH] D18938: is_integral_or_enum ❥ enum class ⇒ hashable enum class
JF Bastien via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 9 13:08:22 PDT 2016
jfb updated this revision to Diff 53150.
jfb added a comment.
- Use underlying_type
http://reviews.llvm.org/D18938
Files:
include/llvm/ADT/Hashing.h
include/llvm/Support/type_traits.h
Index: include/llvm/Support/type_traits.h
===================================================================
--- include/llvm/Support/type_traits.h
+++ include/llvm/Support/type_traits.h
@@ -54,20 +54,22 @@
};
/// \brief Metafunction that determines whether the given type is either an
-/// integral type or an enumeration type.
+/// integral type or an enumeration type, including enum classes.
///
/// Note that this accepts potentially more integral types than is_integral
-/// because it is based on merely being convertible implicitly to an integral
-/// type.
+/// because it is based on being implicitly convertible to an integral type.
+/// Also note that enum classes aren't implicitly convertible to integral types,
+/// the value may therefore need to be explicitly converted before being used.
template <typename T> class is_integral_or_enum {
typedef typename std::remove_reference<T>::type UnderlyingT;
public:
static const bool value =
!std::is_class<UnderlyingT>::value && // Filter conversion operators.
!std::is_pointer<UnderlyingT>::value &&
!std::is_floating_point<UnderlyingT>::value &&
- std::is_convertible<UnderlyingT, unsigned long long>::value;
+ (std::is_enum<UnderlyingT>::value ||
+ std::is_convertible<UnderlyingT, unsigned long long>::value);
};
/// \brief If T is a pointer, just return it. If it is not, return T&.
Index: include/llvm/ADT/Hashing.h
===================================================================
--- include/llvm/ADT/Hashing.h
+++ include/llvm/ADT/Hashing.h
@@ -632,7 +632,8 @@
template <typename T>
typename std::enable_if<is_integral_or_enum<T>::value, hash_code>::type
hash_value(T value) {
- return ::llvm::hashing::detail::hash_integer_value(value);
+ return ::llvm::hashing::detail::hash_integer_value(
+ static_cast<typename std::underlying_type<T>::type>(value));
}
// Declared and documented above, but defined here so that any of the hashing
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18938.53150.patch
Type: text/x-patch
Size: 1978 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160409/05538c80/attachment.bin>
More information about the llvm-commits
mailing list