]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement LWG 3523 changes to ranges::iota_view
authorPatrick Palka <ppalka@redhat.com>
Tue, 19 Oct 2021 21:54:24 +0000 (17:54 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 12 Apr 2022 12:37:27 +0000 (08:37 -0400)
libstdc++-v3/ChangeLog:

* include/std/ranges (iota_view::_Iterator): Befriend iota_view.
(iota_view::_Sentinel): Likewise.
(iota_view::iota_view): Add three overloads, each taking an
iterator/sentinel pair as per LWG 3523.
* testsuite/std/ranges/iota/iota_view.cc (test06): New test.

(cherry picked from commit 861440a77b62756d200ae356c4fdfd9653902e77)

libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc

index 4a65a49ed3021e22fdd5d9bf4f1c4fea39f6e002..70f571f74fd61ab3208bc15b0f2ce5abecda3ffa 100644 (file)
@@ -496,6 +496,7 @@ namespace ranges
       private:
        _Winc _M_value = _Winc();
 
+       friend iota_view;
         friend _Sentinel;
       };
 
@@ -532,6 +533,8 @@ namespace ranges
        operator-(const _Sentinel& __x, const _Iterator& __y)
          requires sized_sentinel_for<_Bound, _Winc>
        { return __x._M_distance_from(__y); }
+
+       friend iota_view;
       };
 
       _Winc _M_value = _Winc();
@@ -554,6 +557,24 @@ namespace ranges
          __glibcxx_assert( bool(__value <= __bound) );
       }
 
+      constexpr
+      iota_view(_Iterator __first, _Iterator __last)
+       requires same_as<_Winc, _Bound>
+       : iota_view(__first._M_value, __last._M_value)
+      { }
+
+      constexpr
+      iota_view(_Iterator __first, unreachable_sentinel_t __last)
+       requires same_as<_Bound, unreachable_sentinel_t>
+       : iota_view(__first._M_value, __last)
+      { }
+
+      constexpr
+      iota_view(_Iterator __first, _Sentinel __last)
+       requires (!same_as<_Winc, _Bound>) && (!same_as<_Bound, unreachable_sentinel_t>)
+       : iota_view(__first._M_value, __last._M_bound)
+      { }
+
       constexpr _Iterator
       begin() const { return _Iterator{_M_value}; }
 
index 362ef1f7f7859c541ad7dff2f30083644f9a092f..5bebe4be693ec8af1eade2c6e1469749fa439319 100644 (file)
@@ -18,6 +18,7 @@
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
 
+#include <algorithm>
 #include <ranges>
 #include <testsuite_hooks.h>
 
@@ -90,6 +91,25 @@ test05()
   VERIFY( r.begin() - r.end() == -3 );
 }
 
+void
+test06()
+{
+  // Verify LWG 3523 changes.
+  auto v1 = std::views::iota(0, 5);
+  auto w1 = decltype(v1)(v1.begin(), v1.end());
+  VERIFY( std::ranges::equal(v1, w1) );
+
+  auto v2 = std::views::iota(0);
+  auto w2 = decltype(v2)(v2.begin(), v2.end());
+  static_assert(std::same_as<decltype(w2.end()), std::unreachable_sentinel_t>);
+  VERIFY( *w2.begin() == 0 );
+
+  auto v3 = std::views::iota(0, 5l);
+  auto w3 = decltype(v3)(v3.begin(), v3.end());
+  static_assert(!std::ranges::common_range<decltype(w3)>);
+  VERIFY( std::ranges::equal(v3, w3) );
+}
+
 int
 main()
 {
@@ -98,4 +118,5 @@ main()
   test03();
   test04();
   test05();
+  test06();
 }