diff --git a/libcxx/include/__ranges/filter_view.h b/libcxx/include/__ranges/filter_view.h --- a/libcxx/include/__ranges/filter_view.h +++ b/libcxx/include/__ranges/filter_view.h @@ -46,6 +46,15 @@ #if _LIBCPP_STD_VER > 17 namespace ranges { + + template > _Pred> + requires view<_View> && is_object_v<_Pred> + class __filter_view_iterator; + + template > _Pred> + requires view<_View> && is_object_v<_Pred> + class __filter_view_sentinel; + template> _Pred> requires view<_View> && is_object_v<_Pred> class filter_view : public view_interface> { @@ -58,8 +67,8 @@ using _Cache = _If<_UseCache, __non_propagating_cache>, __empty_cache>; _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache(); - class __iterator; - class __sentinel; + using __iterator = __filter_view_iterator<_View, _Pred>; + using __sentinel = __filter_view_sentinel<_View, _Pred>; public: _LIBCPP_HIDE_FROM_ABI @@ -119,10 +128,13 @@ template> _Pred> requires view<_View> && is_object_v<_Pred> - class filter_view<_View, _Pred>::__iterator : public __filter_iterator_category<_View> { + class __filter_view_iterator : public __filter_iterator_category<_View> { + + using __filter_view = filter_view<_View, _Pred>; + public: _LIBCPP_NO_UNIQUE_ADDRESS iterator_t<_View> __current_ = iterator_t<_View>(); - _LIBCPP_NO_UNIQUE_ADDRESS filter_view* __parent_ = nullptr; + _LIBCPP_NO_UNIQUE_ADDRESS __filter_view* __parent_ = nullptr; using iterator_concept = _If, bidirectional_iterator_tag, @@ -134,10 +146,10 @@ using difference_type = range_difference_t<_View>; _LIBCPP_HIDE_FROM_ABI - __iterator() requires default_initializable> = default; + __filter_view_iterator() requires default_initializable> = default; _LIBCPP_HIDE_FROM_ABI - constexpr __iterator(filter_view& __parent, iterator_t<_View> __current) + constexpr __filter_view_iterator(__filter_view& __parent, iterator_t<_View> __current) : __current_(std::move(__current)), __parent_(std::addressof(__parent)) { } @@ -156,7 +168,7 @@ } _LIBCPP_HIDE_FROM_ABI - constexpr __iterator& operator++() { + constexpr __filter_view_iterator& operator++() { __current_ = ranges::find_if(std::move(++__current_), ranges::end(__parent_->__base_), std::ref(*__parent_->__pred_)); return *this; @@ -164,42 +176,42 @@ _LIBCPP_HIDE_FROM_ABI constexpr void operator++(int) { ++*this; } _LIBCPP_HIDE_FROM_ABI - constexpr __iterator operator++(int) requires forward_range<_View> { + constexpr __filter_view_iterator operator++(int) requires forward_range<_View> { auto __tmp = *this; ++*this; return __tmp; } _LIBCPP_HIDE_FROM_ABI - constexpr __iterator& operator--() requires bidirectional_range<_View> { + constexpr __filter_view_iterator& operator--() requires bidirectional_range<_View> { do { --__current_; } while (!std::invoke(*__parent_->__pred_, *__current_)); return *this; } _LIBCPP_HIDE_FROM_ABI - constexpr __iterator operator--(int) requires bidirectional_range<_View> { + constexpr __filter_view_iterator operator--(int) requires bidirectional_range<_View> { auto tmp = *this; --*this; return tmp; } _LIBCPP_HIDE_FROM_ABI - friend constexpr bool operator==(__iterator const& __x, __iterator const& __y) + friend constexpr bool operator==(__filter_view_iterator const& __x, __filter_view_iterator const& __y) requires equality_comparable> { return __x.__current_ == __y.__current_; } _LIBCPP_HIDE_FROM_ABI - friend constexpr range_rvalue_reference_t<_View> iter_move(__iterator const& __it) + friend constexpr range_rvalue_reference_t<_View> iter_move(__filter_view_iterator const& __it) noexcept(noexcept(ranges::iter_move(__it.__current_))) { return ranges::iter_move(__it.__current_); } _LIBCPP_HIDE_FROM_ABI - friend constexpr void iter_swap(__iterator const& __x, __iterator const& __y) + friend constexpr void iter_swap(__filter_view_iterator const& __x, __filter_view_iterator const& __y) noexcept(noexcept(ranges::iter_swap(__x.__current_, __y.__current_))) requires indirectly_swappable> { @@ -209,23 +221,25 @@ template> _Pred> requires view<_View> && is_object_v<_Pred> - class filter_view<_View, _Pred>::__sentinel { + class __filter_view_sentinel { + using __filter_view = filter_view<_View, _Pred>; + public: sentinel_t<_View> __end_ = sentinel_t<_View>(); _LIBCPP_HIDE_FROM_ABI - __sentinel() = default; + __filter_view_sentinel() = default; _LIBCPP_HIDE_FROM_ABI - constexpr explicit __sentinel(filter_view& __parent) + constexpr explicit __filter_view_sentinel(__filter_view& __parent) : __end_(ranges::end(__parent.__base_)) { } _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_View> base() const { return __end_; } - _LIBCPP_HIDE_FROM_ABI - friend constexpr bool operator==(__iterator const& __x, __sentinel const& __y) { + _LIBCPP_HIDE_FROM_ABI friend constexpr bool + operator==(__filter_view_iterator<_View, _Pred> const& __x, __filter_view_sentinel const& __y) { return __x.__current_ == __y.__end_; } };