From patchwork Sat Jun 8 15:03:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1945496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NOmSjSyN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VxLxf37nyz20Q5 for ; Sun, 9 Jun 2024 01:06:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 249B1385332C for ; Sat, 8 Jun 2024 15:06:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D9DF63858417 for ; Sat, 8 Jun 2024 15:06:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9DF63858417 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 D9DF63858417 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=1717859165; cv=none; b=avU35Yi/FNBWidGRK8l30TcXRVRvMcAPzKMFFKs8WipCAyLjebWTN3TJD/Gg3hodGodEfPdwLAuBsmPL9MRJeAw27maO43Ex/mw+0y+W5V9JlmwIFPxriexxc12q239JyZtOUuowKe9MJ3cvWJjhvNRscLQhgYXlsIo4E6f7o8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717859165; c=relaxed/simple; bh=fEE8XHFb8tCiM1kBX95lLFP3TbTCHgqkOawIZtz36+w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SH+wK9tJZNmWqaYifCRhcTX/ltIVOrxvTUbkR2A/echkOurvUX9l61vNxix3miI1HJ43S+dQ9lr111vYC5xdShdjpKWmSNI/LBZWhZaNC1IoLKW2+5BurQ14FvvRfQJbx48Vl8UcVlAKuGBUdTay3d/r5DFAQRntBXZijo9hsy0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717859163; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=baBoF9Y1qsMTua6ZR4FW0zLF735KmPflRdBiakP3RWc=; b=NOmSjSyNnhZm8Z0GJziWnVm719Iw0KkMRSRYjDP0o78X0k9f7cz7nltJgtPwYzbZ3NfkQ6 nIo+K5Q1QTzwzSmUiZHN3rNsvB/wGnXWfRk6ViuMw2PgRN0B4tCxmoXpqaVbsN2tgzHUNe Pi2nBV2uMIMfNQH8o5GBLFnh6ZxzEsc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-LxZnpKlEMA6z1ZbcgGBavA-1; Sat, 08 Jun 2024 11:05:59 -0400 X-MC-Unique: LxZnpKlEMA6z1ZbcgGBavA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C0AF419560AE; Sat, 8 Jun 2024 15:05:58 +0000 (UTC) Received: from localhost (unknown [10.39.192.128]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9727919560AB; Sat, 8 Jun 2024 15:05:57 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Michael Levine Subject: [committed v4] libstdc++: Fix std::ranges::iota is not included in numeric [PR108760] Date: Sat, 8 Jun 2024 16:03:00 +0100 Message-ID: <20240608150555.457573-1-jwakely@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.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, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Michael Levine I committed the missing include separately, and pushed Michael's change as attached (with some whitespace tweaks and a changelog entry). Thanks for the patch, Michael! Tested x86_64-linux. Pushed to trunk. I'm in two minds about backporting this one. It would be good to fix the non-conformance problem for the release branches, but it also potentially breaks some code that uses ranges::iota without including . Ideally we'd make ranges::iota available in *both* and for gcc-13 and gcc-14, as a transition aid. I'm not sure I can be bothered to move it to a separate header to make that work, nor to include all of bits/ranges_algo.h in . -- >8 -- Before this patch, using std::ranges::iota required including when it should have been sufficient to only include . libstdc++-v3/ChangeLog: PR libstdc++/108760 * include/bits/ranges_algo.h (ranges::out_value_result): Move to . (ranges::iota_result, ranges::__iota_fn, ranges::iota): Move to . * include/bits/ranges_algobase.h (ranges::out_value_result): Move to here. * include/std/numeric (ranges::iota_result, ranges::__iota_fn) (ranges::iota): Move to here. * testsuite/25_algorithms/iota/1.cc: Renamed to ... * testsuite/26_numerics/iota/2.cc: ... here. Signed-off-by: Michael Levine --- libstdc++-v3/include/bits/ranges_algo.h | 52 ------------------- libstdc++-v3/include/bits/ranges_algobase.h | 24 +++++++++ libstdc++-v3/include/std/numeric | 38 ++++++++++++++ .../iota/1.cc => 26_numerics/iota/2.cc} | 2 +- 4 files changed, 63 insertions(+), 53 deletions(-) rename libstdc++-v3/testsuite/{25_algorithms/iota/1.cc => 26_numerics/iota/2.cc} (96%) diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index 62faff173bd..d258be0b93f 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -3521,58 +3521,6 @@ namespace ranges #endif // __glibcxx_ranges_contains -#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 - - template - struct out_value_result - { - [[no_unique_address]] _Out out; - [[no_unique_address]] _Tp value; - - template - requires convertible_to - && convertible_to - constexpr - operator out_value_result<_Out2, _Tp2>() const & - { return {out, value}; } - - template - requires convertible_to<_Out, _Out2> - && convertible_to<_Tp, _Tp2> - constexpr - operator out_value_result<_Out2, _Tp2>() && - { return {std::move(out), std::move(value)}; } - }; - - template - using iota_result = out_value_result<_Out, _Tp>; - - struct __iota_fn - { - template _Sent, weakly_incrementable _Tp> - requires indirectly_writable<_Out, const _Tp&> - constexpr iota_result<_Out, _Tp> - operator()(_Out __first, _Sent __last, _Tp __value) const - { - while (__first != __last) - { - *__first = static_cast(__value); - ++__first; - ++__value; - } - return {std::move(__first), std::move(__value)}; - } - - template _Range> - constexpr iota_result, _Tp> - operator()(_Range&& __r, _Tp __value) const - { return (*this)(ranges::begin(__r), ranges::end(__r), std::move(__value)); } - }; - - inline constexpr __iota_fn iota{}; - -#endif // __glibcxx_ranges_iota - #if __glibcxx_ranges_find_last >= 202207L // C++ >= 23 struct __find_last_fn diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h index e1f00838818..7ce5ac314f2 100644 --- a/libstdc++-v3/include/bits/ranges_algobase.h +++ b/libstdc++-v3/include/bits/ranges_algobase.h @@ -35,6 +35,7 @@ #include #include #include +#include // __memcpy #include // ranges::begin, ranges::range etc. #include // __invoke #include // __is_byte @@ -71,6 +72,29 @@ namespace ranges __is_move_iterator> = true; } // namespace __detail +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 + template + struct out_value_result + { + [[no_unique_address]] _Out out; + [[no_unique_address]] _Tp value; + + template + requires convertible_to + && convertible_to + constexpr + operator out_value_result<_Out2, _Tp2>() const & + { return {out, value}; } + + template + requires convertible_to<_Out, _Out2> + && convertible_to<_Tp, _Tp2> + constexpr + operator out_value_result<_Out2, _Tp2>() && + { return {std::move(out), std::move(value)}; } + }; +#endif // __glibcxx_ranges_iota + struct __equal_fn { template _Sent1, diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric index c912db4a519..201bb8e74a1 100644 --- a/libstdc++-v3/include/std/numeric +++ b/libstdc++-v3/include/std/numeric @@ -89,6 +89,10 @@ #define __glibcxx_want_saturation_arithmetic #include +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 +# include // for ranges::out_value_result +#endif + #ifdef __glibcxx_saturation_arithmetic // C++ >= 26 # include #endif @@ -726,6 +730,40 @@ namespace __detail /// @} group numeric_ops #endif // C++17 +namespace ranges +{ +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 + + template + using iota_result = out_value_result<_Out, _Tp>; + + struct __iota_fn + { + template _Sent, weakly_incrementable _Tp> + requires indirectly_writable<_Out, const _Tp&> + constexpr iota_result<_Out, _Tp> + operator()(_Out __first, _Sent __last, _Tp __value) const + { + while (__first != __last) + { + *__first = static_cast(__value); + ++__first; + ++__value; + } + return {std::move(__first), std::move(__value)}; + } + + template _Range> + constexpr iota_result, _Tp> + operator()(_Range&& __r, _Tp __value) const + { return (*this)(ranges::begin(__r), ranges::end(__r), std::move(__value)); } + }; + + inline constexpr __iota_fn iota{}; + +#endif // __glibcxx_ranges_iota +} // namespace ranges + _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/testsuite/25_algorithms/iota/1.cc b/libstdc++-v3/testsuite/26_numerics/iota/2.cc similarity index 96% rename from libstdc++-v3/testsuite/25_algorithms/iota/1.cc rename to libstdc++-v3/testsuite/26_numerics/iota/2.cc index 61bf418b4da..040c48d91ce 100644 --- a/libstdc++-v3/testsuite/25_algorithms/iota/1.cc +++ b/libstdc++-v3/testsuite/26_numerics/iota/2.cc @@ -1,6 +1,6 @@ // { dg-do run { target c++23 } } -#include +#include #include #include