end() requires ((!__detail::__simple_view<_First> || ... || !__detail::__simple_view<_Vs>)
&& __detail::__cartesian_product_is_common<_First, _Vs...>)
{
- bool __empty_tail = [this]<size_t... _Is>(index_sequence<_Is...>) {
- return (ranges::empty(std::get<1 + _Is>(_M_bases)) || ...);
+ auto __its = [this]<size_t... _Is>(index_sequence<_Is...>) {
+ using _Ret = __detail::__tuple_or_pair_t<iterator_t<_First>,
+ iterator_t<_Vs>...>;
+ bool __empty_tail = (ranges::empty(std::get<1 + _Is>(_M_bases)) || ...);
+ auto& __first = std::get<0>(_M_bases);
+ return _Ret{(__empty_tail
+ ? ranges::begin(__first)
+ : __detail::__cartesian_common_arg_end(__first)),
+ ranges::begin(std::get<1 + _Is>(_M_bases))...};
}(make_index_sequence<sizeof...(_Vs)>{});
- auto __it = __detail::__tuple_transform(ranges::begin, _M_bases);
- if (!__empty_tail)
- std::get<0>(__it) = __detail::__cartesian_common_arg_end(std::get<0>(_M_bases));
- return _Iterator<false>{*this, std::move(__it)};
+ return _Iterator<false>{*this, std::move(__its)};
}
constexpr _Iterator<true>
end() const requires __detail::__cartesian_product_is_common<const _First, const _Vs...>
{
- bool __empty_tail = [this]<size_t... _Is>(index_sequence<_Is...>) {
- return (ranges::empty(std::get<1 + _Is>(_M_bases)) || ...);
+ auto __its = [this]<size_t... _Is>(index_sequence<_Is...>) {
+ using _Ret = __detail::__tuple_or_pair_t<iterator_t<const _First>,
+ iterator_t<const _Vs>...>;
+ bool __empty_tail = (ranges::empty(std::get<1 + _Is>(_M_bases)) || ...);
+ auto& __first = std::get<0>(_M_bases);
+ return _Ret{(__empty_tail
+ ? ranges::begin(__first)
+ : __detail::__cartesian_common_arg_end(__first)),
+ ranges::begin(std::get<1 + _Is>(_M_bases))...};
}(make_index_sequence<sizeof...(_Vs)>{});
- auto __it = __detail::__tuple_transform(ranges::begin, _M_bases);
- if (!__empty_tail)
- std::get<0>(__it) = __detail::__cartesian_common_arg_end(std::get<0>(_M_bases));
- return _Iterator<true>{*this, std::move(__it)};
+ return _Iterator<true>{*this, std::move(__its)};
}
constexpr default_sentinel_t
#include <ranges>
#include <algorithm>
+#include <sstream>
#include <testsuite_hooks.h>
#include <testsuite_iterators.h>
return true;
}
+void
+test07()
+{
+ // PR libstdc++/107572
+ static std::istringstream ints("0 1 2 3 4");
+ struct istream_range {
+ auto begin() { return std::istream_iterator<int>{ints}; }
+ auto end() { return std::istream_iterator<int>{}; }
+ using iterator_concept = std::input_iterator_tag;
+ };
+ static_assert(!ranges::forward_range<istream_range>
+ && ranges::common_range<istream_range>);
+ istream_range r;
+ int i = 0;
+ for (auto [v] : views::cartesian_product(r))
+ {
+ VERIFY( v == i );
+ ++i;
+ };
+ VERIFY( i == 5 );
+}
+
int
main()
{
test04();
test05();
static_assert(test06());
+ test07();
}