From patchwork Wed Jan 10 21:40:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1885193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XZ/pTrat; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T9Lng177Kz1yPp for ; Thu, 11 Jan 2024 08:40:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1130A386F016 for ; Wed, 10 Jan 2024 21:40:37 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 8C0E938582B3 for ; Wed, 10 Jan 2024 21:40:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C0E938582B3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8C0E938582B3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704922815; cv=none; b=VHRDpkXoijFTPJaJcV3a7LDaej/TZun+TxZQx0zOvVXvj88yomQBkKrenMrvWzmrf7qTrrU3BJYBwwrtHxzIXgr73ZWPef8cEhpX4IgmRMesqRIIe6g5TR7M48iu+nGzJcC9uCN3tqPO28UGF2oQ5fbmPg/Tlcdz5Agmcw/raR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704922815; c=relaxed/simple; bh=kiG9d5vA9W4DN+TISVd2/7WtR9nxYDJnaI6nEpGVg2M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EONWr9ex3shjsUWNBT1acY6kOzGOqygtC+UjvyKo+Wv+/CqcIua8Q3fcAeUv5G3mBqUhBFtgctQZF1jX10c0ePjzdQA4t4Fys8pHUmB/xCCIGIoRoWku7y9w2LPV8gnrlt4mCVYSe2spY2a92Y2tuj1RfCpz2+c0Vy6cdb8q0BY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704922812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tG6EDIT4xK4WNuZ8RAWQqMHvBvcOuupkyaxp7i06b7g=; b=XZ/pTrat1jMo5u+FfeZmXhYWgoaplMfSI2aBh0TAv8PZXFHPdhKLoEIc2F5cacwMB7DyHt xAfLG3SPCT0hDTUt/Hs/mlcxEYbcTZufYjFMWJAxPu4XpivhE31NQbiSawjIvbAh9WkirL Y09b7T18rCGZcCuE0vwjjO0NlRZ3Lw8= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-D2DJOVSpNN6oAE4uD5_2cg-1; Wed, 10 Jan 2024 16:40:11 -0500 X-MC-Unique: D2DJOVSpNN6oAE4uD5_2cg-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-5f7942a16c3so62524997b3.3 for ; Wed, 10 Jan 2024 13:40:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704922809; x=1705527609; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tG6EDIT4xK4WNuZ8RAWQqMHvBvcOuupkyaxp7i06b7g=; b=lUM6i2lewkSL/w8r5hNdILQCTNi7s6RSYQMkXN4o3+QiZDuxH+6vxC2GLZLnvKAb5a A1sHkuKrKWQGtY6dq8EEHy7BrGqpCAHrPwB9km6FSZZoY8pgLwXme88NTvNpQp8WCabg LrprmnbljWshVKGMGCcEasX82JnoWzeUM9gxWTMvR6MTvUh1NC/ZBCfn+/txijtBNpKL VbbiXpR0VQnZRh/HMiikSMe2B8M9KLmdnMZrDfP3Nm1VtimJ0Y0BoRvpgyGVnMOjiNIa ciD5v88DBGQOtepEfwvYgQtX/7xv1MWNSq2nVnNfe9wxZIGnugdyu/WxwRL1yTin5RSh wDUA== X-Gm-Message-State: AOJu0YznV6rZN4plEB9kpre6UkV1pTR8c/pFMVWW5ZU0PLJYG5P5aSFN 8Ts8oLy0jVi/YAtBOnDfgTCgnrrZiovYn63elfDQ/qLkf4uSV7WksN/AOg3jJgWEmFFLfUFJoXp DY+qeNJPf+gWlkZXXAS71gd1Kr4d10OFaUEz+STCO9maMQ0hP/hqSZI7AuMeAOFZH25ob7Byco/ RYLBTKrbE= X-Received: by 2002:a81:ae0f:0:b0:5ee:26aa:3d4 with SMTP id m15-20020a81ae0f000000b005ee26aa03d4mr277420ywh.43.1704922809567; Wed, 10 Jan 2024 13:40:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1l93bod5lH0fYkLnFccUn57+bEP+acLLbJ3M4kGQegQ1Uas09+1BTmZCZ8a0ZGIXoU8mKOA== X-Received: by 2002:a81:ae0f:0:b0:5ee:26aa:3d4 with SMTP id m15-20020a81ae0f000000b005ee26aa03d4mr277411ywh.43.1704922809262; Wed, 10 Jan 2024 13:40:09 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id bn9-20020a05620a2ac900b007815844a295sm1880046qkb.116.2024.01.10.13.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 13:40:08 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++/ranges: Use perfect forwarding in _Pipe and _Partial ctors Date: Wed, 10 Jan 2024 16:40:07 -0500 Message-ID: <20240110214007.2478417-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.283.ga54a84b333 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.5 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- This avoids redundant moves when composing and partially applying range adaptor objects. Note that the new constraints on _Partial's constructor templates are needed so that it's not inadvertently chosen over the copy constructor when constructing a _Partial object from a non-const _Partial lvalue. libstdc++-v3/ChangeLog: * include/std/ranges (views::__adaptor::operator|): Perform perfect forwarding of arguments. (views::__adaptor::_Partial::_Partial): Likewise. (views::__adaptor::_Pipe::__Pipe): Likewise. --- libstdc++-v3/include/std/ranges | 65 ++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 81a857502e3..0734daa42bf 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -957,8 +957,11 @@ namespace views::__adaptor requires __is_range_adaptor_closure<_Lhs> && __is_range_adaptor_closure<_Rhs> constexpr auto - operator|(_Lhs __lhs, _Rhs __rhs) - { return _Pipe<_Lhs, _Rhs>{std::move(__lhs), std::move(__rhs)}; } + operator|(_Lhs&& __lhs, _Rhs&& __rhs) + { + return _Pipe, decay_t<_Rhs>>{std::forward<_Lhs>(__lhs), + std::forward<_Rhs>(__rhs)}; + } // The base class of every range adaptor non-closure. // @@ -1004,10 +1007,12 @@ namespace views::__adaptor { tuple<_Args...> _M_args; - constexpr - _Partial(_Args... __args) - : _M_args(std::move(__args)...) - { } + template + requires (sizeof...(_Ts) == sizeof...(_Args)) + constexpr + _Partial(_Ts&&... __args) + : _M_args(std::forward<_Ts>(__args)...) + { } // Invoke _Adaptor with arguments __r, _M_args... according to the // value category of this _Partial object. @@ -1046,10 +1051,12 @@ namespace views::__adaptor { _Arg _M_arg; - constexpr - _Partial(_Arg __arg) - : _M_arg(std::move(__arg)) - { } + template + requires (!same_as, _Partial>) + constexpr + _Partial(_Tp&& __arg) + : _M_arg(std::forward<_Tp>(__arg)) + { } template requires __adaptor_invocable<_Adaptor, _Range, const _Arg&> @@ -1079,10 +1086,12 @@ namespace views::__adaptor { tuple<_Args...> _M_args; - constexpr - _Partial(_Args... __args) - : _M_args(std::move(__args)...) - { } + template + requires (sizeof...(_Ts) == sizeof...(_Args)) + constexpr + _Partial(_Ts&&... __args) + : _M_args(std::forward<_Ts>(__args)...) + { } // Invoke _Adaptor with arguments __r, const _M_args&... regardless // of the value category of this _Partial object. @@ -1109,10 +1118,12 @@ namespace views::__adaptor { _Arg _M_arg; - constexpr - _Partial(_Arg __arg) - : _M_arg(std::move(__arg)) - { } + template + requires (!same_as, _Partial>) + constexpr + _Partial(_Tp&& __arg) + : _M_arg(std::forward<_Tp>(__arg)) + { } template requires __adaptor_invocable<_Adaptor, _Range, const _Arg&> @@ -1135,10 +1146,11 @@ namespace views::__adaptor [[no_unique_address]] _Lhs _M_lhs; [[no_unique_address]] _Rhs _M_rhs; - constexpr - _Pipe(_Lhs __lhs, _Rhs __rhs) - : _M_lhs(std::move(__lhs)), _M_rhs(std::move(__rhs)) - { } + template + constexpr + _Pipe(_Tp&& __lhs, _Up&& __rhs) + : _M_lhs(std::forward<_Tp>(__lhs)), _M_rhs(std::forward<_Up>(__rhs)) + { } // Invoke _M_rhs(_M_lhs(__r)) according to the value category of this // range adaptor closure object. @@ -1172,10 +1184,11 @@ namespace views::__adaptor [[no_unique_address]] _Lhs _M_lhs; [[no_unique_address]] _Rhs _M_rhs; - constexpr - _Pipe(_Lhs __lhs, _Rhs __rhs) - : _M_lhs(std::move(__lhs)), _M_rhs(std::move(__rhs)) - { } + template + constexpr + _Pipe(_Tp&& __lhs, _Up&& __rhs) + : _M_lhs(std::forward<_Tp>(__lhs)), _M_rhs(std::forward<_Up>(__rhs)) + { } template requires __pipe_invocable