aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-11-25 21:55:09 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-12-03 21:34:25 +0000
commitaa7acf6fc9251cc9bdb9a406dc58439eb54e1217 (patch)
tree33ad9d5de33224d8c0a00cdf7ccbb8d962cf468f
parent84b40a1c1b2c9e3feb546838fa988d653eed0755 (diff)
downloadgcc-aa7acf6fc9251cc9bdb9a406dc58439eb54e1217.zip
gcc-aa7acf6fc9251cc9bdb9a406dc58439eb54e1217.tar.gz
gcc-aa7acf6fc9251cc9bdb9a406dc58439eb54e1217.tar.bz2
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.
-rw-r--r--libstdc++-v3/include/bits/alloc_traits.h56
1 files changed, 3 insertions, 53 deletions
diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h
index c64f475..76d5646 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<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,46 +866,24 @@ _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
__alloc_on_swap(_Alloc& __one, _Alloc& __two)
{
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>,