Given that __underlying_type is now available in clang, implement

std::underlying_type.

llvm-svn: 135410
This commit is contained in:
Alexis Hunt 2011-07-18 18:37:21 +00:00
parent a27d8b183a
commit 397d787642
4 changed files with 40 additions and 2 deletions

View File

@ -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__)

View File

@ -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

View File

@ -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)
}

View File

@ -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>