Skip to content

Commit e5ebd79

Browse files
committed
views::cartesian_product + test
1 parent f79867a commit e5ebd79

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

libcxx/include/__ranges/cartesian_product_view.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,22 @@ class cartesian_product_view<First, Vs...>::iterator {
450450
}
451451
};
452452

453+
namespace views {
454+
namespace __cartesian_product {
455+
struct __fn {
456+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()() { return views::single(tuple()); }
457+
458+
template <class... _Ranges>
459+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ranges&&... __rs)
460+
-> decltype(cartesian_product_view<all_t<_Ranges&&>...>(std::forward<_Ranges>(__rs)...)) {
461+
return cartesian_product_view<all_t<_Ranges>...>(std::forward<_Ranges>(__rs)...);
462+
}
463+
};
464+
} // namespace __cartesian_product
465+
inline namespace __cpo {
466+
inline constexpr auto cartesian_product = __cartesian_product::__fn{};
467+
} // namespace __cpo
468+
} // namespace views
453469
} // namespace ranges
454470

455471
_LIBCPP_END_NAMESPACE_STD

libcxx/test/std/ranges/range.adaptors/range.cartesian.product.view/example_from_std.pass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ constexpr bool test() {
2828

2929
const std::vector<int> v{0, 1, 2};
3030
ConstexprStringStream out;
31-
// fixme: replace by views::cartesian_product
32-
for (auto&& [a, b, c] : std::ranges::cartesian_product_view(v, v, v)) {
31+
for (auto&& [a, b, c] : std::ranges::views::cartesian_product(v, v, v)) {
3332
out << a << ' ' << b << ' ' << c << '\n';
3433
}
3534

0 commit comments

Comments
 (0)