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.129.124]) by sourceware.org (Postfix) with ESMTPS id 354213858C56 for ; Sat, 8 Jun 2024 15:06:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 354213858C56 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 354213858C56 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=1717859164; cv=none; b=SHND49v5SwWyBgzebT+j6vAeRmhfNtx+Dp5Rzp8gRO1QG+Tr5N7KzsBKH+bwAsg/98XiLiu13AqbRSmGCKgyeIOnsl+M8glVdy68LzY0ZFOyPkFv4CM9WMw6+JY6libUzOhHIbEQuXXxWdW+W0mfUi6J1sawzU7T3Vto97BiQQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717859164; c=relaxed/simple; bh=fEE8XHFb8tCiM1kBX95lLFP3TbTCHgqkOawIZtz36+w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PtEulrHuyaWA/8zgMV9GpLK9V3ekzRj0J1XaWDtlymiGvQIE874Wy/RDVf1YjEdqe8m2l3FwfucuQeFi+yOf8OApSg3+VgU4DfrMEVCxE8bq2XSLioQMzz/FtCXCBcIdXI9gmb7ad/p2dpJO0IrUoxobEVi+GzoMCvbLS9DAnVg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717859161; 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=ZQ50YyJUet0OOgwUseBqEkeCxjAbnvhWii74aQKFcX1Z8QcMwZTzgtjPBXV7d2lbJE6zse E5MkRqYDV2UzU9NF81h+V5u9H+Ar7JxZoD+uJoSJ5wB8CnSXi+0wudqYCA0SogEviTiGgR 32vTrykIr9YvlUpehNIQ9YmS+1s5/a0= 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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=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: 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 -- 2.45.1