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.133.124]) by sourceware.org (Postfix) with ESMTPS id 3BE113835784 for ; Mon, 14 Nov 2022 15:12:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3BE113835784 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668438765; 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=wyn0va6jUvs7Dv9eQ5w8GBDHxVbgHm/qKe2moCLrlSY=; b=TBu6kSUjYeGyeBS1s1guoJEMPTaxwvGhZncd39rKezGp9mTTu+vLTIcMxqL8yxAMQlCXrn wQLv2QYAFSUmpYo+vKm023rezKscS6M5F5GLufYzgQ6I48P8GKZdgxStYKMB//OMrkefs/ CN3FqP3tmtSQzKOU+1+9Je8uK4E+kew= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-256-Iic-PQl_OwW3JKY9h18SSg-1; Mon, 14 Nov 2022 10:12:44 -0500 X-MC-Unique: Iic-PQl_OwW3JKY9h18SSg-1 Received: by mail-ed1-f70.google.com with SMTP id r12-20020a05640251cc00b00463699c95aeso8417832edd.18 for ; Mon, 14 Nov 2022 07:12:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=wyn0va6jUvs7Dv9eQ5w8GBDHxVbgHm/qKe2moCLrlSY=; b=SE7EFTKReL8xdqCaKzv+rOOF6k0qmRVdEschDCgYtozLPLgPzvFflQ/RUssBwTVGG9 F1Xo5tL/JBXf/uJJG3W0clJG7Tnbp6AhK+ncVZ+McOt12d+/XdSS8u596ll1wsGG4CSt IaCe//vqRu/LubkWYjIbcZZQ3v2eH5oADRdd3/RmegjxHFW/VXdC4zLAjzEvYBJFlj1Q PB1zsnyGqPuwfPKVgRiXzq+YX9fu/QXX4DAEcU2vMfha6wsXv2qsbo8ZxILsAjxjDLCa UPnvmDkTnD2FXwsFoNAqlt0QbG6H/OMiifTQK8yyENvmPI5+QLMDRchMhwFU3bgTdzyg s/IA== X-Gm-Message-State: ANoB5pn/scZQ6ZG2g6eRlFuAOpAylzsn8MkGUq9rTy7JXECTZdtCJFqQ jDnF6AsDhKjZzldMlZBoU5HrxKw2TnjsL6UqngMArX6jgQR12WMRFz+ovlIxcH4G6s/kPY5OP5I zNgBF8EhsL0lLFGHMcbrXf4sQjjs24IhStg== X-Received: by 2002:a17:906:1ed0:b0:78d:9e77:1f8c with SMTP id m16-20020a1709061ed000b0078d9e771f8cmr10490570ejj.236.1668438763563; Mon, 14 Nov 2022 07:12:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf7v2pkl3coFwuXkvhUmqAzgguhvBrgkrRHdPEVbw+U16IJvhOq3sDAich5DFpGh4mNpDEbkLs0DOYBBdH+QlLE= X-Received: by 2002:a17:906:1ed0:b0:78d:9e77:1f8c with SMTP id m16-20020a1709061ed000b0078d9e771f8cmr10490560ejj.236.1668438763376; Mon, 14 Nov 2022 07:12:43 -0800 (PST) MIME-Version: 1.0 References: <20221114045047.362745-1-ppalka@redhat.com> <20221114045047.362745-3-ppalka@redhat.com> In-Reply-To: <20221114045047.362745-3-ppalka@redhat.com> From: Jonathan Wakely Date: Mon, 14 Nov 2022 15:12:32 +0000 Message-ID: Subject: Re: [PATCH 3/3] libstdc++: Implement ranges::find_last{, _if, _if_not} from P1223R5 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=-12.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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 Mon, 14 Nov 2022 at 04:51, Patrick Palka via Libstdc++ wrote: > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > libstdc++-v3/ChangeLog: > > * include/bits/ranges_algo.h (__find_last_fn, find_last): > Define. > (__find_last_if_fn, find_last_if): Define. > (__find_last_if_not_fn, find_last_if_not): Define. > * testsuite/25_algorithms/find_last/1.cc: New test. > * testsuite/25_algorithms/find_last_if/1.cc: New test. > * testsuite/25_algorithms/find_last_if_not/1.cc: New test. > --- > libstdc++-v3/include/bits/ranges_algo.h | 123 ++++++++++++++++++ > .../testsuite/25_algorithms/find_last/1.cc | 90 +++++++++++++ > .../testsuite/25_algorithms/find_last_if/1.cc | 92 +++++++++++++ > .../25_algorithms/find_last_if_not/1.cc | 92 +++++++++++++ > 4 files changed, 397 insertions(+) > create mode 100644 libstdc++-v3/testsuite/25_algorithms/find_last/1.cc > create mode 100644 libstdc++-v3/testsuite/25_algorithms/find_last_if/1.cc > create mode 100644 libstdc++-v3/testsuite/25_algorithms/find_last_if_not/1.cc > > diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h > index f003117c569..0e4329382eb 100644 > --- a/libstdc++-v3/include/bits/ranges_algo.h > +++ b/libstdc++-v3/include/bits/ranges_algo.h > @@ -3565,6 +3565,129 @@ namespace ranges > }; > > inline constexpr __iota_fn iota{}; > + > + struct __find_last_fn > + { > + template _Sent, typename T, typename _Proj = identity> > + requires indirect_binary_predicate, const T*> > + constexpr subrange<_Iter> > + operator()(_Iter __first, _Sent __last, const T& __value, _Proj __proj = {}) const > + { > + if constexpr (same_as<_Iter, _Sent> && bidirectional_iterator<_Iter>) > + { > + _Iter __found = ranges::find(reverse_iterator<_Iter>{__last}, > + reverse_iterator<_Iter>{__first}, > + __value, __proj).base(); > + if (__found == __first) > + return {__last, __last}; > + else > + return {ranges::prev(__found), __last}; > + } > + else > + { > + _Iter __found = ranges::find(__first, __last, __value, __proj); std::move(__proj) here too, for consistency. > + if (__found == __last) > + return {__found, __found}; > + for (;;) > + { > + __first = ranges::find(ranges::next(__first), __last, __value, __proj); And here. > + if (__first == __last) > + return {__found, __first}; > + __found = __first; > + } > + } > + } > + > + template > + requires indirect_binary_predicate, _Proj>, const T*> > + constexpr borrowed_subrange_t<_Range> > + operator()(_Range&& __r, const T& __value, _Proj __proj = {}) const > + { return (*this)(ranges::begin(__r), ranges::end(__r), __value, std::move(__proj)); } > + }; > + > + inline constexpr __find_last_fn find_last{}; > + > + struct __find_last_if_fn > + { > + template _Sent, typename _Proj = identity, > + indirect_unary_predicate> _Pred> > + constexpr subrange<_Iter> > + operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const > + { > + if constexpr (same_as<_Iter, _Sent> && bidirectional_iterator<_Iter>) > + { > + _Iter __found = ranges::find_if(reverse_iterator<_Iter>{__last}, > + reverse_iterator<_Iter>{__first}, > + __pred, __proj).base(); And here, and std::move(__pred) too, I think. OK for trunk with those changes here (and the later cases).