From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 547A63858D28 for ; Thu, 11 Jan 2024 22:56:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 547A63858D28 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 547A63858D28 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=1705013799; cv=none; b=p9e0TBinv5/0aMUzqbPeA0iFeGgInLWusHTmm2KQ9xQ9jZntD29CwCZ+vSG/7vJBpi0XsRRJuntIs6TXQxFSxYlcddUxGJEN8ZNWHYM8KDtma3ls6YxsLg2eBLB7ufwZBYGZszDhauwJ2bB6/CX6ofP7pRzTqXN788DiSFr7BHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705013799; c=relaxed/simple; bh=dz/VvoRe7LaxVhXCTIuPAV5sEw0z1dotOGDiwwB3jng=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=ts4n07yoGIaavQATCGjX4Bu8HdthaVniEWRo09O/8LDrUBdPrdmOscO55dAoOWC+jafRdbljJ7yFj/Mazj/rBMdELTkhAvOV+ZpCWOMhVbDmJePM56WWHjvgTuMNuLpTEMRkzhhwH7pVHAln/M4SG5dmwQkObAqUh0aVZ9TJEv8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705013795; 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: in-reply-to:in-reply-to:references:references; bh=mIwpuW8yS/N+RG7WdywhC/mynNsTRkjnJrOtscanVtA=; b=SAsRRyjxPAuiQUoh9aBrYdeaVQJlrZf/0a+V4m+B0ioBEcu0mYkVj3NHApQS21vltrslJB LJaUVhAucAgBcV8p13LmwyMhAfNSTwizxIBM9Hn4xl35Ai/o6F3prpfTa0dQA/4BcKckcT tSXQLgF9kMmz+Cz5AxNvvw0pUEJ7j9Y= 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-381-0TxWFBVoNSuh175UAGpbJg-1; Thu, 11 Jan 2024 17:56:34 -0500 X-MC-Unique: 0TxWFBVoNSuh175UAGpbJg-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-5e8d2c6903dso109992267b3.0 for ; Thu, 11 Jan 2024 14:56:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705013794; x=1705618594; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mIwpuW8yS/N+RG7WdywhC/mynNsTRkjnJrOtscanVtA=; b=jqxebRh3zNZ75b8EZpG0dF5wZoW0h8I/wPUhzi3rzMYFpumpzmAfy9xhZiJO5JYLrc JzwvLANWeXwgHqjkUpmD0Od9IvW9am34jZmmkdTpVN8VkgpytGMIPq2HSZPdsGHvVnoM KWKJM5XRiwZnKvV1bxHQsly6ltxm2r2y4ndHHKnubtWDbqveM2L4jU9E3RZAe8VUeGCP SsX4P1Jq1j2DSJGilm1EfkM6VdtkWIUUE7YnAgTpP+TpU7WLsg2cKXyQ//9Q0fg+gdnT CX0nBV9ZEkdNdOO7KpDQeoa9FQMdx1fk0bE0cYrFKuzWB3V0sm6deu44R8e+Nawzkuqa 3HdQ== X-Gm-Message-State: AOJu0Ywuitx+/s0YzVBmwGEQxCQyKbGb0SzEOMqgKugWvGqRCdvGaSfK Lbb1ns0nWtnjptMFq81UdAivrIqc6nc8iFXGCi9pdo5a/YcTujcRniuK2gmSkWSENRTi2lRT1PK SB/p3kbIPvBAOCgPZTgF2GDfursUHoB9tuusgEOkOnQ== X-Received: by 2002:a81:6dca:0:b0:5fb:9321:9ff5 with SMTP id i193-20020a816dca000000b005fb93219ff5mr467226ywc.61.1705013794213; Thu, 11 Jan 2024 14:56:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXanXCQpbKOvMros+PKjAK7ydkh9ukttu6pAzU5TnYac+nzFBejl7HVyvdORmwGzAYRzBQuGTMFr+XDvmYhLw= X-Received: by 2002:a81:6dca:0:b0:5fb:9321:9ff5 with SMTP id i193-20020a816dca000000b005fb93219ff5mr467218ywc.61.1705013793894; Thu, 11 Jan 2024 14:56:33 -0800 (PST) MIME-Version: 1.0 References: <20240110214007.2478417-1-ppalka@redhat.com> <286e5a28-cd2c-ea40-e4cc-0180798f18b0@idea> In-Reply-To: <286e5a28-cd2c-ea40-e4cc-0180798f18b0@idea> From: Jonathan Wakely Date: Thu, 11 Jan 2024 22:56:17 +0000 Message-ID: Subject: Re: [PATCH] libstdc++/ranges: Use perfect forwarding in _Pipe and _Partial ctors To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.7 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 List-Id: On Thu, 11 Jan 2024 at 16:12, Patrick Palka wrote: > > On Thu, 11 Jan 2024, Jonathan Wakely wrote: > > > On Wed, 10 Jan 2024 at 21:40, Patrick Palka wrote: > > > > > > 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)) > > > > Do we also need a !same_as constraint here? If sizeof...(_Args) == 1 > > then this could be chosen instead of a constructor, no? > > For the == 1 case we would have used a different partial specialization > of _Partial (one that doesn't use heavyweight std::tuple). So checking > sizeof...(_Ts) == sizof...(_Args) instead is sufficient and simpler. Aha thanks, I did wonder if that was the case but failed to see the other partial specialization. Looks fine for trunk then. > Checking sizeof...(_Args) > 1 would be sufficient as well. > > > > > Or is > > > + 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 > > > -- > > > 2.43.0.283.ga54a84b333 > > > > > > > >