diff --git a/include/flux/op/cartesian_product.hpp b/include/flux/op/cartesian_product.hpp index 30fa79c6..c40a22e0 100644 --- a/include/flux/op/cartesian_product.hpp +++ b/include/flux/op/cartesian_product.hpp @@ -209,21 +209,6 @@ struct cartesian_product_traits_base { } }; -template -struct cartesian_product_tuple_drop_impl; - -template -struct cartesian_product_tuple_drop_impl> { - using type = std::tuple...>; -}; - -template -using cartesian_product_tuple_drop = - typename cartesian_product_tuple_drop_impl - I>>::type; - -template -using cartesian_product_partial_cursor_t = cartesian_product_tuple_drop, I>; - } // end namespace detail template @@ -248,32 +233,28 @@ struct sequence_traits> template - static constexpr auto for_each_while_impl(Self& self, + static constexpr void for_each_while_impl(Self& self, + bool& keep_going, + cursor_t& cur, Function&& func, PartialElements&&... partial_elements) - -> std::tuple> { // We need to iterate right to left. if constexpr (I == sizeof...(Bases) - 1) { - bool keep_going = true; - auto this_current = flux::for_each_while(std::get(self.bases_), + std::get(cur) = flux::for_each_while(std::get(self.bases_), [&](auto&& elem) { keep_going = std::invoke(func, element_t(FLUX_FWD(partial_elements)..., FLUX_FWD(elem))); return keep_going; }); - return std::tuple(keep_going, std::tuple(std::move(this_current))); } else { - bool keep_going = true; - detail::cartesian_product_partial_cursor_t nested_current; - auto this_current = flux::for_each_while(std::get(self.bases_), + std::get(cur) = flux::for_each_while(std::get(self.bases_), [&](auto&& elem) { - std::tie(keep_going, nested_current) = for_each_while_impl( - self, func, FLUX_FWD(partial_elements)..., FLUX_FWD(elem)); + for_each_while_impl( + self, keep_going, cur, + func, FLUX_FWD(partial_elements)..., FLUX_FWD(elem)); return keep_going; }); - return std::tuple(keep_going, - std::tuple_cat(std::tuple(std::move(this_current)), std::move(nested_current))); } } @@ -308,7 +289,10 @@ struct sequence_traits> static constexpr auto for_each_while(Self& self, Function&& func) -> cursor_t { - return std::get<1>(for_each_while_impl<0>(self, FLUX_FWD(func))); + bool keep_going = true; + cursor_t cur; + for_each_while_impl<0>(self, keep_going, cur, FLUX_FWD(func)); + return cur; } };