public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Michael Levine (BLOOMBERG/ 731 LEX)" <mlevine55@bloomberg.net>
To: ppalka@redhat.com
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH v3] libstdc++: Fix std::ranges::iota not in numeric [PR108760]
Date: Fri, 24 May 2024 13:56:19 -0000	[thread overview]
Message-ID: <66509C830000B1C70C340001@message.bloomberg.net> (raw)
In-Reply-To: <798944df-9d81-74b2-486f-908ef87c054c@idea>


[-- Attachment #1.1: Type: text/plain, Size: 2659 bytes --]

I've attached the v3 version of the patch as a single, squashed patch containing all of the changes.  I manually prepended my sign off to the patch.

From: ppalka@redhat.com At: 05/23/24 18:41:14 UTC-4:00To:  Michael Levine (BLOOMBERG/ 731 LEX ) 
Cc:  gcc-patches@gcc.gnu.org,  libstdc++@gcc.gnu.org
Subject: Re: [PATCH v2] libstdc++: Fix std::ranges::iota not included in numeric [PR108760]

On Fri, 17 May 2024, Michael Levine (BLOOMBERG/ 731 LEX) wrote:

> This is the revised version of my patch incorporating the provided feedback 
from Patrick Palka and Jonathan Wakely.
> This patch fixes GCC Bug 108760: 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108760
> I moved out_value_result to <bits/ranges_algobase.h>, moved std::ranges:iota 
into <numeric>, removed my new test, and moved and renamed the existing test.

Nice, thanks!  The incremental changes seem good, but could you send a
single squashed patch containing all the changes?  That's what we'll end
up pushing after all.

> 
> I built my local version of gcc using the following configuration: $ 
../gcc/configure --disable-bootstrap --prefix="$(pwd)/_pfx/" 
--enable-languages=c,c++,lto
> I then ran $ make -jN
> and $ make -jN install
> 
> Using the locally installed version, the following code compiled: 
https://godbolt.org/z/33EPeqd1b
> 
> I tested my changes by running: $ make check-c++ -jN -k
> I personally found it difficult to understand the results of running the 
tests.
> 
> I ran this on the following OS:
> 
> Virtualization: wsl
> Operating System: Ubuntu 20.04.6 LTS
> Kernel: Linux 5.15.146.1-microsoft-standard-WSL2
> Architecture: x86-64
> 
> 
> 
> From: Michael Levine (BLOOMBERG/ 731 LEX) At: 04/17/24 14:24:24 UTC-4:00
> To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
> Subject: [PATCH] libstdc++: Fix std::ranges::iota is not included in numeric 
[PR108760]
> 
> This patch fixes GCC Bug 108760: 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108760
> Before this patch, using std::ranges::iota required including <algorithm> 
when it should have been sufficient to only include <numeric>.
> 
> When the patch is applied, the following code will compile: 
https://godbolt.org/z/33EPeqd1b
> 
> I added a test case for this change as well.
> 
> I built my local version of gcc using the following configuration: $ 
../gcc/configure --disable-bootstrap --prefix="$(pwd)/_pfx/" 
--enable-languages=c,c++,lto
> 
> and I tested my changes by running: $ make check-c++ -jN -k
> 
> I ran this on the following OS:
> 
> Virtualization: wsl
> Operating System: Ubuntu 20.04.6 LTS
> Kernel: Linux 5.15.146.1-microsoft-standard-WSL2
> Architecture: x86-64
> 
> 
> 
> 
> 



[-- Attachment #2: 108760v3.patch --]
[-- Type: application/octet-stream, Size: 5860 bytes --]

Signed-off-by: Michael Levine <mlevine55@bloomberg.net>
---
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<typename _Out, typename _Tp>
-    struct out_value_result
-    {
-      [[no_unique_address]] _Out out;
-      [[no_unique_address]] _Tp value;
-
-      template<typename _Out2, typename _Tp2>
-	requires convertible_to<const _Out&, _Out2>
-	  && convertible_to<const _Tp&, _Tp2>
-	constexpr
-	operator out_value_result<_Out2, _Tp2>() const &
-	{ return {out, value}; }
-
-      template<typename _Out2, typename _Tp2>
-	requires convertible_to<_Out, _Out2>
-	  && convertible_to<_Tp, _Tp2>
-	constexpr
-	operator out_value_result<_Out2, _Tp2>() &&
-	{ return {std::move(out), std::move(value)}; }
-    };
-
-  template<typename _Out, typename _Tp>
-    using iota_result = out_value_result<_Out, _Tp>;
-
-  struct __iota_fn
-  {
-    template<input_or_output_iterator _Out, sentinel_for<_Out> _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<const _Tp&>(__value);
-	    ++__first;
-	    ++__value;
-	  }
-	return {std::move(__first), std::move(__value)};
-      }
-
-    template<weakly_incrementable _Tp, output_range<const _Tp&> _Range>
-      constexpr iota_result<borrowed_iterator_t<_Range>, _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 e26a73a27d6..965b36aed35 100644
--- a/libstdc++-v3/include/bits/ranges_algobase.h
+++ b/libstdc++-v3/include/bits/ranges_algobase.h
@@ -35,6 +35,7 @@
 #include <compare>
 #include <bits/stl_iterator_base_funcs.h>
 #include <bits/stl_iterator.h>
+#include <bits/stl_algobase.h> // __memcpy
 #include <bits/ranges_base.h> // ranges::begin, ranges::range etc.
 #include <bits/invoke.h>      // __invoke
 #include <bits/cpp_type_traits.h> // __is_byte
@@ -70,6 +71,32 @@ namespace ranges
 	__is_move_iterator<move_iterator<_Iterator>> = true;
   } // namespace __detail
 
