From: Hui Date: Sat, 28 Jan 2023 14:36:56 +0000 (+0000) Subject: [libcxx][ranges] revert join_view::iterator and sentinel to be in-class X-Git-Tag: upstream/17.0.6~17847 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3b059cd25b8ce31762b76a3b172fdd811c07dc34;p=platform%2Fupstream%2Fllvm.git [libcxx][ranges] revert join_view::iterator and sentinel to be in-class --- diff --git a/libcxx/include/__ranges/join_view.h b/libcxx/include/__ranges/join_view.h index 9d56e13..7c07842 100644 --- a/libcxx/include/__ranges/join_view.h +++ b/libcxx/include/__ranges/join_view.h @@ -69,14 +69,6 @@ namespace ranges { >; }; - template - requires view<_View> && input_range> - struct __join_view_iterator; - - template - requires view<_View> && input_range> - struct __join_view_sentinel; - template requires view<_View> && input_range> class join_view @@ -84,19 +76,9 @@ namespace ranges { private: using _InnerRange = range_reference_t<_View>; - template - using __iterator = __join_view_iterator<_View, _Const>; - - template - using __sentinel = __join_view_sentinel<_View, _Const>; + template struct __iterator; - template - requires view<_View2> && input_range> - friend struct __join_view_iterator; - - template - requires view<_View2> && input_range> - friend struct __join_view_sentinel; + template struct __sentinel; template friend struct std::__segmented_iterator_traits; @@ -167,12 +149,12 @@ namespace ranges { } }; - template + template requires view<_View> && input_range> - struct __join_view_sentinel { - template - requires view<_View2> && input_range> - friend struct __join_view_sentinel; + template + struct join_view<_View>::__sentinel { + template + friend struct __sentinel; private: using _Parent = __maybe_const<_Const, join_view<_View>>; @@ -181,37 +163,42 @@ namespace ranges { public: _LIBCPP_HIDE_FROM_ABI - __join_view_sentinel() = default; + __sentinel() = default; _LIBCPP_HIDE_FROM_ABI - constexpr explicit __join_view_sentinel(_Parent& __parent) + constexpr explicit __sentinel(_Parent& __parent) : __end_(ranges::end(__parent.__base_)) {} _LIBCPP_HIDE_FROM_ABI - constexpr __join_view_sentinel(__join_view_sentinel<_View, !_Const> __s) + constexpr __sentinel(__sentinel __s) requires _Const && convertible_to, sentinel_t<_Base>> : __end_(std::move(__s.__end_)) {} template requires sentinel_for, iterator_t<__maybe_const<_OtherConst, _View>>> _LIBCPP_HIDE_FROM_ABI - friend constexpr bool operator==(const __join_view_iterator<_View, _OtherConst>& __x, const __join_view_sentinel& __y) { + friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) { return __x.__outer_ == __y.__end_; } }; - template + // https://reviews.llvm.org/D142811#inline-1383022 + // To simplify the segmented iterator traits specialization, + // make the iterator `final` + template requires view<_View> && input_range> - struct __join_view_iterator + template + struct join_view<_View>::__iterator final : public __join_view_iterator_category<__maybe_const<_Const, _View>> { - template - requires view<_View2> && input_range> - friend struct __join_view_iterator; + template + friend struct __iterator; template friend struct std::__segmented_iterator_traits; + static constexpr bool __is_join_view_iterator = true; + private: using _Parent = __maybe_const<_Const, join_view<_View>>; using _Base = __maybe_const<_Const, _View>; @@ -246,7 +233,7 @@ namespace ranges { __inner_.reset(); } - _LIBCPP_HIDE_FROM_ABI constexpr __join_view_iterator(_Parent* __parent, _Outer __outer, _Inner __inner) + _LIBCPP_HIDE_FROM_ABI constexpr __iterator(_Parent* __parent, _Outer __outer, _Inner __inner) : __outer_(std::move(__outer)), __inner_(std::move(__inner)), __parent_(__parent) {} public: @@ -267,17 +254,17 @@ namespace ranges { range_difference_t<_Base>, range_difference_t>>; _LIBCPP_HIDE_FROM_ABI - __join_view_iterator() requires default_initializable<_Outer> = default; + __iterator() requires default_initializable<_Outer> = default; _LIBCPP_HIDE_FROM_ABI - constexpr __join_view_iterator(_Parent& __parent, _Outer __outer) + constexpr __iterator(_Parent& __parent, _Outer __outer) : __outer_(std::move(__outer)) , __parent_(std::addressof(__parent)) { __satisfy(); } _LIBCPP_HIDE_FROM_ABI - constexpr __join_view_iterator(__join_view_iterator<_View, !_Const> __i) + constexpr __iterator(__iterator __i) requires _Const && convertible_to, _Outer> && convertible_to, _Inner> @@ -298,7 +285,7 @@ namespace ranges { } _LIBCPP_HIDE_FROM_ABI - constexpr __join_view_iterator& operator++() { + constexpr __iterator& operator++() { auto&& __inner = [&]() -> auto&& { if constexpr (__ref_is_glvalue) return *__outer_; @@ -318,7 +305,7 @@ namespace ranges { } _LIBCPP_HIDE_FROM_ABI - constexpr __join_view_iterator operator++(int) + constexpr __iterator operator++(int) requires __ref_is_glvalue && forward_range<_Base> && forward_range> @@ -329,7 +316,7 @@ namespace ranges { } _LIBCPP_HIDE_FROM_ABI - constexpr __join_view_iterator& operator--() + constexpr __iterator& operator--() requires __ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range> && @@ -348,7 +335,7 @@ namespace ranges { } _LIBCPP_HIDE_FROM_ABI - constexpr __join_view_iterator operator--(int) + constexpr __iterator operator--(int) requires __ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range> && @@ -360,7 +347,7 @@ namespace ranges { } _LIBCPP_HIDE_FROM_ABI - friend constexpr bool operator==(const __join_view_iterator& __x, const __join_view_iterator& __y) + friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) requires __ref_is_glvalue && equality_comparable> && equality_comparable>> @@ -369,14 +356,14 @@ namespace ranges { } _LIBCPP_HIDE_FROM_ABI - friend constexpr decltype(auto) iter_move(const __join_view_iterator& __i) + friend constexpr decltype(auto) iter_move(const __iterator& __i) noexcept(noexcept(ranges::iter_move(*__i.__inner_))) { return ranges::iter_move(*__i.__inner_); } _LIBCPP_HIDE_FROM_ABI - friend constexpr void iter_swap(const __join_view_iterator& __x, const __join_view_iterator& __y) + friend constexpr void iter_swap(const __iterator& __x, const __iterator& __y) noexcept(noexcept(ranges::iter_swap(*__x.__inner_, *__y.__inner_))) requires indirectly_swappable<_Inner> { @@ -404,12 +391,12 @@ inline namespace __cpo { } // namespace views } // namespace ranges -template - requires(ranges::common_range::_Parent> && - __is_cpp17_random_access_iterator::_Outer>::value && - __is_cpp17_random_access_iterator::_Inner>::value) -struct __segmented_iterator_traits> { - using _JoinViewIterator = ranges::__join_view_iterator<_View, _Const>; +template + requires(_JoinViewIterator::__is_join_view_iterator && + ranges::common_range && + __is_cpp17_random_access_iterator::value && + __is_cpp17_random_access_iterator::value) +struct __segmented_iterator_traits<_JoinViewIterator> { using __segment_iterator = _LIBCPP_NODEBUG __iterator_with_data; diff --git a/libcxx/test/libcxx/containers/sequences/deque/segmented_iterator.compile.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/segmented_iterator.compile.pass.cpp new file mode 100644 index 0000000..27100f9 --- /dev/null +++ b/libcxx/test/libcxx/containers/sequences/deque/segmented_iterator.compile.pass.cpp @@ -0,0 +1,13 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include + + +using DequeIterator = typename std::deque::iterator; +static_assert(std::__is_segmented_iterator::value, ""); diff --git a/libcxx/test/libcxx/ranges/range.adaptors/range.join/segmented_iterator.compile.pass.cpp b/libcxx/test/libcxx/ranges/range.adaptors/range.join/segmented_iterator.compile.pass.cpp new file mode 100644 index 0000000..08b8949 --- /dev/null +++ b/libcxx/test/libcxx/ranges/range.adaptors/range.join/segmented_iterator.compile.pass.cpp @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +#include +#include + +using JoinView = decltype(std::views::join(std::declval>&>())); +using JoinIter = std::ranges::iterator_t; +static_assert(std::__is_segmented_iterator::value);