From patchwork Thu Dec 12 14:35:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1208548 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515800-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ulYahviC"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="EM9iZ+U6"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47YbvY30L4z9sPh for ; Fri, 13 Dec 2019 01:36:09 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=R5IXGrAYQO0jfcoWzKy5Co2IfCuFLH3Ny3SjKY65m0Ut2OKTTjHoT Xeg3JB69keerelC4ympE0QDcEeEPP/0c1swMpizmk2D86Sz3ihLZiBi6AXSWREUZ W8KRtdJhOYxWcFAKkaDBUnJ46LHbC46MP9bW4JSTD7TgWVKK6VR+0I= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=IheoXINz+VPUoOAsbw9/S0mPVRQ=; b=ulYahviCREAIAXihwICR sOUBVjPwZTUV4w5twpAT9Bk5CGQKzSlYwqv9u28OH97dq6+TQNWbxiOJqV6YcdXm XkV3CA59Vac+cZUs/fp3lc+vTS2pPF55ININsnO28BYcg+AkanISH5O/1EeKlfun 28MYWRLjcJcXlPak09s0hKo= Received: (qmail 126104 invoked by alias); 12 Dec 2019 14:35:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 126008 invoked by uid 89); 12 Dec 2019 14:35:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=_Tp, _tp X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Dec 2019 14:35:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576161352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=fu0ymv9lPvISz/I0c+4pIAb6V/dh8ly8mT2kqlgbtt0=; b=EM9iZ+U6sXP9BJCHerbIcSnGeM7DFNBkF9Q3gnPJFdxE8sfTHglZ4pD0xNKaNIu31Cj+8q lM946cNILgL8eFgTBZsdOG8TtqkAuwJzP2uJ+hshYQalc0os97MFKRMQLNUbuWe1sjYole smWsAd99bcomz5pg4Ojezm/qrlXkFCw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-X5jPTeVDOZq9DNn6z-qjgQ-1; Thu, 12 Dec 2019 09:35:50 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22D9E100551B; Thu, 12 Dec 2019 14:35:49 +0000 (UTC) Received: from localhost (unknown [10.33.36.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0E7260BE1; Thu, 12 Dec 2019 14:35:48 +0000 (UTC) Date: Thu, 12 Dec 2019 14:35:47 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Simplify std::common_comparison_category Message-ID: <20191212143547.GA2571530@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Mimecast-Spam-Score: 0 Content-Disposition: inline * 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. Tested x86_64-linux, committed to trunk. commit 70a1dc5fb4465642c00306d003164bdd9a5b8e08 Author: Jonathan Wakely Date: Thu Dec 12 13:21:07 2019 +0000 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. 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