Variadic template parameters from integer
A bit another way to do - use function signature to match the A<...>
type:
#include <type_traits>
template<int ...Is>
struct A {};
namespace details
{
template <int ...Is>
auto GenrateAHelper(std::integer_sequence<int, Is...>) -> A<Is...>;
}
template<int I>
using GenerateA = decltype(details::GenrateAHelper(std::make_integer_sequence<int, I>()));
static_assert(std::is_same<GenerateA<3>, A<0, 1, 2>>::value, "");
We already have what you want in the Standard library - std::make_integer_sequence
. If you want to use your own type A<...>
you can do this:
template<int... Is>
struct A {};
template<class>
struct make_A_impl;
template<int... Is>
struct make_A_impl<std::integer_sequence<int, Is...>> {
using Type = A<Is...>;
};
template<int size>
using make_A = typename make_A_impl<std::make_integer_sequence<int, size>>::Type;
And then for A<0, ..., 2999>
write
make_A<3000>