From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id BBB30388CC0B; Wed, 21 Apr 2021 03:27:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBB30388CC0B MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-9739] libstdc++: Simplify copy-pasted algorithms in X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: d1af36d4f9d80dc7081078ede2999bd4853cfb75 X-Git-Newrev: 8ac3b416bfdae9b72dd0804f3cf0a77f9dc20fcc Message-Id: <20210421032753.BBB30388CC0B@sourceware.org> Date: Wed, 21 Apr 2021 03:27:53 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Apr 2021 03:27:53 -0000 https://gcc.gnu.org/g:8ac3b416bfdae9b72dd0804f3cf0a77f9dc20fcc commit r10-9739-g8ac3b416bfdae9b72dd0804f3cf0a77f9dc20fcc Author: Patrick Palka Date: Thu Apr 8 16:45:25 2021 -0400 libstdc++: Simplify copy-pasted algorithms in 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'd increase the size of by ~10%. 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 (a simplified version of) 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. (cherry picked from commit c1ce418af29bc1796bfe82a5aa97639eccc30cb7) Diff: --- 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 880f6eefc80..d885fb52fd5 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1277,65 +1277,40 @@ namespace views } // 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> - _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 @@ -2112,14 +2087,14 @@ namespace views 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)); } };