[libcxx-commits] [PATCH] D133220: [libc++][ranges] fix errors on passing input iterator to `std::views::take`

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Sep 25 07:43:32 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4851fbc3cf23: fix errors on passing input iterator to `std::views::take` (authored by huixie90).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133220/new/

https://reviews.llvm.org/D133220

Files:
  libcxx/include/__ranges/take_view.h
  libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp


Index: libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp
===================================================================
--- libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp
+++ libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp
@@ -194,6 +194,19 @@
     [[maybe_unused]] auto partial = std::views::take(X{});
   }
 
+  // Test when `subrange<Iter>` is not well formed
+  {
+    int input[] = {1, 2, 3};
+    using Iter  = cpp20_input_iterator<int*>;
+    using Sent  = sentinel_wrapper<Iter>;
+    std::ranges::subrange r{Iter{input}, Sent{Iter{input + 3}}};
+    auto tv = std::views::take(std::move(r), 1);
+    auto it                  = tv.begin();
+    assert(*it == 1);
+    ++it;
+    assert(it == tv.end());
+  }
+
   return true;
 }
 
Index: libcxx/include/__ranges/take_view.h
===================================================================
--- libcxx/include/__ranges/take_view.h
+++ libcxx/include/__ranges/take_view.h
@@ -226,6 +226,7 @@
 };
 
 template <class _Iter, class _Sent, subrange_kind _Kind>
+  requires requires{typename subrange<_Iter>;}
 struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
   using type = subrange<_Iter>;
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133220.462729.patch
Type: text/x-patch
Size: 1217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220925/80b8bbcb/attachment.bin>


More information about the libcxx-commits mailing list