Given that __underlying_type is now available in clang, implement
std::underlying_type. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@135410 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		@@ -188,6 +188,10 @@ namespace std {
 | 
				
			|||||||
#  define _NOEXCEPT_(x)
 | 
					#  define _NOEXCEPT_(x)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if __has_feature(underlying_type)
 | 
				
			||||||
 | 
					#  define _LIBCXX_UNDERLYING_TYPE(T) __underlying_type(T)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// end defined(__clang__)
 | 
					// end defined(__clang__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#elif defined(__GNUC__)
 | 
					#elif defined(__GNUC__)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3092,6 +3092,26 @@ struct __is_nothrow_swappable
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#endif  // __has_feature(cxx_noexcept)
 | 
					#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
 | 
					_LIBCPP_END_NAMESPACE_STD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif  // _LIBCPP_TYPE_TRAITS
 | 
					#endif  // _LIBCPP_TYPE_TRAITS
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,8 +12,22 @@
 | 
				
			|||||||
// underlying_type
 | 
					// underlying_type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <type_traits>
 | 
					#include <type_traits>
 | 
				
			||||||
 | 
					#include <climits>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main()
 | 
					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)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -260,7 +260,7 @@ changed.  Please see:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<tr>
 | 
					<tr>
 | 
				
			||||||
<td><tt>underlying_type<T></tt></td>
 | 
					<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>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<tr>
 | 
					<tr>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user