Commit d1505d01 by Jonathan Wakely Committed by Jonathan Wakely

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
parent 2fb1d6d6
2019-12-12 Jonathan Wakely <jwakely@redhat.com>
* 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 <fdumont@gcc.gnu.org> 2019-12-12 François Dumont <fdumont@gcc.gnu.org>
* include/tr1/cctype: Add _GLIBCXX_BEGIN_VERSION_NAMESPACE and * include/tr1/cctype: Add _GLIBCXX_BEGIN_VERSION_NAMESPACE and
......
...@@ -385,53 +385,43 @@ namespace std ...@@ -385,53 +385,43 @@ namespace std
is_gteq(partial_ordering __cmp) noexcept is_gteq(partial_ordering __cmp) noexcept
{ return __cmp >= 0; } { return __cmp >= 0; }
#if __cpp_lib_concepts
namespace __detail namespace __detail
{ {
template<typename _Tp> template<typename _Tp>
inline constexpr unsigned __cmp_cat_id = 1; inline constexpr unsigned __cmp_cat_id = 1;
template<> template<>
inline constexpr unsigned __cmp_cat_id<strong_ordering> = 2; inline constexpr unsigned __cmp_cat_id<partial_ordering> = 2;
template<> template<>
inline constexpr unsigned __cmp_cat_id<weak_ordering> = 4; inline constexpr unsigned __cmp_cat_id<weak_ordering> = 4;
template<> template<>
inline constexpr unsigned __cmp_cat_id<partial_ordering> = 8; inline constexpr unsigned __cmp_cat_id<strong_ordering> = 8;
template<typename... _Ts> template<typename... _Ts>
constexpr unsigned __cmp_cat_ids() constexpr auto __common_cmp_cat()
{ return (__cmp_cat_id<_Ts> | ...); } {
constexpr unsigned __cats = (__cmp_cat_id<_Ts> | ...);
template<unsigned> // If any Ti is not a comparison category type, U is void.
struct __common_cmp_cat; if constexpr (__cats & 1)
return;
// If any Ti is not a comparison category type, U is void. // Otherwise, if at least one Ti is std::partial_ordering,
template<unsigned _Bits> // U is std::partial_ordering.
requires ((_Bits & 1) == 1) else if constexpr (bool(__cats & __cmp_cat_id<partial_ordering>))
struct __common_cmp_cat<_Bits> { using type = void; }; return partial_ordering::equivalent;
// Otherwise, if at least one Ti is std::weak_ordering,
// Otherwise, if at least one Ti is std::partial_ordering, // U is std::weak_ordering.
// U is std::partial_ordering. else if constexpr (bool(__cats & __cmp_cat_id<weak_ordering>))
template<unsigned _Bits> return weak_ordering::equivalent;
requires ((_Bits & 0b1001) == 0b1000) // Otherwise, U is std::strong_ordering.
struct __common_cmp_cat<_Bits> { using type = partial_ordering; }; else
return strong_ordering::equivalent;
// Otherwise, if at least one Ti is std::weak_ordering, }
// U is std::weak_ordering.
template<unsigned _Bits>
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; };
} // namespace __detail } // namespace __detail
// [cmp.common], common comparison category type // [cmp.common], common comparison category type
template<typename... _Ts> template<typename... _Ts>
struct common_comparison_category struct common_comparison_category
{ {
using type using type = decltype(__detail::__common_cmp_cat<_Ts...>());
= __detail::__common_cmp_cat<__detail::__cmp_cat_ids<_Ts...>()>::type;
}; };
// Partial specializations for one and zero argument cases. // Partial specializations for one and zero argument cases.
...@@ -460,6 +450,7 @@ namespace std ...@@ -460,6 +450,7 @@ namespace std
using common_comparison_category_t using common_comparison_category_t
= typename common_comparison_category<_Ts...>::type; = typename common_comparison_category<_Ts...>::type;
#if __cpp_lib_concepts
namespace __detail namespace __detail
{ {
template<typename _Tp, typename _Cat> template<typename _Tp, typename _Cat>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment