diff --git a/libcxx/include/__ranges/take_while_view.h b/libcxx/include/__ranges/take_while_view.h --- a/libcxx/include/__ranges/take_while_view.h +++ b/libcxx/include/__ranges/take_while_view.h @@ -53,11 +53,17 @@ concept __take_while_const_is_range = range && indirect_unary_predicate>; +template +class __take_while_view_sentinel; + template requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate> class take_while_view : public view_interface> { - template - class __sentinel; + template + friend class __take_while_view_sentinel; + + template + using __sentinel = __take_while_view_sentinel<_View, _Pred, _Const>; _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); _LIBCPP_NO_UNIQUE_ADDRESS __copyable_box<_Pred> __pred_; @@ -108,37 +114,37 @@ template take_while_view(_Range&&, _Pred) -> take_while_view, _Pred>; -template - requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate> -template -class take_while_view<_View, _Pred>::__sentinel { +template +class __take_while_view_sentinel { using _Base = __maybe_const<_Const, _View>; sentinel_t<_Base> __end_ = sentinel_t<_Base>(); const _Pred* __pred_ = nullptr; - friend class __sentinel; + template + friend class __take_while_view_sentinel; public: - _LIBCPP_HIDE_FROM_ABI __sentinel() = default; + _LIBCPP_HIDE_FROM_ABI __take_while_view_sentinel() = default; - _LIBCPP_HIDE_FROM_ABI constexpr explicit __sentinel(sentinel_t<_Base> __end, const _Pred* __pred) + _LIBCPP_HIDE_FROM_ABI constexpr explicit __take_while_view_sentinel(sentinel_t<_Base> __end, const _Pred* __pred) : __end_(std::move(__end)), __pred_(__pred) {} - _LIBCPP_HIDE_FROM_ABI constexpr __sentinel(__sentinel __s) + _LIBCPP_HIDE_FROM_ABI constexpr __take_while_view_sentinel(__take_while_view_sentinel<_View, _Pred, !_Const> __s) requires _Const && convertible_to, sentinel_t<_Base>> : __end_(std::move(__s.__end_)), __pred_(__s.__pred_) {} _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const iterator_t<_Base>& __x, const __sentinel& __y) { + _LIBCPP_HIDE_FROM_ABI friend constexpr bool + operator==(const iterator_t<_Base>& __x, const __take_while_view_sentinel& __y) { return __x == __y.__end_ || !std::invoke(*__y.__pred_, *__x); } template requires sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> _LIBCPP_HIDE_FROM_ABI friend constexpr bool - operator==(const iterator_t<__maybe_const<_OtherConst, _View>>& __x, const __sentinel& __y) { + operator==(const iterator_t<__maybe_const<_OtherConst, _View>>& __x, const __take_while_view_sentinel& __y) { return __x == __y.__end_ || !std::invoke(*__y.__pred_, *__x); } };