Skip to content

Commit 95412b9

Browse files
committed
iterator: operator-(iterator, iterator) <cleanup>
1 parent 59d7c14 commit 95412b9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

libcxx/include/__ranges/cartesian_product_view.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,7 @@ class cartesian_product_view<First, Vs...>::iterator {
297297

298298
template <class Tuple>
299299
constexpr difference_type distance_from(const Tuple& t) const {
300-
constexpr auto seq = std::make_integer_sequence<int, sizeof...(Vs) + 1>{};
301-
constexpr auto scaled_sum = [&t, this]<int... Ints>(std::integer_sequence<int, Ints...>) -> difference_type {
302-
return (scaled_distance<Ints>(t) + ...);
303-
};
304-
return scaled_sum(seq);
300+
return scaled_sum(t);
305301
}
306302

307303
template <auto N>
@@ -311,10 +307,17 @@ class cartesian_product_view<First, Vs...>::iterator {
311307
return static_cast<difference_type>(1);
312308
}
313309

314-
template <auto N, class Tuple>
315-
constexpr difference_type scaled_distance(const Tuple& t) const {
310+
template <auto N>
311+
constexpr difference_type scaled_distance(const auto& t) const {
316312
return static_cast<difference_type>(std::get<N>(current_) - std::get<N>(t)) * scaled_size<N + 1>();
317313
}
314+
315+
template <auto N = 0>
316+
constexpr difference_type scaled_sum(const auto& t) const {
317+
if constexpr (N <= sizeof...(Vs))
318+
return scaled_distance<N>(t) + scaled_sum<N + 1>(t);
319+
return static_cast<difference_type>(0);
320+
}
318321
};
319322

320323
} // namespace ranges

0 commit comments

Comments
 (0)