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

Konstantin Varlamov via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 1 16:05:20 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>;
----------------
var-const wrote:

Optional: when passing booleans or numeric constants as parameters, I often find it more readable to annotate them with comments to imitate named parameters:
```cpp
using NonSimpleNonSizedView = CommonInputView<common_input_iterator, /*Simple=*/false, /*Sized=*/false>;
```

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


More information about the libcxx-commits mailing list