[libcxx-commits] [PATCH] D58987: Make underlying_type SFINAE-friendly

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 5 11:20:20 PST 2019


zoecarver created this revision.
zoecarver added reviewers: ldionne, mclow.lists.
Herald added a subscriber: libcxx-commits.

I couldn't view the the document (P0340R3) <https://wg21.link/P0340R3>. But I think this implementation should work.


Repository:
  rCXX libc++

https://reviews.llvm.org/D58987

Files:
  include/type_traits
  test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp


Index: test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
===================================================================
--- test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
+++ test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
@@ -27,6 +27,15 @@
 enum F { W = UINT_MAX };
 #endif // TEST_UNSIGNED_UNDERLYING_TYPE
 
+#if TEST_STD_VER > 17
+template<class T>
+std::enable_if_t<
+	std::is_same_v<std::underlying_type_t<T>, int>
+> test_sfinae(T t);
+
+void test_sfinae(int) { return; }
+#endif // TEST_STD_VER > 17
+
 int main(int, char**)
 {
     static_assert((std::is_same<std::underlying_type<E>::type, int>::value),
@@ -52,6 +61,10 @@
     static_assert((std::is_same<std::underlying_type_t<G>, char>::value), "");
 #endif // TEST_STD_VER > 11
 #endif // TEST_STD_VER >= 11
+	
+#if TEST_STD_VER > 17
+	test_sfinae(0);
+#endif // TEST_STD_VER > 17
 
   return 0;
 }
Index: include/type_traits
===================================================================
--- include/type_traits
+++ include/type_traits
@@ -4711,12 +4711,15 @@
 
 #ifdef _LIBCPP_UNDERLYING_TYPE
 
-template <class _Tp>
+template <class _Tp, bool = is_enum<_Tp>::value>
 struct underlying_type
 {
     typedef _LIBCPP_UNDERLYING_TYPE(_Tp) type;
 };
 
+template <class _Tp>
+struct underlying_type<_Tp, false> {};
+
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58987.189372.patch
Type: text/x-patch
Size: 1493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190305/b1fee7f8/attachment.bin>


More information about the libcxx-commits mailing list