+#if __glibcxx_ranges_iota >= 202202L // C++ >= 23
+
+    template<typename _Out, typename _Tp>
+    struct out_value_result
+    {
+        [[no_unique_address]] _Out out;
+        [[no_unique_address]] _Tp value;
+
+        template<typename _Out2, typename _Tp2>
+	requires convertible_to<const _Out&, _Out2>
+        && convertible_to<const _Tp&, _Tp2>
+	constexpr
+	operator out_value_result<_Out2, _Tp2>() const &
+	{ return {out, value}; }
+
+        template<typename _Out2, typename _Tp2>
+	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<input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric
index c912db4a519..d88f7f02137 100644
--- a/libstdc++-v3/include/std/numeric
+++ b/libstdc++-v3/include/std/numeric
@@ -65,6 +65,10 @@
 # include <parallel/numeric>
 #endif
 
+#if __glibcxx_ranges_iota >= 202202L // C++ >= 23
+#include <bits/ranges_algobase.h> // for out_value_result as used by std::ranges::iota.  It transitively also brings in <bits/ranges_base.h>, from which _Range is used by std::ranges::iota
+#endif // __glibcxx_ranges_iota
+
 #if __cplusplus >= 201402L
 # include <type_traits>
 # include <bit>
@@ -726,6 +730,40 @@ namespace __detail
   /// @} group numeric_ops
 #endif // C++17
 
+namespace ranges
+{
+#if __glibcxx_ranges_iota >= 202202L // C++ >= 23
+
+  template<typename _Out, typename _Tp>
+  using iota_result = out_value_result<_Out, _Tp>;
+
+  struct __iota_fn
+  {
+    template<input_or_output_iterator _Out, sentinel_for<_Out> _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<const _Tp&>(__value);
+	    ++__first;
+	    ++__value;
+	  }
+	return {std::move(__first), std::move(__value)};
+      }
+
+    template<weakly_incrementable _Tp, output_range<const _Tp&> _Range>
+      constexpr iota_result<borrowed_iterator_t<_Range>, _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 <algorithm>
+#include <numeric>
 #include <testsuite_hooks.h>
 #include <testsuite_iterators.h>
 

  reply	other threads:[~2024-05-24 13:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 18:24 [PATCH] libstdc++: Fix std::ranges::iota is not included " Michael Levine (BLOOMBERG/ 919 3RD A)
2024-04-18 21:58 ` Patrick Palka
2024-04-19  9:18   ` Jonathan Wakely
2024-05-17 16:59 ` [PATCH v2] libstdc++: Fix std::ranges::iota " Michael Levine (BLOOMBERG/ 731 LEX)
2024-05-23 22:41   ` Patrick Palka
2024-05-24 13:56     ` Michael Levine (BLOOMBERG/ 731 LEX) [this message]
2024-05-24 14:12       ` [PATCH v3] libstdc++: Fix std::ranges::iota not " Jonathan Wakely
2024-05-30 17:43         ` Michael Levine (BLOOMBERG/ 731 LEX)
2024-06-06 20:49           ` Michael Levine (BLOOMBERG/ 731 LEX)
2024-06-07  8:50             ` Jonathan Wakely
2024-06-08 15:03               ` [committed v4] libstdc++: Fix std::ranges::iota is not included " Jonathan Wakely
2024-06-08 15:55                 ` Ulrich Drepper
2024-06-08 19:23                   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=66509C830000B1C70C340001@message.bloomberg.net \
    --to=mlevine55@bloomberg.net \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).