From: Jonathan Wakely Date: Thu, 12 Dec 2019 14:35:55 +0000 (+0000) Subject: libstdc++: Simplify std::common_comparison_category X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d1505d01462a5c99ecee7847d913836f898f8b65;p=gcc.git libstdc++: Simplify std::common_comparison_category * libsupc++/compare (common_comparison_category): Define without using concepts and optimise for compilation time. (__detail::__cmp_cat_ids): Remove. (__detail::__common_cmp_cat): Replace class template and specializations with constexpr function. From-SVN: r279307 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 54377d89dbb..91d60d0bff4 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2019-12-12 Jonathan Wakely + + * libsupc++/compare (common_comparison_category): Define without using + concepts and optimise for compilation time. + (__detail::__cmp_cat_ids): Remove. + (__detail::__common_cmp_cat): Replace class template and + specializations with constexpr function. + 2019-12-12 François Dumont * include/tr1/cctype: Add _GLIBCXX_BEGIN_VERSION_NAMESPACE and diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index 412ec6861d3..f77b7d71e04 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -385,53 +385,43 @@ namespace std is_gteq(partial_ordering __cmp) noexcept { return __cmp >= 0; } -#if __cpp_lib_concepts namespace __detail { template inline constexpr unsigned __cmp_cat_id = 1; template<> - inline constexpr unsigned __cmp_cat_id = 2; + inline constexpr unsigned __cmp_cat_id = 2; template<> inline constexpr unsigned __cmp_cat_id = 4; template<> - inline constexpr unsigned __cmp_cat_id = 8; + inline constexpr unsigned __cmp_cat_id = 8; template - constexpr unsigned __cmp_cat_ids() - { return (__cmp_cat_id<_Ts> | ...); } - - template - struct __common_cmp_cat; - - // If any Ti is not a comparison category type, U is void. - template - requires ((_Bits & 1) == 1) - struct __common_cmp_cat<_Bits> { using type = void; }; - - // Otherwise, if at least one Ti is std::partial_ordering, - // U is std::partial_ordering. - template - requires ((_Bits & 0b1001) == 0b1000) - struct __common_cmp_cat<_Bits> { using type = partial_ordering; }; - - // Otherwise, if at least one Ti is std::weak_ordering, - // U is std::weak_ordering. - template - requires ((_Bits & 0b1101) == 0b0100) - struct __common_cmp_cat<_Bits> { using type = weak_ordering; }; - - // Otherwise, U is std::strong_ordering. - template<> - struct __common_cmp_cat<0b0010> { using type = strong_ordering; }; + constexpr auto __common_cmp_cat() + { + constexpr unsigned __cats = (__cmp_cat_id<_Ts> | ...); + // If any Ti is not a comparison category type, U is void. + if constexpr (__cats & 1) + return; + // Otherwise, if at least one Ti is std::partial_ordering, + // U is std::partial_ordering. + else if constexpr (bool(__cats & __cmp_cat_id)) + return partial_ordering::equivalent; + // Otherwise, if at least one Ti is std::weak_ordering, + // U is std::weak_ordering. + else if constexpr (bool(__cats & __cmp_cat_id)) + return weak_ordering::equivalent; + // Otherwise, U is std::strong_ordering. + else + return strong_ordering::equivalent; + } } // namespace __detail // [cmp.common], common comparison category type template struct common_comparison_category { - using type - = __detail::__common_cmp_cat<__detail::__cmp_cat_ids<_Ts...>()>::type; + using type = decltype(__detail::__common_cmp_cat<_Ts...>()); }; // Partial specializations for one and zero argument cases. @@ -460,6 +450,7 @@ namespace std using common_comparison_category_t = typename common_comparison_category<_Ts...>::type; +#if __cpp_lib_concepts namespace __detail { template