6#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_CARTESIAN_PRODUCT_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_CARTESIAN_PRODUCT_HPP_
13#include "arene/base/array/array.hpp"
14#include "arene/base/iterator/next.hpp"
15#include "arene/base/stdlib_choice/cstddef.hpp"
16#include "arene/base/stdlib_choice/integer_sequence.hpp"
17#include "arene/base/type_list/at.hpp"
18#include "arene/base/type_list/size.hpp"
19#include "arene/base/type_list/type_list.hpp"
27namespace cartesian_product_detail {
34template <std::size_t Dimension>
35constexpr auto permutation_space_size_impl(arene::base::array<std::size_t, Dimension>
const& sizes)
noexcept
37 if (Dimension == 0U) {
41 std::size_t product{1U};
44 for (std::size_t idx{}; idx < sizes.size(); ++idx) {
45 product *= sizes[idx];
53template <std::size_t... Sizes>
54struct permutation_space_size {
56 static constexpr arene::base::array<std::size_t,
sizeof...(Sizes)> sizes{Sizes...};
58 static constexpr std::size_t value{permutation_space_size_impl(sizes)};
63template <std::size_t... Sizes>
64constexpr std::size_t permutation_space_size_v{permutation_space_size<Sizes...>::value};
69template <std::size_t... Sizes>
70constexpr auto all_index_permutations_impl()
noexcept
71 -> arene::base::array<arene::base::array<std::size_t,
sizeof...(Sizes)>, permutation_space_size_v<Sizes...>> {
72 using permutation = arene::base::array<std::size_t,
sizeof...(Sizes)>;
75 constexpr permutation sizes{Sizes...};
76 arene::base::array<permutation, permutation_space_size_v<Sizes...>> permutations{};
79 permutation indices{};
80 for (
auto perm_itr = arene::base::next(permutations.begin()); perm_itr < permutations.end(); ++perm_itr) {
82 indices[
sizeof...(Sizes) - 1U] += 1U;
84 auto size_itr = sizes.rbegin();
86 for (
auto idx_itr = indices.rbegin(); idx_itr != indices.rend(); ++idx_itr) {
91 if (*idx_itr == *size_itr) {
111template <std::size_t... Sizes>
112constexpr arene::base::array<arene::base::array<std::size_t,
sizeof...(Sizes)>, permutation_space_size_v<Sizes...>>
113 all_index_permutations_v{all_index_permutations_impl<Sizes...>()};
119template <
template <
class...>
class InnerTemplate, std::size_t PermIndex,
class... Ln>
120class nth_type_permutation {
124 static constexpr arene::base::array<std::size_t,
sizeof...(Ln)>
const& index_permutation{
125 all_index_permutations_v<size_v<Ln>...>[PermIndex]
134 template <std::size_t... TypeListIndices>
135 static constexpr auto deduce_type_from_permutation(std::index_sequence<TypeListIndices...>)
136 -> InnerTemplate<at_t<Ln, index_permutation[TypeListIndices]>...>;
141 using type =
decltype(deduce_type_from_permutation(std::index_sequence_for<Ln...>{}));
148template <
template <
class...>
class InnerTemplate, std::size_t PermIndex,
class... Ln>
149using nth_type_permutation_t =
typename nth_type_permutation<InnerTemplate, PermIndex, Ln...>::type;
163struct all_type_permutations;
175 std::size_t... PermIndices,
177struct all_type_permutations<OuterTemplate, InnerTemplate, std::index_sequence<PermIndices...>, Ln...> {
179 using type = OuterTemplate<nth_type_permutation_t<InnerTemplate, PermIndices, Ln...>...>;
184template <
class... Ln>
185struct get_first_list_template {
188 template <
class... Types>
189 using type = arene::base::type_list<Types...>;
196template <
template <
class...>
class FirstInnerTemplate,
class... Ts,
class... RemainingLists>
197struct get_first_list_template<FirstInnerTemplate<Ts...>, RemainingLists...> {
200 template <
class... Types>
201 using type = FirstInnerTemplate<Types...>;
214template <
class...
Ln>
229template <
class...
Ln>
Definition apply_all.hpp:14
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10