[libcxx-commits] [libcxx] [libc++] Use __is_scoped_enum for the implementation of is_scoped_enum if it's available (PR #85580)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 18 00:47:52 PDT 2024
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/85580
>From ccb76b5ea16d0e624890def95d455f76f3fd203f Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sun, 17 Mar 2024 20:27:15 +0100
Subject: [PATCH] [libc++] Use __is_scoped_enum for the implementation of
is_scoped_enum if it's available
---
libcxx/include/__type_traits/is_scoped_enum.h | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__type_traits/is_scoped_enum.h b/libcxx/include/__type_traits/is_scoped_enum.h
index 43b3a6b66b1f5d..1db88e13356e83 100644
--- a/libcxx/include/__type_traits/is_scoped_enum.h
+++ b/libcxx/include/__type_traits/is_scoped_enum.h
@@ -22,6 +22,18 @@
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 23
+
+// TODO: GCC and Clang both have this builtin. Remove the false case once we've updated to GCC 14.
+# if __has_builtin(__is_scoped_enum)
+
+template <class _Tp>
+struct _LIBCPP_TEMPLATE_VIS is_scoped_enum : bool_constant<__is_scoped_enum(_Tp)> {};
+
+template <class _Tp>
+inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
+
+# else
+
template <class _Tp, bool = is_enum_v<_Tp> >
struct __is_scoped_enum_helper : false_type {};
@@ -33,7 +45,10 @@ struct _LIBCPP_TEMPLATE_VIS is_scoped_enum : public __is_scoped_enum_helper<_Tp>
template <class _Tp>
inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
-#endif
+
+# endif // __has_builtin(__is_scoped_enum)
+
+#endif // _LIBCPP_STD_VER >= 23
_LIBCPP_END_NAMESPACE_STD
More information about the libcxx-commits
mailing list