[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
Tue Nov 8 01:51:51 PST 2022
phyBrackets updated this revision to Diff 473920.
phyBrackets marked an inline comment as done.
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/std/iterators/predef.iterators/move.iterators/move.iterator/iterator_specializations.pass.cpp
Index: libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/iterator_specializations.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/iterator_specializations.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <iterator>
+
+// move_iterator
+
+#include <iterator>
+
+#include "test_macros.h"
+#include "test_iterators.h"
+
+
+// Tests for move_iterator specializations
+#if TEST_STD_VER > 20
+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
+int main() {} // COMPILE-ONLY
Index: libcxx/include/__iterator/move_iterator.h
===================================================================
--- libcxx/include/__iterator/move_iterator.h
+++ libcxx/include/__iterator/move_iterator.h
@@ -59,10 +59,24 @@
: public __move_iter_category_base<_Iter>
#endif
{
+ private:
+#if _LIBCPP_STD_VER > 20
+ 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 > 20
public:
-#if _LIBCPP_STD_VER > 17
+#if _LIBCPP_STD_VER > 20
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>;
@@ -70,6 +84,7 @@
using reference = iter_rvalue_reference_t<_Iter>;
#else
typedef _Iter iterator_type;
+ typedef input_iterator_tag iterator_concept;
typedef _If<
__is_cpp17_random_access_iterator<_Iter>::value,
random_access_iterator_tag,
@@ -85,8 +100,7 @@
__libcpp_remove_reference_t<__reference>&&,
__reference
>::type reference;
-#endif // _LIBCPP_STD_VER > 17
-
+#endif // _LIBCPP_STD_VER > 20
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
explicit move_iterator(_Iter __i) : __current_(std::move(__i)) {}
@@ -216,11 +230,10 @@
return ranges::iter_swap(__x.__current_, __y.__current_);
}
#endif // _LIBCPP_STD_VER > 17
-
private:
- template<class _It2> friend class move_iterator;
+template<class _It2> friend class move_iterator;
- _Iter __current_;
+ _Iter __current_;
};
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_iterator);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135248.473920.patch
Type: text/x-patch
Size: 3701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221108/028c7e29/attachment.bin>
More information about the libcxx-commits
mailing list