I am trying to built compile time tables. I use arrays of arrays of arrays ... to do that. Unfortunately the compiler is not able to deduce template arguments of the resulting type. Is there a work around?
#include <array>
template <typename T, size_t... dims>
struct variadic_array;
template <typename T, size_t... dims>
using variadic_array_t = typename variadic_array<T, dims...>::type;
template <typename T, size_t dim>
struct variadic_array<T, dim> {
using type = std::array<T, dim>;
};
template <typename T, size_t dim, size_t ...dims>
struct variadic_array<T, dim, dims...> {
using type = std::array<variadic_array_t<T, dims...>, dim>;
};
template <typename T, size_t ...dims>
void foo(variadic_array_t<T, dims...>) {}
void call_foo() {
foo(variadic_array_t<int, 3, 4>{});
}
Compilation error:
error: no matching function for call to 'foo'
foo(variadic_array_t<int, 3, 4>{});
^~~
note: candidate template ignored: couldn't infer template argument 'T'
void foo(variadic_array_t<T, dims...>) {}
^