[libcxx-commits] [PATCH] D103341: [libcxx][nfc] Cleanup cpp20_input_iterator.

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 28 13:58:02 PDT 2021


zoecarver created this revision.
zoecarver added reviewers: Quuxplusone, cjdb, ldionne.
zoecarver requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

As requested by Arthur in D102020 <https://reviews.llvm.org/D102020>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103341

Files:
  libcxx/test/support/test_iterators.h


Index: libcxx/test/support/test_iterators.h
===================================================================
--- libcxx/test/support/test_iterators.h
+++ libcxx/test/support/test_iterators.h
@@ -634,14 +634,12 @@
 bool operator!= (const NonThrowingIterator<T>& a, const NonThrowingIterator<T>& b) TEST_NOEXCEPT
 {   return !a.operator==(b); }
 
-#ifdef TEST_SUPPORTS_RANGES
-
-// clang-format off
+#if TEST_STD_VER >= 14
 
 template <class I>
 struct cpp20_input_iterator {
-  using value_type = std::iter_value_t<I>;
-  using difference_type = std::iter_difference_t<I>;
+  using value_type = typename std::iterator_traits<I>::value_type;
+  using difference_type = typename std::iterator_traits<I>::difference_type;
   using iterator_concept = std::input_iterator_tag;
 
   cpp20_input_iterator() = default;
@@ -655,22 +653,39 @@
   explicit constexpr cpp20_input_iterator(I base) : base_(std::move(base)) {}
 
   constexpr decltype(auto) operator*() const { return *base_; }
-
   constexpr cpp20_input_iterator& operator++() {
     ++base_;
     return *this;
   }
-
   constexpr void operator++(int) { ++base_; }
 
-  [[nodiscard]] constexpr I const& base() const& { return base_; }
+  constexpr I const& base() const& { return base_; }
+  constexpr I base() && { return std::move(base_); }
 
-  [[nodiscard]] constexpr I base() && { return std::move(base_); }
+  struct sentinel {
+    friend cpp20_input_iterator;
+
+    sentinel() = default;
+    sentinel(I base) : base(base) {}
+
+  private:
+    I base = I();
+  };
+
+  friend constexpr bool operator==(const sentinel& lhs, const cpp20_input_iterator& rhs) { return lhs.base == rhs.base(); }
+  friend constexpr bool operator==(const cpp20_input_iterator& lhs, const sentinel& rhs) { return lhs.base() == rhs.base; }
+
+  template <class T>
+  void operator,(T const &) DELETE_FUNCTION;
 
 private:
   I base_ = I();
 };
 
+#endif // TEST_STD_VER >= 14
+
+#ifdef TEST_SUPPORTS_RANGES
+
 template <std::input_or_output_iterator I>
 struct iterator_concept {
   using type = std::output_iterator_tag;
@@ -854,6 +869,9 @@
     return !(x < y);
   }
 
+  template <class T>
+  void operator,(T const &) DELETE_FUNCTION;
+
 private:
   I base_;
   difference_type stride_count_ = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103341.348581.patch
Type: text/x-patch
Size: 2242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210528/748a5ad7/attachment.bin>


More information about the libcxx-commits mailing list