From 391d5d2e30aee5c2c6cce96399758e8ade836536 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 10 Sep 2019 08:35:36 +0100 Subject: [PATCH] Optimise std::remove_cv and use more helper aliases Define partial specializations for std::remove_cv so that std::remove_const and std::remove_volatile don't need to be instantiated. * include/std/type_traits (__remove_cv_t): New alias template. (is_void, is_integral, is_floating_point, is_pointer) (is_member_object_pointer, is_member_function_pointer, is_null_pointer) (is_member_point), __is_signed_integer, __is_unsigned_integer) (__make_unsigned_selector, __make_signed_selector, remove_pointer) (__decay_selector): Use __remove_cv_t. (remove_cv): Add partial specializations for cv-qualified types. (__decay_t): New alias template. (__decay_and_strip, __common_type_impl, __result_of_impl): Use __decay_t. (__enable_if_t): Move earlier in the file. (_Require): Use __enable_if_t. (swap(T&, T&)): Use _Require. (swap(T(&)[N])): Use __enable_if_t. From-SVN: r275562 --- libstdc++-v3/ChangeLog | 17 ++++++ libstdc++-v3/include/std/type_traits | 86 ++++++++++++++++------------ 2 files changed, 65 insertions(+), 38 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7f3793409e2..6be181413ff 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2019-09-10 Jonathan Wakely + + * include/std/type_traits (__remove_cv_t): New alias template. + (is_void, is_integral, is_floating_point, is_pointer) + (is_member_object_pointer, is_member_function_pointer, is_null_pointer) + (is_member_point), __is_signed_integer, __is_unsigned_integer) + (__make_unsigned_selector, __make_signed_selector, remove_pointer) + (__decay_selector): Use __remove_cv_t. + (remove_cv): Add partial specializations for cv-qualified types. + (__decay_t): New alias template. + (__decay_and_strip, __common_type_impl, __result_of_impl): Use + __decay_t. + (__enable_if_t): Move earlier in the file. + (_Require): Use __enable_if_t. + (swap(T&, T&)): Use _Require. + (swap(T(&)[N])): Use __enable_if_t. + 2019-09-09 Edward Smith-Rowland <3dw4rd@verizon.net> Implement C++20 p1424 - 'constexpr' feature macro concerns, diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 443208813b1..d2f53591e5a 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -226,6 +226,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct remove_cv; + // __remove_cv_t (std::remove_cv_t for C++11). + template + using __remove_cv_t = typename remove_cv<_Tp>::type; + template struct is_const; @@ -242,7 +246,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_void template struct is_void - : public __is_void_helper::type>::type + : public __is_void_helper<__remove_cv_t<_Tp>>::type { }; template @@ -359,7 +363,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_integral template struct is_integral - : public __is_integral_helper::type>::type + : public __is_integral_helper<__remove_cv_t<_Tp>>::type { }; template @@ -387,7 +391,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_floating_point template struct is_floating_point - : public __is_floating_point_helper::type>::type + : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type { }; /// is_array @@ -414,7 +418,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_pointer template struct is_pointer - : public __is_pointer_helper::type>::type + : public __is_pointer_helper<__remove_cv_t<_Tp>>::type { }; /// is_lvalue_reference @@ -446,8 +450,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_member_object_pointer template struct is_member_object_pointer - : public __is_member_object_pointer_helper< - typename remove_cv<_Tp>::type>::type + : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; template @@ -461,8 +464,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_member_function_pointer template struct is_member_function_pointer - : public __is_member_function_pointer_helper< - typename remove_cv<_Tp>::type>::type + : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type { }; /// is_enum @@ -509,7 +511,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_null_pointer (LWG 2247). template struct is_null_pointer - : public __is_null_pointer_helper::type>::type + : public __is_null_pointer_helper<__remove_cv_t<_Tp>>::type { }; /// __is_nullptr_t (deprecated extension). @@ -573,7 +575,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_member_pointer template struct is_member_pointer - : public __is_member_pointer_helper::type>::type + : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type { }; template @@ -584,7 +586,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Check if a type is one of the signed integer types. template - using __is_signed_integer = __is_one_of::type, + using __is_signed_integer = __is_one_of<__remove_cv_t<_Tp>, signed char, signed short, signed int, signed long, signed long long #if defined(__GLIBCXX_TYPE_INT_N_0) @@ -603,7 +605,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Check if a type is one of the unsigned integer types. template - using __is_unsigned_integer = __is_one_of::type, + using __is_unsigned_integer = __is_one_of<__remove_cv_t<_Tp>, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long #if defined(__GLIBCXX_TYPE_INT_N_0) @@ -1507,10 +1509,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// remove_cv template struct remove_cv - { - typedef typename - remove_const::type>::type type; - }; + { using type = _Tp; }; + + template + struct remove_cv + { using type = _Tp; }; + + template + struct remove_cv + { using type = _Tp; }; + + template + struct remove_cv + { using type = _Tp; }; /// add_const template @@ -1709,7 +1720,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class __make_unsigned_selector<_Tp, true, false> { using __unsigned_type - = typename __make_unsigned::type>::__type; + = typename __make_unsigned<__remove_cv_t<_Tp>>::__type; public: using __type @@ -1863,7 +1874,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class __make_signed_selector<_Tp, true, false> { using __signed_type - = typename __make_signed::type>::__type; + = typename __make_signed<__remove_cv_t<_Tp>>::__type; public: using __type @@ -1989,7 +2000,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// remove_pointer template struct remove_pointer - : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type> + : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>> { }; /// add_pointer @@ -2105,7 +2116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // NB: DR 705. template struct __decay_selector<_Up, false, false> - { typedef typename remove_cv<_Up>::type __type; }; + { typedef __remove_cv_t<_Up> __type; }; template struct __decay_selector<_Up, true, false> @@ -2125,6 +2136,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename __decay_selector<__remove_type>::__type type; }; + // __decay_t (std::decay_t for C++11). + template + using __decay_t = typename decay<_Tp>::type; + template class reference_wrapper; @@ -2142,11 +2157,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; template - struct __decay_and_strip - { - typedef typename __strip_reference_wrapper< - typename decay<_Tp>::type>::__type __type; - }; + using __decay_and_strip = __strip_reference_wrapper<__decay_t<_Tp>>; // Primary template. @@ -2160,8 +2171,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct enable_if { typedef _Tp type; }; + // __enable_if_t (std::enable_if_t for C++11) + template + using __enable_if_t = typename enable_if<_Cond, _Tp>::type; + template - using _Require = typename enable_if<__and_<_Cond...>::value>::type; + using _Require = __enable_if_t<__and_<_Cond...>::value>; // Primary template. /// Define a member typedef @c type to one of two argument types. @@ -2208,8 +2223,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // If sizeof...(T) is two, ... template::type, - typename _Dp2 = typename decay<_Tp2>::type> + typename _Dp1 = __decay_t<_Tp1>, typename _Dp2 = __decay_t<_Tp2>> struct __common_type_impl { // If is_same_v is false or is_same_v is false, @@ -2444,13 +2458,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __result_of_impl - : public __result_of_memobj::type, + : public __result_of_memobj<__decay_t<_MemPtr>, typename __inv_unwrap<_Arg>::type> { }; template struct __result_of_impl - : public __result_of_memfun::type, + : public __result_of_memfun<__decay_t<_MemPtr>, typename __inv_unwrap<_Arg>::type, _Args...> { }; @@ -2526,10 +2540,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using result_of_t = typename result_of<_Tp>::type; #endif // C++14 - // __enable_if_t (std::enable_if_t for C++11) - template - using __enable_if_t = typename enable_if<_Cond, _Tp>::type; - #if __cplusplus >= 201703L || !defined(__STRICT_ANSI__) // c++17 or gnu++11 #define __cpp_lib_void_t 201411 /// A metafunction that always yields void, used for detecting valid types. @@ -2607,9 +2617,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _GLIBCXX20_CONSTEXPR inline - typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>, - is_move_constructible<_Tp>, - is_move_assignable<_Tp>>::value>::type + _Require<__not_<__is_tuple_like<_Tp>>, + is_move_constructible<_Tp>, + is_move_assignable<_Tp>> swap(_Tp&, _Tp&) noexcept(__and_, is_nothrow_move_assignable<_Tp>>::value); @@ -2617,7 +2627,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _GLIBCXX20_CONSTEXPR inline - typename enable_if<__is_swappable<_Tp>::value>::type + __enable_if_t<__is_swappable<_Tp>::value> swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) noexcept(__is_nothrow_swappable<_Tp>::value); -- 2.30.2