From patchwork Mon May 22 20:50:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 1784693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=WXdz8psd; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QQ8l054Sxz20PY for ; Tue, 23 May 2023 06:51:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC821385702B for ; Mon, 22 May 2023 20:51:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC821385702B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684788713; bh=JvBqhBHxLM1AnlOO1EWbzKq3YYzBoP0rsIIJSohdG0k=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=WXdz8psddgmzN+UX1sOQHJ7EcdIKkzNuN+j2ebAhLq5CW7ZCJzHJD8K101DCtuwgx +w0+U3v7NpHCSC3a1nBWAuZ9Kpqq64cY2/tCBL1/dMZB+JB96P6ojqQngQto9VGvMd lBDCOLO+vWKOd9U0DZxVsT5ZDLvuTeOlPLZhlLT8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id C71853858D35; Mon, 22 May 2023 20:50:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C71853858D35 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-309382efe13so4110602f8f.2; Mon, 22 May 2023 13:50:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684788656; x=1687380656; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JvBqhBHxLM1AnlOO1EWbzKq3YYzBoP0rsIIJSohdG0k=; b=l7kyCTR7YbbL2VRUo9kFAfRXMhOIW2kobBvKOXXZo4EfQpnvk6cYv3RWZixCkp8EGq KsgPtBd91ydtKzTSFRXqlW5sa3Ky7pubOMZwpi3yfOJtHdKYU4gt82GsTaXC+0CapjfQ gxJL/uBCpCaZuXWiGj4SnMqvqLqdhrlnr1saVKlIQFQRbVmP39G3BuBsYKztreu9YiBF ngnHU28P+L66TkSTI8/4oJCyGAQh9w6QC1SnesEgyQmnZglfmi5iFQ+V8FTVhzmo4Ov5 gNVIGEIkF4uMlbQtkW7Y7KnXmav/DgwZOOdYmW5MipVQOMMiWlVHr0YRdNx6IICnZMFc 8k/g== X-Gm-Message-State: AC+VfDys+To/Y3AnCcTvNPGhVgAX+4bHf/mYkfJ1ATM/V85KzvyBkVE2 HqXAm26uVvCg7JA5FY8aOWVU+nMEJl4= X-Google-Smtp-Source: ACHHUZ48dnMHpR2GAqUa93EDpeA2YIgDRA5buszP11HxDparGxnutJNbMYXriJYHMLifVOKYNrKPFA== X-Received: by 2002:a05:6000:148:b0:309:1532:828a with SMTP id r8-20020a056000014800b003091532828amr8062797wrx.34.1684788655934; Mon, 22 May 2023 13:50:55 -0700 (PDT) Received: from ?IPV6:2a01:e0a:1dc:b1c0:65c4:47fe:e8a3:98a2? ([2a01:e0a:1dc:b1c0:65c4:47fe:e8a3:98a2]) by smtp.gmail.com with ESMTPSA id j15-20020a5d464f000000b003012030a0c6sm8844478wrs.18.2023.05.22.13.50.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 May 2023 13:50:55 -0700 (PDT) Message-ID: <9fbe09f1-ea49-b520-251b-faba47d74179@gmail.com> Date: Mon, 22 May 2023 22:50:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Content-Language: en-US To: libstdc++ Cc: gcc-patches Subject: [PATCH] Replace __gnu_cxx::__ops::__negate with std::not_fn X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Fran=C3=A7ois_Dumont_via_Gcc-patches?= From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Reply-To: =?utf-8?q?Fran=C3=A7ois_Dumont?= Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" I was thinking that it might be nice to get rid of predefined_ops.h content. So here is a start with __negate. Drawback is that stl_algo.h has to include . For now I just get rid of stl_algo.h include in to rather use stl_algobase.h. But maybe it would be better to also isolate std::not_fn in a dedicated header file so that stl_algo.h do not have to include all .     libstdc++: Replace __gnu_cxx::__ops::__negate with std::not_fn     Replace the internal __gnu_cxx::__ops::__negate function and associated     __gnu_cxx::__ops::_Iter_negate by the C++17 std::not_fn.     libstdc++-v3/ChangeLog:             * include/bits/predefined_ops.h: Include .             [__cpp_lib_not_fn](__gnu_cxx::__ops::_Iter_negate): Remove.             [__cpp_lib_not_fn](__gnu_cxx::__ops::__negate): Remove.             * include/bits/stl_algo.h: Include for C++17 and later.             [__cpp_lib_not_fn](__find_if_not): Use std::not_fn.             (std::__search, std::search(_FwdIt1, _FwdIt1, _FwdIt2, _FwdIt2, _BinPred)): Move...             * include/bits/stl_algobase.h: ...here.             * include/std/functional: Replace include by . Tests still running. François diff --git a/libstdc++-v3/include/bits/predefined_ops.h b/libstdc++-v3/include/bits/predefined_ops.h index e9933373ed9..8fdb11ea84b 100644 --- a/libstdc++-v3/include/bits/predefined_ops.h +++ b/libstdc++-v3/include/bits/predefined_ops.h @@ -30,6 +30,7 @@ #ifndef _GLIBCXX_PREDEFINED_OPS_H #define _GLIBCXX_PREDEFINED_OPS_H 1 +#include #include namespace __gnu_cxx @@ -377,6 +378,7 @@ namespace __ops _GLIBCXX_MOVE(__comp._M_comp), __it); } +#if !__cpp_lib_not_fn template struct _Iter_negate { @@ -400,6 +402,7 @@ namespace __ops inline _Iter_negate<_Predicate> __negate(_Iter_pred<_Predicate> __pred) { return _Iter_negate<_Predicate>(_GLIBCXX_MOVE(__pred._M_pred)); } +#endif } // namespace __ops } // namespace __gnu_cxx diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 54695490166..849d8a59ec2 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -65,6 +65,10 @@ #include #endif +#if __cplusplus >= 201703L +#include // for std::not_fn. +#endif + #if _GLIBCXX_HOSTED # include // for _Temporary_buffer # if (__cplusplus <= 201103L || _GLIBCXX_USE_DEPRECATED) @@ -110,7 +114,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Predicate __pred) { return std::__find_if(__first, __last, +#if __cpp_lib_not_fn + std::not_fn(std::move(__pred)), +#else __gnu_cxx::__ops::__negate(__pred), +#endif std::__iterator_category(__first)); } @@ -140,54 +148,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // count // count_if // search - - template - _GLIBCXX20_CONSTEXPR - _ForwardIterator1 - __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, - _BinaryPredicate __predicate) - { - // Test for empty ranges - if (__first1 == __last1 || __first2 == __last2) - return __first1; - - // Test for a pattern of length 1. - _ForwardIterator2 __p1(__first2); - if (++__p1 == __last2) - return std::__find_if(__first1, __last1, - __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2)); - - // General case. - _ForwardIterator1 __current = __first1; - - for (;;) - { - __first1 = - std::__find_if(__first1, __last1, - __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2)); - - if (__first1 == __last1) - return __last1; - - _ForwardIterator2 __p = __p1; - __current = __first1; - if (++__current == __last1) - return __last1; - - while (__predicate(__current, __p)) - { - if (++__p == __last2) - return __first1; - if (++__current == __last1) - return __last1; - } - ++__first1; - } - return __first1; - } - // search_n /** @@ -4147,48 +4107,6 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO __gnu_cxx::__ops::__iter_equal_to_iter()); } - /** - * @brief Search a sequence for a matching sub-sequence using a predicate. - * @ingroup non_mutating_algorithms - * @param __first1 A forward iterator. - * @param __last1 A forward iterator. - * @param __first2 A forward iterator. - * @param __last2 A forward iterator. - * @param __predicate A binary predicate. - * @return The first iterator @c i in the range - * @p [__first1,__last1-(__last2-__first2)) such that - * @p __predicate(*(i+N),*(__first2+N)) is true for each @c N in the range - * @p [0,__last2-__first2), or @p __last1 if no such iterator exists. - * - * Searches the range @p [__first1,__last1) for a sub-sequence that - * compares equal value-by-value with the sequence given by @p - * [__first2,__last2), using @p __predicate to determine equality, - * and returns an iterator to the first element of the - * sub-sequence, or @p __last1 if no such iterator exists. - * - * @see search(_ForwardIter1, _ForwardIter1, _ForwardIter2, _ForwardIter2) - */ - template - _GLIBCXX20_CONSTEXPR - inline _ForwardIterator1 - search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, - _BinaryPredicate __predicate) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>) - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator1>::value_type, - typename iterator_traits<_ForwardIterator2>::value_type>) - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - return std::__search(__first1, __last1, __first2, __last2, - __gnu_cxx::__ops::__iter_comp_iter(__predicate)); - } - /** * @brief Search a sequence for a number of consecutive values. * @ingroup non_mutating_algorithms diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 4a6f8195d98..dd95e94f7e9 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -2150,6 +2150,53 @@ _GLIBCXX_END_NAMESPACE_ALGO return __result; } + template + _GLIBCXX20_CONSTEXPR + _ForwardIterator1 + __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, + _BinaryPredicate __predicate) + { + // Test for empty ranges + if (__first1 == __last1 || __first2 == __last2) + return __first1; + + // Test for a pattern of length 1. + _ForwardIterator2 __p1(__first2); + if (++__p1 == __last2) + return std::__find_if(__first1, __last1, + __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2)); + + // General case. + _ForwardIterator1 __current = __first1; + + for (;;) + { + __first1 = + std::__find_if(__first1, __last1, + __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2)); + + if (__first1 == __last1) + return __last1; + + _ForwardIterator2 __p = __p1; + __current = __first1; + if (++__current == __last1) + return __last1; + + while (__predicate(__current, __p)) + { + if (++__p == __last2) + return __first1; + if (++__current == __last1) + return __last1; + } + ++__first1; + } + return __first1; + } + #if __cplusplus >= 201103L template @@ -2220,6 +2267,51 @@ _GLIBCXX_END_NAMESPACE_ALGO } #endif // C++11 +_GLIBCXX_BEGIN_NAMESPACE_ALGO + + /** + * @brief Search a sequence for a matching sub-sequence using a predicate. + * @ingroup non_mutating_algorithms + * @param __first1 A forward iterator. + * @param __last1 A forward iterator. + * @param __first2 A forward iterator. + * @param __last2 A forward iterator. + * @param __predicate A binary predicate. + * @return The first iterator @c i in the range + * @p [__first1,__last1-(__last2-__first2)) such that + * @p __predicate(*(i+N),*(__first2+N)) is true for each @c N in the range + * @p [0,__last2-__first2), or @p __last1 if no such iterator exists. + * + * Searches the range @p [__first1,__last1) for a sub-sequence that + * compares equal value-by-value with the sequence given by @p + * [__first2,__last2), using @p __predicate to determine equality, + * and returns an iterator to the first element of the + * sub-sequence, or @p __last1 if no such iterator exists. + * + * @see search(_ForwardIter1, _ForwardIter1, _ForwardIter2, _ForwardIter2) + */ + template + _GLIBCXX20_CONSTEXPR + inline _ForwardIterator1 + search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, + _BinaryPredicate __predicate) + { + // concept requirements + __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>) + __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>) + __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, + typename iterator_traits<_ForwardIterator1>::value_type, + typename iterator_traits<_ForwardIterator2>::value_type>) + __glibcxx_requires_valid_range(__first1, __last1); + __glibcxx_requires_valid_range(__first2, __last2); + + return std::__search(__first1, __last1, __first2, __last2, + __gnu_cxx::__ops::__iter_comp_iter(__predicate)); + } + +_GLIBCXX_END_NAMESPACE_ALGO _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index c7c6a5a7924..4a4b8b2b2e6 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -64,7 +64,7 @@ # include # include # endif -# include // std::search +# include // std::search #endif #if __cplusplus >= 202002L # include // std::identity, ranges::equal_to etc.