ContainerOut carthesian_product_n(std::size_t power, const ContainerIn& xs_in) { if (power == 0) return ContainerOut(1); std::vector<T> xs = convert_container<std::vector<T>>(xs_in); auto idxs = all_idxs(xs); auto result_idxss = internal::helper_carthesian_product_n_idxs(power, idxs); typedef typename ContainerOut::value_type ContainerOutInner; auto to_result_cont = [&](const std::vector<std::size_t>& indices) { return convert_container_and_elems<ContainerOutInner>( elems_at_idxs(indices, xs)); }; return transform(to_result_cont, result_idxss); }
auto enumerate(const Container& xs) { return zip(all_idxs(xs), xs); }