I was wondering if its possible to make the following answer more generic, in the sense that the type of the array be templated instead of just unsigned:
I've enclosed the whole thing in a struct like so:
template<typename ArrayType>
struct Array
{
template<ArrayType... args> struct ArrayHolder {
static const ArrayType data[sizeof...(args)];
};
template<ArrayType... args>
const ArrayType ArrayHolder<args...>::data[sizeof...(args)] = { args... };
template<size_t N, template<size_t> class F, ArrayType... args>
struct generate_array_impl {
typedef typename generate_array_impl<N-1, F, F<N>::value, args...>::result result;
};
template<template<size_t> class F, ArrayType... args>
struct generate_array_impl<0, F, args...> {
typedef ArrayHolder<F<0>::value, args...> result;
};
template<size_t N, template<size_t> class F>
struct generate_array {
typedef typename generate_array_impl<N-1, F>::result result;
};
};
but I get the following errors:
c++-4.6 -std=c++0x -o test test.cpp
test.cpp:49:17: error: specializing member ‘Array<ArrayType>::ArrayHolder<args>::data’ requires ‘template<>’ syntax