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.
This commit is contained in:
Jonathan Wakely 2024-11-25 21:55:09 +00:00 committed by Jonathan Wakely
parent 84b40a1c1b
commit aa7acf6fc9
No known key found for this signature in database

View 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>,