[libcxx-commits] [PATCH] D135248: [libc++] implement move_iterator<T*> should be a random access iterator

Shivam Rajput via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 7 06:03:29 PST 2022


phyBrackets updated this revision to Diff 473644.

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

https://reviews.llvm.org/D135248

Files:
  libcxx/include/__iterator/move_iterator.h
  libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp


Index: libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
===================================================================
--- libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
+++ libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
@@ -142,11 +142,11 @@
 
 #if TEST_STD_VER > 17
   test<contiguous_iterator<char*>>();
-  static_assert(std::is_same_v<typename std::move_iterator<forward_iterator<char*>>::iterator_concept, std::input_iterator_tag>);
-  static_assert(std::is_same_v<typename std::move_iterator<bidirectional_iterator<char*>>::iterator_concept, std::input_iterator_tag>);
-  static_assert(std::is_same_v<typename std::move_iterator<random_access_iterator<char*>>::iterator_concept, std::input_iterator_tag>);
-  static_assert(std::is_same_v<typename std::move_iterator<contiguous_iterator<char*>>::iterator_concept, std::input_iterator_tag>);
-  static_assert(std::is_same_v<typename std::move_iterator<char*>::iterator_concept, std::input_iterator_tag>);
+  static_assert(std::is_same_v<typename std::move_iterator<forward_iterator<char*>>::iterator_concept, std::forward_iterator_tag>);
+  static_assert(std::is_same_v<typename std::move_iterator<bidirectional_iterator<char*>>::iterator_concept, std::bidirectional_iterator_tag>);
+  static_assert(std::is_same_v<typename std::move_iterator<random_access_iterator<char*>>::iterator_concept, std::random_access_iterator_tag>);
+  static_assert(std::is_same_v<typename std::move_iterator<contiguous_iterator<char*>>::iterator_concept, std::random_access_iterator_tag>);
+  static_assert(std::is_same_v<typename std::move_iterator<char*>::iterator_concept, std::random_access_iterator_tag>);
 #endif
 
   return 0;
Index: libcxx/include/__iterator/move_iterator.h
===================================================================
--- libcxx/include/__iterator/move_iterator.h
+++ libcxx/include/__iterator/move_iterator.h
@@ -59,10 +59,28 @@
     : public __move_iter_category_base<_Iter>
 #endif
 {
+    private:
+    #if _LIBCPP_STD_VER > 17
+   static consteval auto _get_iterator_concept() {
+     if constexpr (random_access_iterator<_Iter>) {
+        return random_access_iterator_tag{};
+     }  else if constexpr (bidirectional_iterator<_Iter>) {
+        return bidirectional_iterator_tag{};
+     } else if constexpr (forward_iterator<_Iter>) {
+        return forward_iterator_tag{};
+     } else {
+        return input_iterator_tag{}; 
+     }
+   }
+   #endif //_LIBCPP_STD_VER > 17  
+    template<class _It2> friend class move_iterator;
+
+    _Iter __current_;
+    
 public:
 #if _LIBCPP_STD_VER > 17
     using iterator_type = _Iter;
-    using iterator_concept = input_iterator_tag;
+    using iterator_concept = decltype(_get_iterator_concept());
     // iterator_category is inherited and not always present
     using value_type = iter_value_t<_Iter>;
     using difference_type = iter_difference_t<_Iter>;
@@ -216,11 +234,6 @@
         return ranges::iter_swap(__x.__current_, __y.__current_);
     }
 #endif // _LIBCPP_STD_VER > 17
-
-private:
-    template<class _It2> friend class move_iterator;
-
-    _Iter __current_;
 };
 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_iterator);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135248.473644.patch
Type: text/x-patch
Size: 3282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221107/683bd4d7/attachment-0001.bin>


More information about the libcxx-commits mailing list