[libcxx-commits] [PATCH] D117449: [libcxx] Constrain common_iterator's iterator_traits specialization

Casey Carter via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 16 19:24:13 PST 2022


CaseyCarter created this revision.
CaseyCarter added reviewers: libc++, zoecarver.
CaseyCarter added a project: libc++.
CaseyCarter requested review of this revision.
Herald added 1 blocking reviewer(s): libc++.

... to require `input_iterator` per [common.iterator].


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117449

Files:
  libcxx/include/__iterator/common_iterator.h
  libcxx/test/std/iterators/predef.iterators/iterators.common/iterator_traits.compile.pass.cpp


Index: libcxx/test/std/iterators/predef.iterators/iterators.common/iterator_traits.compile.pass.cpp
===================================================================
--- libcxx/test/std/iterators/predef.iterators/iterators.common/iterator_traits.compile.pass.cpp
+++ libcxx/test/std/iterators/predef.iterators/iterators.common/iterator_traits.compile.pass.cpp
@@ -17,6 +17,9 @@
 #include "test_macros.h"
 #include "types.h"
 
+template<class T>
+concept HasIteratorConcept = requires { typename T::iterator_concept; };
+
 void test() {
   {
     using Iter = simple_iterator<int*>;
@@ -48,12 +51,12 @@
     using CommonIter = std::common_iterator<Iter, sentinel_type<int*>>;
     using IterTraits = std::iterator_traits<CommonIter>;
 
-    static_assert(std::same_as<IterTraits::iterator_concept, std::input_iterator_tag>);
-    static_assert(std::same_as<IterTraits::iterator_category, std::input_iterator_tag>);
-    static_assert(std::same_as<IterTraits::value_type, int>);
+    static_assert(!HasIteratorConcept<IterTraits>);
+    static_assert(std::same_as<IterTraits::iterator_category, std::output_iterator_tag>);
+    static_assert(std::same_as<IterTraits::value_type, void>);
     static_assert(std::same_as<IterTraits::difference_type, std::ptrdiff_t>);
     static_assert(std::same_as<IterTraits::pointer, void>);
-    static_assert(std::same_as<IterTraits::reference, int&>);
+    static_assert(std::same_as<IterTraits::reference, void>);
   }
   {
     using Iter = cpp17_input_iterator<int*>;
Index: libcxx/include/__iterator/common_iterator.h
===================================================================
--- libcxx/include/__iterator/common_iterator.h
+++ libcxx/include/__iterator/common_iterator.h
@@ -274,7 +274,7 @@
     using type = decltype(declval<const common_iterator<_Iter, _Sent>>().operator->());
 };
 
-template<class _Iter, class _Sent>
+template<input_iterator _Iter, class _Sent>
 struct iterator_traits<common_iterator<_Iter, _Sent>> {
   using iterator_concept = _If<forward_iterator<_Iter>,
                                forward_iterator_tag,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117449.400421.patch
Type: text/x-patch
Size: 2088 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220117/651e74da/attachment.bin>


More information about the libcxx-commits mailing list