[libcxx-commits] [PATCH] D108575: [libcxx] Define insert_iterator::iter with ranges::iterator_t
Joe Loser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 24 21:26:33 PDT 2021
jloser updated this revision to Diff 368547.
jloser added a comment.
Add test for type without iterator type alias
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108575/new/
https://reviews.llvm.org/D108575
Files:
libcxx/include/__iterator/insert_iterator.h
libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp
Index: libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp
===================================================================
--- libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp
+++ libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iterator/types.pass.cpp
@@ -28,6 +28,7 @@
// typedef void pointer;
// };
+#include <__ranges/access.h>
#include <iterator>
#include <type_traits>
#include <vector>
@@ -74,5 +75,27 @@
{
test<std::vector<int> >();
- return 0;
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
+ struct WithoutIteratorTypeAlias {
+ private:
+ using Container = std::vector<int>;
+
+ public:
+ WithoutIteratorTypeAlias() = default;
+ WithoutIteratorTypeAlias(const WithoutIteratorTypeAlias&) = default;
+
+ using value_type = Container;
+
+ std::ranges::iterator_t<Container> iter{};
+
+ auto begin() { return iter; }
+
+ std::insert_iterator<value_type> insert(Container& container, decltype(iter) i) {
+ return std::insert_iterator<Container>(container, i);
+ }
+ };
+ test<WithoutIteratorTypeAlias>();
+#endif
+
+ return 0;
}
Index: libcxx/include/__iterator/insert_iterator.h
===================================================================
--- libcxx/include/__iterator/insert_iterator.h
+++ libcxx/include/__iterator/insert_iterator.h
@@ -14,6 +14,7 @@
#include <__iterator/iterator.h>
#include <__iterator/iterator_traits.h>
#include <__memory/addressof.h>
+#include <__ranges/access.h>
#include <__utility/move.h>
#include <cstddef>
@@ -36,8 +37,12 @@
_LIBCPP_SUPPRESS_DEPRECATED_POP
protected:
_Container* container;
- typename _Container::iterator iter; // FIXME: `ranges::iterator_t<Container>` in C++20 mode
-public:
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
+ ranges::iterator_t<_Container> iter;
+#else
+ typename _Container::iterator iter;
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
+ public:
typedef output_iterator_tag iterator_category;
typedef void value_type;
#if _LIBCPP_STD_VER > 17
@@ -49,7 +54,7 @@
typedef void reference;
typedef _Container container_type;
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, decltype(iter) __i)
: container(_VSTD::addressof(__x)), iter(__i) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
{iter = container->insert(iter, __value_); ++iter; return *this;}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108575.368547.patch
Type: text/x-patch
Size: 2812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210825/e8357b15/attachment.bin>
More information about the libcxx-commits
mailing list