[libcxx-commits] [PATCH] D116808: fix __simple_view concept in std::ranges

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 8 05:30:32 PST 2022


huixie90 updated this revision to Diff 398330.
huixie90 added a comment.

Updating D116808 <https://reviews.llvm.org/D116808>: fix __simple_view concept in std::ranges

add unit tests for drop_view and join_view


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116808

Files:
  libcxx/test/std/ranges/range.adaptors/range.drop/begin.pass.cpp
  libcxx/test/std/ranges/range.adaptors/range.join.view/begin.pass.cpp


Index: libcxx/test/std/ranges/range.adaptors/range.join.view/begin.pass.cpp
===================================================================
--- libcxx/test/std/ranges/range.adaptors/range.join.view/begin.pass.cpp
+++ libcxx/test/std/ranges/range.adaptors/range.join.view/begin.pass.cpp
@@ -19,6 +19,11 @@
 #include "test_macros.h"
 #include "types.h"
 
+struct SimpleParentView : std::ranges::view_base {
+  const ChildView* begin() const;
+  const ChildView* end() const;
+};
+
 constexpr bool test() {
   int buffer[4][4] = {{1111, 2222, 3333, 4444}, {555, 666, 777, 888}, {99, 1010, 1111, 1212}, {13, 14, 15, 16}};
 
@@ -86,6 +91,20 @@
     assert(*jv.begin() == 1111);
   }
 
+  // !simple-view<V>
+  {
+    using WithNonSimpleBase = std::ranges::join_view<ParentView<ChildView>>;
+    static_assert(!std::same_as<decltype(std::declval<WithNonSimpleBase&>().begin()),
+                                decltype(std::declval<WithNonSimpleBase const&>().begin())>);
+  }
+
+  // simple-view<V> && is_reference_v<range_reference_t<V>>;
+  {
+    using WithSimpleBase = std::ranges::join_view<SimpleParentView>;
+    static_assert(std::same_as<decltype(std::declval<WithSimpleBase&>().begin()),
+                               decltype(std::declval<WithSimpleBase const&>().begin())>);
+  }
+
   return true;
 }
 
Index: libcxx/test/std/ranges/range.adaptors/range.drop/begin.pass.cpp
===================================================================
--- libcxx/test/std/ranges/range.adaptors/range.drop/begin.pass.cpp
+++ libcxx/test/std/ranges/range.adaptors/range.drop/begin.pass.cpp
@@ -19,11 +19,31 @@
 #include <ranges>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 #include "types.h"
 
 template<class T>
 concept BeginInvocable = requires(std::ranges::drop_view<T> t) { t.begin(); };
 
+struct SimpleView : std::ranges::view_base {
+  bool non_const_begin_called{false};
+  constexpr int* begin() {
+    non_const_begin_called = true;
+    return nullptr;
+  }
+  constexpr int* begin() const { return nullptr; }
+  constexpr int* end() const { return nullptr; }
+  constexpr std::size_t size() const { return 0u; }
+};
+
+struct NonSimpleView : std::ranges::view_base {
+  int* begin();
+  const int* begin() const;
+  int* end();
+  const int* end() const;
+  std::size_t size() const;
+};
+
 constexpr bool test() {
   // random_access_range<const V> && sized_range<const V>
   std::ranges::drop_view dropView1(MoveOnlyView(), 4);
@@ -62,6 +82,20 @@
 
   static_assert(!BeginInvocable<const ForwardView>);
 
+  // simple_view<V> && random_access_range<const V> && sized_range<const V>
+  {
+    std::ranges::drop_view dropView(SimpleView{}, 4);
+    dropView.begin();
+    assert(!dropView.base().non_const_begin_called);
+  }
+
+  // !simple_view<V> && random_access_range<const V> && sized_range<const V>
+  {
+    using DropView = std::ranges::drop_view<NonSimpleView>;
+    static_assert(std::same_as<decltype(std::declval<DropView&>().begin()), int*>);
+    static_assert(std::same_as<decltype(std::declval<const DropView&>().begin()), const int*>);
+  }
+
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116808.398330.patch
Type: text/x-patch
Size: 3111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220108/a67735fb/attachment-0001.bin>


More information about the libcxx-commits mailing list