summaryrefslogtreecommitdiffstats
path: root/libcxx
diff options
context:
space:
mode:
authorAlexis Hunt <alercah@gmail.com>2011-07-18 18:37:21 +0000
committerAlexis Hunt <alercah@gmail.com>2011-07-18 18:37:21 +0000
commit397d787642024ab66a9e0c1ca5421b421fcdcdf1 (patch)
tree400ac32b44abf8b4f68e4ffe655bba8cf7529c7c /libcxx
parenta27d8b183a4927c0059b0fcc981a1dd851a5c65a (diff)
downloadbcm5719-llvm-397d787642024ab66a9e0c1ca5421b421fcdcdf1.tar.gz
bcm5719-llvm-397d787642024ab66a9e0c1ca5421b421fcdcdf1.zip
Given that __underlying_type is now available in clang, implement
std::underlying_type. llvm-svn: 135410
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/__config4
-rw-r--r--libcxx/include/type_traits20
-rw-r--r--libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp16
-rw-r--r--libcxx/www/type_traits_design.html2
4 files changed, 40 insertions, 2 deletions
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 2610d817a49..0c46f76188e 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -188,6 +188,10 @@ namespace std {
# define _NOEXCEPT_(x)
#endif
+#if __has_feature(underlying_type)
+# define _LIBCXX_UNDERLYING_TYPE(T) __underlying_type(T)
+#endif
+
// end defined(__clang__)
#elif defined(__GNUC__)
diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index 120c2701cf5..ec12b6b928c 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -3092,6 +3092,26 @@ struct __is_nothrow_swappable
#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
diff --git a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
index 126ab2ce705..a21120bdfde 100644
--- a/libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
+++ b/libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
@@ -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)
}
diff --git a/libcxx/www/type_traits_design.html b/libcxx/www/type_traits_design.html
index 7036a45ec53..451fdc4ace0 100644
--- a/libcxx/www/type_traits_design.html
+++ b/libcxx/www/type_traits_design.html
@@ -260,7 +260,7 @@ changed. Please see:
<tr>
<td><tt>underlying_type&lt;T&gt;</tt></td>
-<td bgcolor="#FF5965"><tt>__underlying_type(T)</tt></td>
+<td bgcolor="#80FF80"><tt>__underlying_type(T)</tt></td>
</tr>
<tr>
OpenPOWER on IntegriCloud