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_
17#include "arene/base/detail/index_permutation_range.hpp"
18#include "arene/base/stdlib_choice/cstddef.hpp"
19#include "arene/base/stdlib_choice/ignore.hpp"
20#include "arene/base/stdlib_choice/initializer_list.hpp"
21#include "arene/base/stdlib_choice/integer_sequence.hpp"
22#include "arene/base/stdlib_choice/multiplies.hpp"
33namespace cartesian_product_detail {
40 sizeof...(Sizes) == 0U
43 std::initializer_list<std::
size_t>{Sizes...},
53template <
class B
idirectionalIterator>
54constexpr auto reverse(BidirectionalIterator first, BidirectionalIterator last)
noexcept ->
void {
55 while (first != last && first != --last) {
56 arene::base::iter_swap(first, last);
65constexpr auto all_index_permutations_impl() noexcept
66 -> arene::base::array<arene::base::array<std::
size_t, sizeof...(Sizes)>, permutation_space_size_v<Sizes...>> {
67 using permutation = arene::base::array<
std::size_t,
sizeof...(Sizes)>;
70 auto reversed_values = arene::base::array<
std::size_t,
sizeof...(Sizes)>{Sizes...};
72 reverse(reversed_values.begin(), reversed_values.end());
74 arene::base::array<permutation, permutation_space_size_v<Sizes...>> permutations{};
75 auto perm_itr = permutations.begin();
76 for (
auto& perm : arene::base::detail::make_index_permutation_range(reversed_values)) {
86constexpr arene::base::array<arene::base::array<
std::size_t,
sizeof...(Sizes)>, permutation_space_size_v<Sizes...>>
87 all_index_permutations_v{all_index_permutations_impl<Sizes...>()};
93template <
template <
class...>
class InnerTemplate,
std::size_t PermIndex,
class... Ln>
94class nth_type_permutation {
100 static constexpr arene::base::array<
std::size_t,
sizeof...(Ln)>
const& index_permutation{
101 all_index_permutations_v<size_v<Ln>...>[PermIndex]
112 -> InnerTemplate<at_t<Ln, index_permutation[TypeListIndices]>...>;
124template <
template <
class...>
class InnerTemplate,
std::size_t PermIndex,
class... Ln>
125using nth_type_permutation_t =
typename nth_type_permutation<InnerTemplate, PermIndex, Ln...>::type;
139struct all_type_permutations;
153struct all_type_permutations<OuterTemplate, InnerTemplate, std::
index_sequence<PermIndices...>, Ln...> {
155 using type = OuterTemplate<nth_type_permutation_t<InnerTemplate, PermIndices, Ln...>...>;
160template <
class... Ln>
161struct get_first_list_template {
164 template <
class... Types>
165 using type = arene::base::type_list<Types...>;
172template <
template <
class...>
class FirstInnerTemplate,
class... Ts,
class... RemainingLists>
173struct get_first_list_template<FirstInnerTemplate<Ts...>, RemainingLists...> {
176 template <
class... Types>
177 using type = FirstInnerTemplate<Types...>;
190template <
class... Ln>
192 cartesian_product_detail::get_first_list_template<Ln...>::template type,
193 cartesian_product_detail::get_first_list_template<Ln...>::template type,
205template <
class... Ln>
218template <
template <
class...>
class DesiredInnerTemplate,
class... Ln>
220 cartesian_product_detail::get_first_list_template<Ln...>::template type,
221 DesiredInnerTemplate,
235template <
template <
class...>
class DesiredInnerTemplate,
class... Ln>
Definition apply_all.hpp:14
arene::base::type_lists::size_detail::size_impl< L0 > size_t
Get the size of the type list.
Definition size.hpp:101
typename cartesian_product< Ln... >::type cartesian_product_t
Produce the cartesian product of multiple type-lists.
Definition cartesian_product.hpp:206
cartesian_product_detail::all_type_permutations< cartesian_product_detail::get_first_list_template< Ln... >::template type, DesiredInnerTemplate, std::make_index_sequence< cartesian_product_detail::permutation_space_size_v< size_v< Ln >... > >, Ln... > cartesian_product_as
The cartesian product of multiple type-lists, with each combination of types bound to DesiredInnerTem...
Definition cartesian_product.hpp:219
cartesian_product_detail::all_type_permutations< cartesian_product_detail::get_first_list_template< Ln... >::template type, cartesian_product_detail::get_first_list_template< Ln... >::template type, std::make_index_sequence< cartesian_product_detail::permutation_space_size_v< size_v< Ln >... > >, Ln... > cartesian_product
Produce the cartesian product of multiple type-lists.
Definition cartesian_product.hpp:191
typename cartesian_product_as< DesiredInnerTemplate, Ln... >::type cartesian_product_as_t
The cartesian product of multiple type-lists, with each combination of types bound to DesiredInnerTem...
Definition cartesian_product.hpp:236
Definition accumulate.hpp:37
constexpr auto copy(InputIterator first, InputIterator last, OutputIterator output) noexcept(noexcept(*(++output)) &&noexcept(*(++first)) &&noexcept(first !=last) &&std::is_nothrow_assignable<, typename std::iterator_traits< InputIterator >::reference >::value) -> OutputIterator
Copies the elements in the range, defined by [first, last), to another range beginning at output.
Definition copy.hpp:40
Definition accumulate.hpp:36
make_integer_sequence< size_t, Size > make_index_sequence
A helper alias template for make_integer_sequence<size_t, Size>
Definition integer_sequence.hpp:224
integer_sequence< size_t, Ints... > index_sequence
A helper alias template for integer_sequence<size_t, Ints>
Definition integer_sequence.hpp:218
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
static constexpr auto const & ignore
An object to which anything can be assigned, which ignores the assigned value.
Definition ignore.hpp:72
make_index_sequence< sizeof...(Types)> index_sequence_for
A helper alias template convert any type parameter pack into an index sequence of the same length.
Definition integer_sequence.hpp:230