]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Simplify allocator propagation helpers using 'if constexpr'
authorJonathan Wakely <jwakely@redhat.com>
Mon, 25 Nov 2024 21:55:09 +0000 (21:55 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 3 Dec 2024 21:34:25 +0000 (21:34 +0000)
Use diagnostic pragmas to allow using `if constexpr` in C++11 mode, so
that we don't need to use tag dispatching.

These helpers could be removed entirely by just using `if constexpr`
directly in the container member functions, but that's a slightly larger
change that can happen later.

It also looks like we could remove the __alloc_on_copy(const Alloc&)
overload, which is unused.

libstdc++-v3/ChangeLog:

* include/bits/alloc_traits.h (__do_alloc_on_copy): Remove.
(__do_alloc_on_move __do_alloc_on_swap): Remove.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if
constexpr.

libstdc++-v3/include/bits/alloc_traits.h

index c64f4757d5daf4a6385ae37e050a3eb4b24d22b0..76d5646afe576c4da5280ee26cb2c6815947c4a7 100644 (file)
@@ -835,20 +835,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   /// @cond undocumented
-#if __cplusplus < 201703L
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void
-    __do_alloc_on_copy(_Alloc& __one, const _Alloc& __two, true_type)
-    { __one = __two; }
-
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void
-    __do_alloc_on_copy(_Alloc&, const _Alloc&, false_type)
-    { }
-#endif
-
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
   template<typename _Alloc>
     [[__gnu__::__always_inline__]]
     _GLIBCXX14_CONSTEXPR inline void
@@ -857,12 +845,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __traits = allocator_traits<_Alloc>;
       using __pocca =
        typename __traits::propagate_on_container_copy_assignment::type;
-#if __cplusplus >= 201703L
       if constexpr (__pocca::value)
        __one = __two;
-#else
-      __do_alloc_on_copy(__one, __two, __pocca());
-#endif
     }
 
   template<typename _Alloc>
@@ -874,18 +858,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return __traits::select_on_container_copy_construction(__a);
     }
 
-#if __cplusplus < 201703L
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two, true_type)
-    { __one = std::move(__two); }
-
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void __do_alloc_on_move(_Alloc&, _Alloc&, false_type)
-    { }
-#endif
-
   template<typename _Alloc>
     [[__gnu__::__always_inline__]]
     _GLIBCXX14_CONSTEXPR inline void
@@ -894,29 +866,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __traits = allocator_traits<_Alloc>;
       using __pocma
        = typename __traits::propagate_on_container_move_assignment::type;
-#if __cplusplus >= 201703L
       if constexpr (__pocma::value)
        __one = std::move(__two);
-#else
-      __do_alloc_on_move(__one, __two, __pocma());
-#endif
-    }
-
-#if __cplusplus < 201703L
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two, true_type)
-    {
-      using std::swap;
-      swap(__one, __two);
     }
 
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void __do_alloc_on_swap(_Alloc&, _Alloc&, false_type)
-    { }
-#endif
-
   template<typename _Alloc>
     [[__gnu__::__always_inline__]]
     _GLIBCXX14_CONSTEXPR inline void
@@ -924,16 +877,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       using __traits = allocator_traits<_Alloc>;
       using __pocs = typename __traits::propagate_on_container_swap::type;
-#if __cplusplus >= 201703L
       if constexpr (__pocs::value)
        {
          using std::swap;
          swap(__one, __two);
        }
-#else
-      __do_alloc_on_swap(__one, __two, __pocs());
-#endif
     }
+#pragma GCC diagnostic pop
 
   template<typename _Alloc, typename _Tp,
           typename _ValueT = __remove_cvref_t<typename _Alloc::value_type>,