Bug 1289033 - Add mozilla::UnderlyingType. r?froydnj
MozReview-Commit-ID: GOCMsqHbMmJ
--- a/mfbt/TypeTraits.h
+++ b/mfbt/TypeTraits.h
@@ -1186,16 +1186,37 @@ struct Conditional
};
template<class A, class B>
struct Conditional<false, A, B>
{
typedef B Type;
};
+/**
+ * Converts an enum to its underlying type.
+ *
+ * enum A { ... };
+ * enum class B { ... };
+ * enum C : uint8_t { ... };
+ * enum class D : int { ... };
+ *
+ * mozilla::UnderlyingType<A>::Type is an unspecified integral type;
+ * mozilla::UnderlyingType<B>::Type is int;
+ * mozilla::UnderlyingType<C>::Type is uint8_t;
+ * mozilla::UnderlyingType<D>::Type is int.
+ */
+template<typename T>
+struct UnderlyingType
+{
+ // __underlying_type is a supported extension across all of our supported
+ // compilers.
+ typedef __underlying_type(T) Type;
+};
+
namespace detail {
template<typename U,
bool IsArray = IsArray<U>::value,
bool IsFunction = IsFunction<U>::value>
struct DecaySelector;
template<typename U>