This is a minor compile-time optimization for C++20.

libstdc++-v3/ChangeLog:

        * include/bits/move.h (swap): Replace enable_if with concepts
        when available, and with __enable_if_t alias otherwise.
---

Here's what I pushed.

Tested x86_64-linux.

 libstdc++-v3/include/bits/move.h | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h
index 085ca074fc88..061e6b4de3d8 100644
--- a/libstdc++-v3/include/bits/move.h
+++ b/libstdc++-v3/include/bits/move.h
@@ -215,14 +215,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  @return   Nothing.
   */
   template<typename _Tp>
-    _GLIBCXX20_CONSTEXPR
-    inline
-#if __cplusplus >= 201103L
-    typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>,
-                             is_move_constructible<_Tp>,
-                             is_move_assignable<_Tp>>::value>::type
+#if __glibcxx_concepts // >= C++20
+    requires (! __is_tuple_like<_Tp>::value)
+      && is_move_constructible_v<_Tp>
+      && is_move_assignable_v<_Tp>
+    constexpr void
+#elif __cplusplus >= 201103L
+    _GLIBCXX20_CONSTEXPR inline
+    __enable_if_t<__and_<__not_<__is_tuple_like<_Tp>>,
+                        is_move_constructible<_Tp>,
+                        is_move_assignable<_Tp>>::value>
 #else
-    void
+    inline void
 #endif
     swap(_Tp& __a, _Tp& __b)
     _GLIBCXX_NOEXCEPT_IF(__and_<is_nothrow_move_constructible<_Tp>,
@@ -241,12 +245,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // DR 809. std::swap should be overloaded for array types.
   /// Swap the contents of two arrays.
   template<typename _Tp, size_t _Nm>
-    _GLIBCXX20_CONSTEXPR
-    inline
-#if __cplusplus >= 201103L
-    typename enable_if<__is_swappable<_Tp>::value>::type
+#if __glibcxx_concepts // >= C++20
+    requires is_swappable_v<_Tp>
+    constexpr void
+#elif __cplusplus >= 201103L
+    _GLIBCXX20_CONSTEXPR inline
+    __enable_if_t<__is_swappable<_Tp>::value>
 #else
-    void
+    inline void
 #endif
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
     _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Tp>::value)
-- 
2.50.1

Reply via email to