Bug 865036 - Implement mozilla::Is{S,Uns}igned. r=froydnj
authorJeff Walden <jwalden@mit.edu>
Tue, 23 Apr 2013 14:35:18 -0700
changeset 129833 441c2a4b1ddebbf17c9d23d37bc3d6c2229a3532
parent 129832 8a8a161575760b23a81df70fa36afa6107a4ba0e
child 129834 f5adb2a4213572742ee737b50667acd8b87db333
push id27035
push userjwalden@mit.edu
push dateThu, 25 Apr 2013 05:35:14 +0000
treeherdermozilla-inbound@f5adb2a42135 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs865036
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 865036 - Implement mozilla::Is{S,Uns}igned. r=froydnj
mfbt/TypeTraits.h
--- a/mfbt/TypeTraits.h
+++ b/mfbt/TypeTraits.h
@@ -166,16 +166,48 @@ template<> struct IsPod<unsigned long>  
 template<> struct IsPod<long long>          : TrueType {};
 template<> struct IsPod<unsigned long long> : TrueType {};
 template<> struct IsPod<bool>               : TrueType {};
 template<> struct IsPod<float>              : TrueType {};
 template<> struct IsPod<double>             : TrueType {};
 template<> struct IsPod<wchar_t>            : TrueType {};
 template<typename T> struct IsPod<T*>       : TrueType {};
 
+/**
+ * IsSigned determines whether a type is a signed arithmetic type.
+ *
+ * Don't use this if the type might be user-defined!  You might or might not get
+ * a compile error, depending.
+ *
+ * mozilla::IsSigned<int>::value is true;
+ * mozilla::IsSigned<const unsigned int>::value is false;
+ * mozilla::IsSigned<unsigned char>::value is false;
+ * mozilla::IsSigned<float>::value is true.
+ */
+template<typename T>
+struct IsSigned
+  : IntegralConstant<bool, IsArithmetic<T>::value && T(-1) < T(0)>
+{};
+
+/**
+ * IsUnsigned determines whether a type is an unsigned arithmetic type.
+ *
+ * Don't use this if the type might be user-defined!  You might or might not get
+ * a compile error, depending.
+ *
+ * mozilla::IsUnsigned<int>::value is false;
+ * mozilla::IsUnsigned<const unsigned int>::value is true;
+ * mozilla::IsUnsigned<unsigned char>::value is true;
+ * mozilla::IsUnsigned<float>::value is false.
+ */
+template<typename T>
+struct IsUnsigned
+  : IntegralConstant<bool, IsArithmetic<T>::value && T(0) < T(-1)>
+{};
+
 /* 20.9.5 Type property queries [meta.unary.prop.query] */
 
 /* 20.9.6 Relationships between types [meta.rel] */
 
 /**
  * IsSame tests whether two types are the same type.
  *
  * mozilla::IsSame<int, int>::value is true;