Skip to content

Commit 2c74927

Browse files
fix bug and add test
1 parent 8b6a060 commit 2c74927

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

libcxx/include/__ranges/concat_view.h

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -421,29 +421,22 @@ class concat_view<_Views...>::__iterator : public __concat_view_iterator_categor
421421
!__it_.valueless_by_exception(), "Trying to increment a valueless iterator of concat_view.");
422422
size_t __active_index = __it_.index();
423423
if (__n > 0) {
424-
__variant_detail::__visitation::__variant::__visit_value(
425-
[&](auto& __active_it) {
426-
__apply_at_index<tuple_size_v<decltype(__parent_->__views_)>>(__active_index, [&](auto __index_constant) {
427-
constexpr size_t __i = __index_constant.value;
428-
auto& __active_view = std::get<__i>(__parent_->__views_);
429-
difference_type __idx = __active_it - ranges::begin(__active_view);
430-
__advance_fwd<__i>(__idx, __n);
431-
});
432-
},
433-
__it_);
424+
__apply_at_index<tuple_size_v<decltype(__parent_->__views_)>>(__active_index, [&](auto __index_constant) {
425+
constexpr size_t __i = __index_constant.value;
426+
auto& __active_view = std::get<__i>(__parent_->__views_);
427+
difference_type __idx = std::get<__i>(__it_) - ranges::begin(__active_view);
428+
__advance_fwd<__i>(__idx, __n);
429+
});
430+
434431
}
435432

436433
else if (__n < 0) {
437-
__variant_detail::__visitation::__variant::__visit_value(
438-
[&](auto& __active_it) {
439-
__apply_at_index<tuple_size_v<decltype(__parent_->__views_)>>(__active_index, [&](auto __index_constant) {
440-
constexpr size_t __i = __index_constant.value;
441-
auto& __active_view = std::get<__i>(__parent_->__views_);
442-
difference_type __idx = __active_it - ranges::begin(__active_view);
443-
__advance_bwd<__i>(__idx, -__n);
444-
});
445-
},
446-
__it_);
434+
__apply_at_index<tuple_size_v<decltype(__parent_->__views_)>>(__active_index, [&](auto __index_constant) {
435+
constexpr size_t __i = __index_constant.value;
436+
auto& __active_view = std::get<__i>(__parent_->__views_);
437+
difference_type __idx = std::get<__i>(__it_) - ranges::begin(__active_view);
438+
__advance_bwd<__i>(__idx, -__n);
439+
});
447440
}
448441

449442
return *this;

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/decrement.pass.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,32 @@ constexpr bool test() {
194194
assert(*it == a.back());
195195
}
196196

197+
// Different range types
198+
{
199+
std::span<const int> sa{a};
200+
auto sb = std::ranges::subrange{b.begin(), b.end()};
201+
std::array<int, 2> c{9, 10};
202+
203+
auto v = std::views::concat(sa, sb, c);
204+
205+
auto it = v.begin();
206+
std::ranges::advance(it, sa.size());
207+
--it;
208+
assert(*it == a.back());
209+
210+
auto it2 = v.begin();
211+
std::ranges::advance(it2, sa.size() + sb.size());
212+
--it2;
213+
assert(*it2 == b.back());
214+
215+
// const-iterator.
216+
const auto& cv = v;
217+
auto cit = cv.begin();
218+
std::ranges::advance(cit, sa.size() + sb.size());
219+
--cit;
220+
assert(*cit == b.back());
221+
}
222+
197223
return true;
198224
}
199225

0 commit comments

Comments
 (0)