Let's assume, I have some sequence, e.g. Fibonacci numbers, defined as a template:
template <unsigned int N> struct Fibonacci { unsigned int value = /*...*/; };
What I need is to obtain constexpr array with the first N elements of this sequence. I can do it, using variadic template:
template <unsigned int ... Numbers>
struct FibArray
{
static constexpr array<unsigned int, sizeof...(Numbers)> value = { Fibonacci<Numbers>::value... };
};
// and then:
const auto fib_array = FibArray<1, 2, 3, 4, 5, 6, 7>::value;
Is it possible, to avoid manual enumeration of indexes, and get the same array with just a number of required values? Something like this:
const array<unsigned, 7> fib_array = GetFirstNFibValues<7>::value;