I want to loop over a "list of typenames" and look at all combinations of them. I was thinking of using a tuple for this, compare:
template<typename T, typename R>
void foo() {
std::cout << std::numeric_limits<T>::max() << ", " << std::numeric_limits<R>::max();
}
void call() {
using int_types = std::tuple<int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t>;
constexpr auto indizes = std::make_integer_sequence<size_t, 8>();
for (auto i: indizes) {
using T = std::tuple_element_t<i, int_types>;
for (auto j: indizes) {
using R = std::tuple_element_t<j, int_types>;
foo<T, R>();
}
}
}
Of course for loops are not consteval, thus this approach does not work. I think it might work using recursion or some consteval stuff from the STL but I can’t quite figure it out.
>Solution :
You can expand pack that way
using int_types = std::tuple<int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t>;
[]<typename... Ts>(std::tuple<Ts...>){
([]<typename T, typename... Us>(std::type_identity<T>, std::tuple<Us...>){
(foo<T, Us>(), ...);
}(std::type_identity<Ts>{}, int_types{}), ...);
}(int_types{});