diff options
author | Arthur O'Dwyer <arthur.j.odwyer@gmail.com> | 2021-08-26 10:55:18 -0400 |
---|---|---|
committer | Arthur O'Dwyer <arthur.j.odwyer@gmail.com> | 2021-09-02 16:15:53 -0400 |
commit | d1e50738d78a9c1493667526653bb0da55091c98 (patch) | |
tree | 119e81e65007d1812c465814afb4ca56423c47f9 /libcxx/include/__iterator | |
parent | ebbf7f90b5529460bf5cc9dde3f35aa3ee6a6093 (diff) | |
download | llvm-d1e50738d78a9c1493667526653bb0da55091c98.tar.gz |
[libc++] Define insert_iterator::iter with ranges::iterator_t.
The `insert_iterator::iter` member is defined as `Container::iterator` but
the standard requires `iter` to be defined in terms of `ranges::iterator_t` as
of C++20. So, if in C++20 or later, define the `iter` member as
`ranges::iterator_t`.
Original patch by Joe Loser!
Differential Revision: https://reviews.llvm.org/D108575
Diffstat (limited to 'libcxx/include/__iterator')
-rw-r--r-- | libcxx/include/__iterator/insert_iterator.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libcxx/include/__iterator/insert_iterator.h b/libcxx/include/__iterator/insert_iterator.h index 9e41319d4877..33117419881b 100644 --- a/libcxx/include/__iterator/insert_iterator.h +++ b/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> @@ -23,6 +24,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) +template <class _Container> +using __insert_iterator_iter_t = ranges::iterator_t<_Container>; +#else +template <class _Container> +using __insert_iterator_iter_t = typename _Container::iterator; +#endif + _LIBCPP_SUPPRESS_DEPRECATED_PUSH template <class _Container> class _LIBCPP_TEMPLATE_VIS insert_iterator @@ -33,7 +42,7 @@ class _LIBCPP_TEMPLATE_VIS insert_iterator _LIBCPP_SUPPRESS_DEPRECATED_POP protected: _Container* container; - typename _Container::iterator iter; // FIXME: `ranges::iterator_t<Container>` in C++20 mode + __insert_iterator_iter_t<_Container> iter; public: typedef output_iterator_tag iterator_category; typedef void value_type; @@ -46,7 +55,7 @@ public: 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, __insert_iterator_iter_t<_Container> __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;} @@ -62,7 +71,7 @@ public: template <class _Container> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator<_Container> -inserter(_Container& __x, typename _Container::iterator __i) +inserter(_Container& __x, __insert_iterator_iter_t<_Container> __i) { return insert_iterator<_Container>(__x, __i); } |