https://gcc.gnu.org/g:178dc3367643bf8a0611c7e218240d807a8d82df

commit r16-2273-g178dc3367643bf8a0611c7e218240d807a8d82df
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Mon Jul 14 11:13:54 2025 +0100

    libstdc++: Constrain std::swap using concepts in C++20
    
    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.

Diff:
---
 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)

Reply via email to