public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Fix typo in stride_view's operator- [PR107313]
@ 2022-10-19 14:31 Patrick Palka
  2022-10-19 16:51 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-10-19 14:31 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Patrick Palka

	PR libstdc++/107313

libstdc++-v3/ChangeLog:

	* include/std/ranges (stride_view::_Iterator::operator-): Fix typo.
	* testsuite/std/ranges/adaptors/stride/1.cc (test03): New test.
---
 libstdc++-v3/include/std/ranges               |  2 +-
 .../testsuite/std/ranges/adaptors/stride/1.cc | 20 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index d113cf19dc7..b29264931cc 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -7874,7 +7874,7 @@ namespace views::__adaptor
     friend constexpr difference_type
     operator-(default_sentinel_t __y, const _Iterator& __x)
       requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>>
-    { return __detail::__div_ceil(__x._M_end, __x._M_current, __x._M_stride); }
+    { return __detail::__div_ceil(__x._M_end - __x._M_current, __x._M_stride); }
 
     friend constexpr difference_type
     operator-(const _Iterator& __x, default_sentinel_t __y)
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
index 745d1a61c1b..37ae896014a 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
@@ -64,10 +64,30 @@ test02()
   VERIFY( ranges::equal(v, (int[]){1, 4, 7}) );
 }
 
+void
+test03()
+{
+  // PR libstdc++/107313
+  int x[] = {1, 2, 3, 4, 5};
+  __gnu_test::test_input_range<int> rx(x);
+  auto r = views::counted(rx.begin(), 4) | views::stride(2);
+  auto i = r.begin();
+  std::default_sentinel_t s = r.end();
+  VERIFY( s != i );
+  VERIFY( s - i == 2 && i - s == -2 );
+  ++i;
+  VERIFY( s != i );
+  VERIFY( s - i == 1 && i - s == -1 );
+  ++i;
+  VERIFY( s == i );
+  VERIFY( s - i == 0 && i - s == 0 );
+}
+
 int
 main()
 {
   static_assert(test01());
   test02<__gnu_test::test_input_range<int>>();
   test02<__gnu_test::test_forward_range<int>>();
+  test03();
 }
-- 
2.38.1.119.g9c32cfb49c


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libstdc++: Fix typo in stride_view's operator- [PR107313]
  2022-10-19 14:31 [PATCH] libstdc++: Fix typo in stride_view's operator- [PR107313] Patrick Palka
@ 2022-10-19 16:51 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-10-19 16:51 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, libstdc++

On Wed, 19 Oct 2022 at 15:33, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
>         PR libstdc++/107313

OK


>
> libstdc++-v3/ChangeLog:
>
>         * include/std/ranges (stride_view::_Iterator::operator-): Fix typo.
>         * testsuite/std/ranges/adaptors/stride/1.cc (test03): New test.
> ---
>  libstdc++-v3/include/std/ranges               |  2 +-
>  .../testsuite/std/ranges/adaptors/stride/1.cc | 20 +++++++++++++++++++
>  2 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
> index d113cf19dc7..b29264931cc 100644
> --- a/libstdc++-v3/include/std/ranges
> +++ b/libstdc++-v3/include/std/ranges
> @@ -7874,7 +7874,7 @@ namespace views::__adaptor
>      friend constexpr difference_type
>      operator-(default_sentinel_t __y, const _Iterator& __x)
>        requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>>
> -    { return __detail::__div_ceil(__x._M_end, __x._M_current, __x._M_stride); }
> +    { return __detail::__div_ceil(__x._M_end - __x._M_current, __x._M_stride); }
>
>      friend constexpr difference_type
>      operator-(const _Iterator& __x, default_sentinel_t __y)
> diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
> index 745d1a61c1b..37ae896014a 100644
> --- a/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
> +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/stride/1.cc
> @@ -64,10 +64,30 @@ test02()
>    VERIFY( ranges::equal(v, (int[]){1, 4, 7}) );
>  }
>
> +void
> +test03()
> +{
> +  // PR libstdc++/107313
> +  int x[] = {1, 2, 3, 4, 5};
> +  __gnu_test::test_input_range<int> rx(x);
> +  auto r = views::counted(rx.begin(), 4) | views::stride(2);
> +  auto i = r.begin();
> +  std::default_sentinel_t s = r.end();
> +  VERIFY( s != i );
> +  VERIFY( s - i == 2 && i - s == -2 );
> +  ++i;
> +  VERIFY( s != i );
> +  VERIFY( s - i == 1 && i - s == -1 );
> +  ++i;
> +  VERIFY( s == i );
> +  VERIFY( s - i == 0 && i - s == 0 );
> +}
> +
>  int
>  main()
>  {
>    static_assert(test01());
>    test02<__gnu_test::test_input_range<int>>();
>    test02<__gnu_test::test_forward_range<int>>();
> +  test03();
>  }
> --
> 2.38.1.119.g9c32cfb49c
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-19 16:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 14:31 [PATCH] libstdc++: Fix typo in stride_view's operator- [PR107313] Patrick Palka
2022-10-19 16:51 ` Jonathan Wakely

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).