[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 05:33:07 PST 2022


phyBrackets updated this revision to Diff 473630.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135248

Files:
  libcxx/include/__iterator/move_iterator.h
  libcxx/test/libcxx/private_headers.verify.cpp
  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/test/libcxx/private_headers.verify.cpp
===================================================================
--- libcxx/test/libcxx/private_headers.verify.cpp
+++ libcxx/test/libcxx/private_headers.verify.cpp
@@ -58,6 +58,9 @@
 #include <__algorithm/find_first_of.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/find_first_of.h'}}
 #include <__algorithm/find_if.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/find_if.h'}}
 #include <__algorithm/find_if_not.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/find_if_not.h'}}
+#include <__algorithm/find_last.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/find_last.h'}}
+#include <__algorithm/find_last_if.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/find_last_if.h'}}
+#include <__algorithm/find_last_if_not.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/find_last_if_not.h'}}
 #include <__algorithm/for_each.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/for_each.h'}}
 #include <__algorithm/for_each_n.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/for_each_n.h'}}
 #include <__algorithm/generate.h> // expected-error@*:* {{use of private header from outside its module: '__algorithm/generate.h'}}
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.473630.patch
Type: text/x-patch
Size: 4762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221107/a9b98b71/attachment.bin>


More information about the libcxx-commits mailing list