From aa7acf6fc9251cc9bdb9a406dc58439eb54e1217 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 25 Nov 2024 21:55:09 +0000 Subject: [PATCH] libstdc++: Simplify allocator propagation helpers using 'if constexpr' 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 | 56 ++---------------------- 1 file changed, 3 insertions(+), 53 deletions(-) diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index c64f4757d5d..76d5646afe5 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -835,20 +835,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// @cond undocumented -#if __cplusplus < 201703L - template - [[__gnu__::__always_inline__]] - inline void - __do_alloc_on_copy(_Alloc& __one, const _Alloc& __two, true_type) - { __one = __two; } - - template - [[__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 [[__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 @@ -874,18 +858,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __traits::select_on_container_copy_construction(__a); } -#if __cplusplus < 201703L - template - [[__gnu__::__always_inline__]] - inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two, true_type) - { __one = std::move(__two); } - - template - [[__gnu__::__always_inline__]] - inline void __do_alloc_on_move(_Alloc&, _Alloc&, false_type) - { } -#endif - template [[__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 - [[__gnu__::__always_inline__]] - inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two, true_type) - { - using std::swap; - swap(__one, __two); - } - - template - [[__gnu__::__always_inline__]] - inline void __do_alloc_on_swap(_Alloc&, _Alloc&, false_type) - { } -#endif - template [[__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,