From patchwork Fri Sep 2 16:01:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp799722wro; Fri, 2 Sep 2022 09:02:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR5bGySed9Tr5K7ma8YbHgge9g2wZIq1ckJmBRnrF23BiNGZ+0Y4TYtB54HnhcYq482hTFne X-Received: by 2002:a17:907:2d2b:b0:731:2179:5ba with SMTP id gs43-20020a1709072d2b00b00731217905bamr29378274ejc.207.1662134575873; Fri, 02 Sep 2022 09:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662134575; cv=none; d=google.com; s=arc-20160816; b=W43SiVy3TmAc3fX5fmKsGR2TRGI30NC43kslk5Dw6dTHx6EXn0CoMaxIVhzl0Zyh9q YAVnfKjgXBccyAoSdrMSjNeucd+nisPH41cDOR64m152GeLHT1g23QHBwELyAjxjD7yt CTkzInQoJE8dD56vH8Ova7JLMR7gHsBbyzw4uvPmG9MK/N1Es2SHge7xXSxB8ktJ4U0f M4uem6FGI75DQh31A/vijgcNIUza+j6c5OoOUKUMxpS51zqD/ESbMua02ARk5z/Hpw6h Jf1CPVbkSzMQArFoOgm1/WMuzU78Y/rV5Djjw5+Ci1Yh4fmQ+NGBdD5rZpF+d1JVRzRr 3iRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=KBPA87E8gxPVoEASG4VscUc1gr3y8oJ/hXVL+vJIEx4=; b=OgK0yMZK4iyslq34skTOFZXNcYdPdFG04AdpcC/xX5cTDH9T/6p8oM/4Bdynuo8rXa i2f9CIi/moPiRSohA6EBfA3BG4PexDFZB28nthNm8nzp7VLF+9ATZer7tnNLG1HPrkDV kZy7r5ghgL9wuAAdXSb6EsWEebmNdb2KUB+dOboTAf95ZQ9e88S5l8cSHhXxCQqlTvo/ 4wJhrIz/IJvWZsG5aBr82XLzaTgS4Y3itfD28++ZmD79HAA7g1LM5Baq25VJKXMzBXYy 5yk1mM2VegL67baNgfYiEWN8mvTCakA46yLsc9498f98xincBv9kQ8U8TFGDTcvpgejP y5Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mH5AaMyt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id he30-20020a1709073d9e00b0073d7c6acb76si2486572ejc.540.2022.09.02.09.02.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 09:02:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mH5AaMyt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6BA73858283 for ; Fri, 2 Sep 2022 16:02:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6BA73858283 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662134552; bh=KBPA87E8gxPVoEASG4VscUc1gr3y8oJ/hXVL+vJIEx4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mH5AaMytdfLusQAU1u21uTgYAapbsC0q3/7597xuiwIS8zreVwlgolTvLbZDjyu6n +75fYPr8Z59cjVqCuLe4FGzmE0zxM4lmiaRqaYE+sj8xsOBsglHwQqR+T7TWyYOcE+ 60VqAIKs+K56Jx1TDgBtutBjIZ7GIL8Q26NfaPbs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id ADCD03858C33 for ; Fri, 2 Sep 2022 16:01:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ADCD03858C33 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-290-uNaXEeWSPPmRwHx29qeGYg-1; Fri, 02 Sep 2022 12:01:45 -0400 X-MC-Unique: uNaXEeWSPPmRwHx29qeGYg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC218858F0C; Fri, 2 Sep 2022 16:01:41 +0000 (UTC) Received: from localhost (unknown [10.33.36.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80A4140B40C7; Fri, 2 Sep 2022 16:01:41 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Optimize constructible/assignable variable templates Date: Fri, 2 Sep 2022 17:01:40 +0100 Message-Id: <20220902160140.414197-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742874424786668758?= X-GMAIL-MSGID: =?utf-8?q?1742874424786668758?= Tested powerpc64le-linux, pushed to trunk. -- >8 -- This defines the is_xxx_constructible_v and is_xxx_assignable_v variable templates by using the built-ins directly. The actual logic for each one is the same as the corresponding class template, but way using the variable template doesn't need to instantiate the class template. This means that the variable templates won't use the static assertions checking for complete types, cv void or unbounded arrays, but that's OK because the built-ins check those anyway. We could probably remove the static assertions from the class templates, and maybe from all type traits that use a built-in. libstdc++-v3/ChangeLog: * include/std/type_traits (is_constructible_v) (is_default_constructible_v, is_copy_constructible_v) (is_move_constructible_v): Define using __is_constructible. (is_assignable_v, is_copy_assignable_v, is_move_assignable_v): Define using __is_assignable. (is_trivially_constructible_v) (is_trivially_default_constructible_v) (is_trivially_copy_constructible_v) (is_trivially_move_constructible_v): Define using __is_trivially_constructible. (is_trivially_assignable_v, is_trivially_copy_assignable_v) (is_trivially_move_assignable_v): Define using __is_trivially_assignable. (is_nothrow_constructible_v) (is_nothrow_default_constructible_v) (is_nothrow_copy_constructible_v) (is_nothrow_move_constructible_v): Define using __is_nothrow_constructible. (is_nothrow_assignable_v, is_nothrow_copy_assignable_v) (is_nothrow_move_assignable_v): Define using __is_nothrow_assignable. --- libstdc++-v3/include/std/type_traits | 88 ++++++++++++++++------------ 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index be9f2955539..2f5fe80b98a 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3105,71 +3105,81 @@ template inline constexpr bool is_signed_v = is_signed<_Tp>::value; template inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value; + template - inline constexpr bool is_constructible_v = - is_constructible<_Tp, _Args...>::value; + inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...); template - inline constexpr bool is_default_constructible_v = - is_default_constructible<_Tp>::value; + inline constexpr bool is_default_constructible_v = __is_constructible(_Tp); template - inline constexpr bool is_copy_constructible_v = - is_copy_constructible<_Tp>::value; + inline constexpr bool is_copy_constructible_v + = __is_constructible(_Tp, __add_lval_ref_t); template - inline constexpr bool is_move_constructible_v = - is_move_constructible<_Tp>::value; + inline constexpr bool is_move_constructible_v + = __is_constructible(_Tp, __add_rval_ref_t<_Tp>); + template - inline constexpr bool is_assignable_v = is_assignable<_Tp, _Up>::value; + inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Up); template - inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value; + inline constexpr bool is_copy_assignable_v + = __is_assignable(__add_lval_ref_t<_Tp>, __add_lval_ref_t); template - inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value; + inline constexpr bool is_move_assignable_v + = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>); + template inline constexpr bool is_destructible_v = is_destructible<_Tp>::value; + template - inline constexpr bool is_trivially_constructible_v = - is_trivially_constructible<_Tp, _Args...>::value; + inline constexpr bool is_trivially_constructible_v + = __is_trivially_constructible(_Tp, _Args...); template - inline constexpr bool is_trivially_default_constructible_v = - is_trivially_default_constructible<_Tp>::value; + inline constexpr bool is_trivially_default_constructible_v + = __is_trivially_constructible(_Tp); template - inline constexpr bool is_trivially_copy_constructible_v = - is_trivially_copy_constructible<_Tp>::value; + inline constexpr bool is_trivially_copy_constructible_v + = __is_trivially_constructible(_Tp, __add_lval_ref_t); template - inline constexpr bool is_trivially_move_constructible_v = - is_trivially_move_constructible<_Tp>::value; + inline constexpr bool is_trivially_move_constructible_v + = __is_trivially_constructible(_Tp, __add_rval_ref_t<_Tp>); + template - inline constexpr bool is_trivially_assignable_v = - is_trivially_assignable<_Tp, _Up>::value; + inline constexpr bool is_trivially_assignable_v + = __is_trivially_assignable(_Tp, _Up); template - inline constexpr bool is_trivially_copy_assignable_v = - is_trivially_copy_assignable<_Tp>::value; + inline constexpr bool is_trivially_copy_assignable_v + = __is_trivially_assignable(__add_lval_ref_t<_Tp>, + __add_lval_ref_t); template - inline constexpr bool is_trivially_move_assignable_v = - is_trivially_move_assignable<_Tp>::value; + inline constexpr bool is_trivially_move_assignable_v + = __is_trivially_assignable(__add_lval_ref_t<_Tp>, + __add_rval_ref_t<_Tp>); template inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value; template - inline constexpr bool is_nothrow_constructible_v = - is_nothrow_constructible<_Tp, _Args...>::value; + inline constexpr bool is_nothrow_constructible_v + = __is_nothrow_constructible(_Tp, _Args...); template - inline constexpr bool is_nothrow_default_constructible_v = - is_nothrow_default_constructible<_Tp>::value; + inline constexpr bool is_nothrow_default_constructible_v + = __is_nothrow_constructible(_Tp); template - inline constexpr bool is_nothrow_copy_constructible_v = - is_nothrow_copy_constructible<_Tp>::value; + inline constexpr bool is_nothrow_copy_constructible_v + = __is_nothrow_constructible(_Tp, __add_lval_ref_t); template - inline constexpr bool is_nothrow_move_constructible_v = - is_nothrow_move_constructible<_Tp>::value; + inline constexpr bool is_nothrow_move_constructible_v + = __is_nothrow_constructible(_Tp, __add_rval_ref_t<_Tp>); + template - inline constexpr bool is_nothrow_assignable_v = - is_nothrow_assignable<_Tp, _Up>::value; + inline constexpr bool is_nothrow_assignable_v + = __is_nothrow_assignable(_Tp, _Up); template - inline constexpr bool is_nothrow_copy_assignable_v = - is_nothrow_copy_assignable<_Tp>::value; + inline constexpr bool is_nothrow_copy_assignable_v + = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, + __add_lval_ref_t); template - inline constexpr bool is_nothrow_move_assignable_v = - is_nothrow_move_assignable<_Tp>::value; + inline constexpr bool is_nothrow_move_assignable_v + = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>); + template inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;