This gives the new split_view's sentinel type a defaulted default constructor, something which was overlooked in r12-1665. This patch also fixes a couple of other issues with the new split_view as reported in the PR.
Tested on x86_64-pc-linux-gnu, does this look OK for trunk? PR libstdc++/101214 libstdc++-v3/ChangeLog: * include/std/ranges (split_view::split_view): Use std::move. (split_view::_Iterator::_Iterator): Remove redundant default_initializable constraint. (split_view::_Sentinel::_Sentinel): Declare. * testsuite/std/ranges/adaptors/split.cc (test02): New test. --- libstdc++-v3/include/std/ranges | 6 ++++-- libstdc++-v3/testsuite/std/ranges/adaptors/split.cc | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index f552caa9d5b..df74ac9dc19 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -3306,7 +3306,7 @@ namespace views::__adaptor && constructible_from<_Pattern, single_view<range_value_t<_Range>>> constexpr split_view(_Range&& __r, range_value_t<_Range> __e) - : _M_pattern(views::single(__e)), + : _M_pattern(views::single(std::move(__e))), _M_base(views::all(std::forward<_Range>(__r))) { } @@ -3364,7 +3364,7 @@ namespace views::__adaptor using value_type = subrange<iterator_t<_Vp>>; using difference_type = range_difference_t<_Vp>; - _Iterator() requires default_initializable<iterator_t<_Vp>> = default; + _Iterator() = default; constexpr _Iterator(split_view* __parent, @@ -3429,6 +3429,8 @@ namespace views::__adaptor { return __x._M_cur == _M_end && !__x._M_trailing_empty; } public: + _Sentinel() = default; + constexpr explicit _Sentinel(split_view* __parent) : _M_end(ranges::end(__parent->_M_base)) diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc index 02c6073a503..b4e01fea6e4 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc @@ -46,6 +46,16 @@ test01() VERIFY( ranges::equal(ints, (int[]){1,2,3,4}) ); } +void +test02() +{ + // PR libstdc++/101214 + auto v = views::iota(0) | views::take(5) | views::split(0); + static_assert(!ranges::common_range<decltype(v)>); + static_assert(std::default_initializable<decltype(v.end())>); + static_assert(std::sentinel_for<decltype(v.end()), decltype(v.begin())>); +} + // The following testcases are adapted from lazy_split.cc. namespace from_lazy_split_cc { @@ -189,6 +199,7 @@ int main() { test01(); + test02(); from_lazy_split_cc::test01(); from_lazy_split_cc::test02(); -- 2.32.0.170.gd486ca60a5