[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
Wed Oct 5 01:33:39 PDT 2022


phyBrackets created this revision.
phyBrackets added reviewers: philnik, ldionne.
phyBrackets added a project: libc++.
Herald added a project: All.
phyBrackets requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Initial patch for implementing https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2520r0.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135248

Files:
  libcxx/include/__iterator/move_iterator.h
  libcxx/include/version


Index: libcxx/include/version
===================================================================
--- libcxx/include/version
+++ libcxx/include/version
@@ -115,6 +115,7 @@
 __cpp_lib_logical_traits                                201510L <type_traits>
 __cpp_lib_make_from_tuple                               201606L <tuple>
 __cpp_lib_make_reverse_iterator                         201402L <iterator>
+__cpp_lib_move_iterator_concept                         202207L <iterator>
 __cpp_lib_make_unique                                   201304L <memory>
 __cpp_lib_map_try_emplace                               201411L <map>
 __cpp_lib_math_constants                                201907L <numbers>
@@ -294,6 +295,7 @@
 # undef  __cpp_lib_array_constexpr
 # define __cpp_lib_array_constexpr                      201811L
 # define __cpp_lib_assume_aligned                       201811L
+#define __cpp_lib_move_iterator_concept                 202207L 
 # define __cpp_lib_atomic_flag_test                     201907L
 // # define __cpp_lib_atomic_float                         201711L
 # define __cpp_lib_atomic_lock_free_type_aliases        201907L
Index: libcxx/include/__iterator/move_iterator.h
===================================================================
--- libcxx/include/__iterator/move_iterator.h
+++ libcxx/include/__iterator/move_iterator.h
@@ -59,10 +59,27 @@
     : public __move_iter_category_base<_Iter>
 #endif
 {
+    private:
+   
+   static constexpr auto _Get_Iterator_Tag() {
+     if constexpr (__is_cpp17_random_access_iterator<_Iter>::value) {
+        return random_access_iterator_tag{};
+     } else if constexpr (__is_cpp17_forward_iterator<_Iter>::value) {
+        return forward_iterator_tag{};
+     } else if constexpr (__is_cpp17_bidirectional_iterator<_Iter>::value) {
+        return bidirectional_iterator_tag{};
+     } else {
+        return input_iterator_tag{}; 
+     }
+   }
+    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_Tag());
     // iterator_category is inherited and not always present
     using value_type = iter_value_t<_Iter>;
     using difference_type = iter_difference_t<_Iter>;
@@ -216,11 +233,6 @@
         return ranges::iter_swap(__x.__current_, __y.__current_);
     }
 #endif // _LIBCPP_STD_VER > 17
-
-private:
-    template<class _It2> friend class move_iterator;
-
-    _Iter __current_;
 };
 
 template <class _Iter1, class _Iter2>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135248.465318.patch
Type: text/x-patch
Size: 2611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221005/31709d95/attachment.bin>


More information about the libcxx-commits mailing list