[cfe-commits] [libcxx] r135410 - in /libcxx/trunk: include/__config include/type_traits test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp www/type_traits_design.html

Sean Hunt scshunt at csclub.uwaterloo.ca
Mon Jul 18 11:37:21 PDT 2011


Author: coppro
Date: Mon Jul 18 13:37:21 2011
New Revision: 135410

URL: http://llvm.org/viewvc/llvm-project?rev=135410&view=rev
Log:
Given that __underlying_type is now available in clang, implement
std::underlying_type.

Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/type_traits
    libcxx/trunk/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
    libcxx/trunk/www/type_traits_design.html

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=135410&r1=135409&r2=135410&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Mon Jul 18 13:37:21 2011
@@ -188,6 +188,10 @@
 #  define _NOEXCEPT_(x)
 #endif
 
+#if __has_feature(underlying_type)
+#  define _LIBCXX_UNDERLYING_TYPE(T) __underlying_type(T)
+#endif
+
 // end defined(__clang__)
 
 #elif defined(__GNUC__)

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=135410&r1=135409&r2=135410&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Mon Jul 18 13:37:21 2011
@@ -3092,6 +3092,26 @@
 
 #endif  // __has_feature(cxx_noexcept)
 
+#ifdef _LIBCXX_UNDERLYING_TYPE
+
+template <class _Tp>
+struct underlying_type
+{
+    typedef _LIBCXX_UNDERLYING_TYPE(_Tp) type;
+};
+
+#else  // _LIBCXX_UNDERLYING_TYPE
+
+template <class _Tp, bool _Support = false>
+struct underlying_type
+{
+    static_assert(_Support, "The underyling_type trait requires compiler "
+                            "support. Either no such support exists or "
+                            "libc++ does not know how to use it.");
+};
+
+#endif // _LIBCXX_UNDERLYING_TYPE
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_TYPE_TRAITS

Modified: libcxx/trunk/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp?rev=135410&r1=135409&r2=135410&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp (original)
+++ libcxx/trunk/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp Mon Jul 18 13:37:21 2011
@@ -12,8 +12,22 @@
 // underlying_type
 
 #include <type_traits>
+#include <climits>
 
 int main()
 {
-#error underlying_type is not implemented
+    enum E { V = INT_MIN };
+    enum F { W = UINT_MAX };
+
+    static_assert((std::is_same<std::underlying_type<E>::type, int>::value),
+                  "E has the wrong underlying type");
+    static_assert((std::is_same<std::underlying_type<F>::type, unsigned>::value),
+                  "F has the wrong underlying type");
+
+#if __has_feature(cxx_strong_enums)
+    enum G : char { };
+
+    static_assert((std::is_same<std::underlying_type<G>::type, char>::value),
+                  "G has the wrong underlying type");
+#endif // __has_feature(cxx_strong_enums)
 }

Modified: libcxx/trunk/www/type_traits_design.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/type_traits_design.html?rev=135410&r1=135409&r2=135410&view=diff
==============================================================================
--- libcxx/trunk/www/type_traits_design.html (original)
+++ libcxx/trunk/www/type_traits_design.html Mon Jul 18 13:37:21 2011
@@ -260,7 +260,7 @@
 
 <tr>
 <td><tt>underlying_type<T></tt></td>
-<td bgcolor="#FF5965"><tt>__underlying_type(T)</tt></td>
+<td bgcolor="#80FF80"><tt>__underlying_type(T)</tt></td>
 </tr>
 
 <tr>





More information about the cfe-commits mailing list