[v14,13/40] libstdc++: Optimize is_scoped_enum trait performance

Message ID 20230915235353.19378-14-kmatsui@gcc.gnu.org
State New
Headers
Series Optimize type traits performance |

Commit Message

Ken Matsui Sept. 15, 2023, 11:50 p.m. UTC
  This patch optimizes the performance of the is_scoped_enum trait
by dispatching to the new __is_scoped_enum built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_scoped_enum): Use
	__is_scoped_enum built-in trait.
	(is_scoped_enum_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
 libstdc++-v3/include/std/type_traits | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index d306073a797..7fd29d8d9f2 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3633,6 +3633,12 @@  template<typename _Ret, typename _Fn, typename... _Args>
   /// True if the type is a scoped enumeration type.
   /// @since C++23
 
+# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
+  template<typename _Tp>
+    struct is_scoped_enum
+    : bool_constant<__is_scoped_enum(_Tp)>
+    { };
+# else
   template<typename _Tp>
     struct is_scoped_enum
     : false_type
@@ -3644,11 +3650,17 @@  template<typename _Ret, typename _Fn, typename... _Args>
     struct is_scoped_enum<_Tp>
     : bool_constant<!requires(_Tp __t, void(*__f)(int)) { __f(__t); }>
     { };
+# endif
 
   /// @ingroup variable_templates
   /// @since C++23
+# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum)
+  template<typename _Tp>
+    inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
+# else
   template<typename _Tp>
     inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
+# endif
 #endif
 
 #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp