Inspired by this post https://stackoverflow.com/a/6730362 I'm trying to set up a compile-time Sequence of similar (integral) types that may be stored in ROM only using template metaprogramming. The idea is to define an array incrementally by adding elements line by line using the variadic scheme of template metaprogramming
Currently I'm here:
template<typename T, T... values> struct Seq
{
static const T value[sizeof...(values)];
static const uint16 n;
};
template<typename T, T... values> const T Seq<T, values...>::value[] = { values };
template<typename T, T... values> const uint16 Seq<T, values...>::n = sizeof...(values);
template<sint32 idx, typename T, T... values> struct IncSeq;
template<sint32 idx, typename T, T... values> struct IncSeq<-1, T, values...> : Seq<T, values...> {};
I'm fairly new to template metaprogramming. So I basically have no clue what I'm doing here. But the VS-compiler complains about some partial specialization issues:
'idx' : template parameter not used or deducible in partial specialization 'IncSeq<-1,T,values...>'
Can you help me out here? Why isn't it deducible? I wrote '-1'!
the ovedrall idea is to have index variable decrement during each call until -1 is reached which causes the IncSeq to inherit from Seq using the provided types. Usage like so:
template<sint32 idx, typename T, T... values> struct IncSeq<0, uint8, values...> : IncSeq<-1, uint8, 42, values..>{};
template<sint32 idx, typename T, T... values> struct IncSeq<1, uint8, values...> : IncSeq<0, uint8, 43, values..>{};
template<sint32 idx, typename T, T... values> struct IncSeq<2, uint8, values...> : IncSeq<1, uint8, 44, values..>{};
typedef IncSeq<2, uint8> myStaticArray;
I realize this looks like a lot of hazzle but the idea of having an array in ROM being constructed line by line in source code may pose some advantages to some of us.