[libcxx-commits] [PATCH] D122072: [libc++][test] Adds an cpp20_output_iterator.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 27 08:15:54 PDT 2022


Mordante updated this revision to Diff 418451.
Mordante marked 2 inline comments as done.
Mordante added a comment.

Rebase.
Address review comments.
Change to C++20 iterator only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122072

Files:
  libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.output/output_iterator.compile.pass.cpp
  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
@@ -515,6 +515,32 @@
     using type = std::iter_value_t<I>;
 };
 
+template <class It>
+class cpp20_output_iterator {
+  It it_;
+
+public:
+  using difference_type = std::iter_difference_t<It>;
+
+  constexpr explicit cpp20_output_iterator(It it) : it_(it) {}
+  cpp20_output_iterator(cpp20_output_iterator&&) = default;
+  cpp20_output_iterator& operator=(cpp20_output_iterator&&) = default;
+
+  constexpr decltype(auto) operator*() const { return *it_; }
+  constexpr cpp20_output_iterator& operator++() {
+    ++it_;
+    return *this;
+  }
+  constexpr cpp20_output_iterator operator++(int) { return cpp20_output_iterator(it_++); }
+
+  friend constexpr It base(const cpp20_output_iterator& i) { return i.it_; }
+
+  template <class T>
+  void operator,(T const&) = delete;
+};
+
+static_assert(std::output_iterator<cpp20_output_iterator<int*>, int>);
+
 // Iterator adaptor that counts the number of times the iterator has had a successor/predecessor
 // operation called. Has two recorders:
 // * `stride_count`, which records the total number of calls to an op++, op--, op+=, or op-=.
Index: libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.output/output_iterator.compile.pass.cpp
===================================================================
--- libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.output/output_iterator.compile.pass.cpp
+++ libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.output/output_iterator.compile.pass.cpp
@@ -28,6 +28,15 @@
 static_assert( std::output_iterator<cpp17_output_iterator<T*>, DerivedFromT>);
 static_assert(!std::output_iterator<cpp17_output_iterator<DerivedFromT*>, T>);
 
+static_assert( std::output_iterator<cpp20_output_iterator<int*>, int>);
+static_assert( std::output_iterator<cpp20_output_iterator<int*>, short>);
+static_assert( std::output_iterator<cpp20_output_iterator<int*>, long>);
+static_assert( std::output_iterator<cpp20_output_iterator<T*>, T>);
+static_assert(!std::output_iterator<cpp20_output_iterator<T const*>, T>);
+static_assert( std::output_iterator<cpp20_output_iterator<T*>, T const>);
+static_assert( std::output_iterator<cpp20_output_iterator<T*>, DerivedFromT>);
+static_assert(!std::output_iterator<cpp20_output_iterator<DerivedFromT*>, T>);
+
 // Not satisfied when the iterator is not an input_or_output_iterator
 static_assert(!std::output_iterator<void, int>);
 static_assert(!std::output_iterator<void (*)(), int>);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122072.418451.patch
Type: text/x-patch
Size: 2702 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220327/18331b2d/attachment.bin>


More information about the libcxx-commits mailing list