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 ESMTP id 123B23851C3E for ; Mon, 29 Mar 2021 18:54:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 123B23851C3E Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-TfM84SGDPSa_1My_5kFhxw-1; Mon, 29 Mar 2021 14:53:58 -0400 X-MC-Unique: TfM84SGDPSa_1My_5kFhxw-1 Received: by mail-qt1-f200.google.com with SMTP id w2so8190126qts.18 for ; Mon, 29 Mar 2021 11:53:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=secUZPt2T9fAOcJplDpWvjZ2fm4X18IGVPE/AqdMaQA=; b=GdG7ZtuKbFJtGVMLCpnqacNzcY6EqkFN9yDvqsw/zYFONwJGroACR/uZtsgnnQ7af9 xA65e0RXWzlfoTQoqQ3tdoGTT/d/+Qsz+DY9DDYmpuCgiD3nEtkVK9lMB/JHKcW7RL2b d6x3H5PCk8c0inkuIZnUimUIgtvTFKv7Ou2vN6lTs/fPk7aCPzE3tEjJcFLgiyPvi7pZ RhXqqPAcfTavI2exxssKtwiucppxzGX1gKKgUTF4L3ncY6KwCCGxLbuDSkst8iId0vMg oMTpIJ5Z0LL3pVpiQkoB4obyz/KamRCkcvgY7PLtMbQKVb7n9bS7ftiHBb6vkzmrVucJ Rzng== X-Gm-Message-State: AOAM531cKFK1IUpO5rW3gt/moBhtryTu2SoGzY471nRucXF9Qhwhr6CN SW4rQZmcfHrG6FJL6lde4hd8J8hDWF+AttBujIkg3QFfweSNTXMR9jkyCCGGGVnkCDsn4tKYkSs yHhjYJfUulhp7MrP0xA== X-Received: by 2002:a37:b807:: with SMTP id i7mr26301530qkf.126.1617044038039; Mon, 29 Mar 2021 11:53:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG2SMD830dd3YroLVSe2oSm1K0x6rMziC+JZme/w375t8a6IanQJCUEDVSpGi2eGssI47Q/w== X-Received: by 2002:a37:b807:: with SMTP id i7mr26301516qkf.126.1617044037797; Mon, 29 Mar 2021 11:53:57 -0700 (PDT) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id g17sm2523329qts.93.2021.03.29.11.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 11:53:57 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 29 Mar 2021 14:53:56 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH 2/3] libstdc++: Simplify copy-pasted algorithms in In-Reply-To: <20210329184915.3921422-2-ppalka@redhat.com> Message-ID: <7a81c633-511e-b6fd-a02a-6840eda18153@idea> References: <20210329184915.3921422-1-ppalka@redhat.com> <20210329184915.3921422-2-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-16.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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Mon, 29 Mar 2021 18:54:02 -0000 On Mon, 29 Mar 2021, Patrick Palka wrote: > The header currently copies some simple algorithms from > , which was originally done in order to avoid a > circular dependency with the header. This is no longer an issue since > the latter header now includes instead of all of > . > > This means we could now just include and remove the > copied algorithms, but that would double the size of . Whoops, more like increase the size of by ~10% (33k SLOC -> 37k). > And we > can't use the corresponding STL-style algorithms here because they > assume input iterators are copyable. So this patch instead simplifies > these copied algorithms, removing their constraints and unused > parameters, and keeps them around. In a subsequent patch we're going to > copy ranges::find into as well. > > libstdc++-v3/ChangeLog: > > * include/std/ranges (__detail::find_if): Simplify. > (__detail::find_if_not): Likewise. > (__detail::min): Remove. > (__detail::mismatch): Simplify. > (take_view::size): Use std::min instead of __detail::min. > --- > libstdc++-v3/include/std/ranges | 59 ++++++++++----------------------- > 1 file changed, 17 insertions(+), 42 deletions(-) > > diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges > index cfcbcaba065..9077271e4e6 100644 > --- a/libstdc++-v3/include/std/ranges > +++ b/libstdc++-v3/include/std/ranges > @@ -978,65 +978,40 @@ namespace views::__adaptor > using all_t = decltype(all(std::declval<_Range>())); > } // namespace views > > - // XXX: the following algos are copied from ranges_algo.h to avoid a circular > - // dependency with that header. > + // The following simple algos are transcribed from ranges_algo.h to avoid > + // having to include that entire header. > namespace __detail > { > - template _Sent, > - typename _Proj = identity, > - indirect_unary_predicate> _Pred> > + template > constexpr _Iter > - find_if(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) > + find_if(_Iter __first, _Sent __last, _Pred __pred) > { > while (__first != __last > - && !(bool)std::__invoke(__pred, std::__invoke(__proj, *__first))) > + && !(bool)std::__invoke(__pred, *__first)) > ++__first; > return __first; > } > > - template _Sent, > - typename _Proj = identity, > - indirect_unary_predicate> _Pred> > + template > constexpr _Iter > - find_if_not(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) > + find_if_not(_Iter __first, _Sent __last, _Pred __pred) > { > while (__first != __last > - && (bool)std::__invoke(__pred, std::__invoke(__proj, *__first))) > + && (bool)std::__invoke(__pred, *__first)) > ++__first; > return __first; > } > > - template - indirect_strict_weak_order> > - _Comp = ranges::less> > - constexpr const _Tp& > - min(const _Tp& __a, const _Tp& __b, _Comp __comp = {}, _Proj __proj = {}) > - { > - if (std::__invoke(std::move(__comp), > - std::__invoke(__proj, __b), > - std::__invoke(__proj, __a))) > - return __b; > - else > - return __a; > - } > - > - template _Sent1, > - input_iterator _Iter2, sentinel_for<_Iter2> _Sent2, > - typename _Pred = ranges::equal_to, > - typename _Proj1 = identity, typename _Proj2 = identity> > - requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> > + template > constexpr pair<_Iter1, _Iter2> > - mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, > - _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) > + mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2) > { > while (__first1 != __last1 && __first2 != __last2 > - && (bool)std::__invoke(__pred, > - std::__invoke(__proj1, *__first1), > - std::__invoke(__proj2, *__first2))) > - { > - ++__first1; > - ++__first2; > - } > + && (bool)ranges::equal_to{}(*__first1, *__first2)) > + { > + ++__first1; > + ++__first2; > + } > return { std::move(__first1), std::move(__first2) }; > } > } // namespace __detail > @@ -1847,14 +1822,14 @@ namespace views::__adaptor > size() requires sized_range<_Vp> > { > auto __n = ranges::size(_M_base); > - return __detail::min(__n, static_cast(_M_count)); > + return std::min(__n, static_cast(_M_count)); > } > > constexpr auto > size() const requires sized_range > { > auto __n = ranges::size(_M_base); > - return __detail::min(__n, static_cast(_M_count)); > + return std::min(__n, static_cast(_M_count)); > } > }; > > -- > 2.31.1.133.g84d06cdc06 > >