libstdc++: Apply proposed resolution for LWG 3450
authorPatrick Palka <ppalka@redhat.com>
Mon, 12 Oct 2020 17:46:24 +0000 (13:46 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 12 Oct 2020 17:46:24 +0000 (13:46 -0400)
libstdc++-v3/ChangeLog:

* include/std/ranges (take_while_view::begin): Constrain the
const overload further as per LWG 3450.
(take_while_view::end): Likewise.
* testsuite/std/ranges/adaptors/take_while.cc: Add test for LWG
3450.

libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/adaptors/take_while.cc

index 19bc01a3b3a656861453cdc313cea0209b60e498..55e7c4de234c5db3a865b778a0e809e7ad738eba 100644 (file)
@@ -1888,6 +1888,7 @@ namespace views
 
       constexpr auto
       begin() const requires range<const _Vp>
+       && indirect_unary_predicate<const _Pred, iterator_t<const _Vp>>
       { return ranges::begin(_M_base); }
 
       constexpr auto
@@ -1897,6 +1898,7 @@ namespace views
 
       constexpr auto
       end() const requires range<const _Vp>
+       && indirect_unary_predicate<const _Pred, iterator_t<const _Vp>>
       { return _Sentinel<true>(ranges::end(_M_base),
                               std::__addressof(*_M_pred)); }
     };
index d587127b97ebe54039df6434dc73b5057d208c20..48771397f1d8be0c30025094a1a41dc1af1122dd 100644 (file)
@@ -70,10 +70,20 @@ test03()
   b = ranges::end(v);
 }
 
+void
+test04()
+{
+  // LWG 3450
+  auto v = views::single(1) | views::take_while([](int& x) { return true;});
+  static_assert(ranges::range<decltype(v)>);
+  static_assert(!ranges::range<decltype(v) const>);
+}
+
 int
 main()
 {
   test01();
   test02();
   test03();
+  test04();
 }