[libcxx-commits] [libcxx] [libc++][NFC] Add additional tests for begin/end of std::ranges::take_view (PR #79085)

Will Hawkins via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 8 05:25:38 PDT 2024


================
@@ -65,4 +65,54 @@ struct View : std::ranges::view_base {
   int* end_;
 };
 
+template <template <class...> typename Iter, bool Simple, bool Sized>
+struct CommonInputView : std::ranges::view_base {
+  constexpr explicit CommonInputView(int* b, int* e) : begin_(b), end_(e) {}
+
+  constexpr Iter<int*> begin() const { return Iter<int*>(begin_); }
+  constexpr Iter<int*> end() const { return Iter<int*>(end_); }
+
+  constexpr Iter<const int*> begin()
+    requires(!Simple)
+  {
+    return Iter<const int*>(begin_);
+  }
+  constexpr Iter<const int*> end()
+    requires(!Simple)
+  {
+    return Iter<const int*>(end_);
+  }
+
+  constexpr auto size() const
+    requires Sized
+  {
+    return end_ - begin_;
+  }
+
+private:
+  int* begin_;
+  int* end_;
+};
+
+using NonSimpleNonSizedView = CommonInputView<common_input_iterator, false, false>;
----------------
hawkinsw wrote:

I like this very much!

https://github.com/llvm/llvm-project/pull/79085


More information about the libcxx-commits mailing list