Transforming an array of int to integer_sequence
While (in C++17) std::array<T>
can't be a template parameter type, const std::array<T>&
can be. Thus, with the restriction that the array in question have static storage duration, you can write
#include<array>
#include<utility>
#include<type_traits>
#include<cstddef>
template<const auto &A,
class=std::make_index_sequence<
std::tuple_size<std::decay_t<decltype(A)>>::value>>
struct as_sequence;
template<const auto &A,std::size_t ...II>
struct as_sequence<A,std::index_sequence<II...>> {
using type=std::integer_sequence<
typename std::decay_t<decltype(A)>::value_type,A[II]...>;
};
constexpr std::array<int, 5> x = {0, 3, 4, 5, 8};
static_assert(std::is_same_v<as_sequence<x>::type,
std::integer_sequence<int, 0, 3, 4, 5, 8>>);
which works on every modern compiler.