On Mon, Jul 14, 2025 at 10:38 PM Jonathan Wakely <jwak...@redhat.com> wrote:
> This is a minor compile-time optimization for C++20. > Please mention that you also replaced _GLIBCXX20_CONSTEXPR, with constexpr under __glibcxx_concepts (that is >= c++ 20). Otherwise LGTM. > > libstdc++-v3/ChangeLog: > > * include/bits/move.h (swap): Replace enable_if with concepts > when available, and with __enable_if_t alias otherwise. > --- > > Tested powerpc64le-linux. > > 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..9c70263b526f 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> > + // swap is constexpr when __cpp_lib_constexpr_algorithms >= 201806L > + constexpr void > +#elif __cplusplus >= 201103L > + 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> > + // swap is constexpr when __cpp_lib_constexpr_algorithms >= 201806L > + constexpr void > +#elif __cplusplus >= 201103L > + 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) > -- > 2.50.1 > >