Is it possible to create a static const
array with values from template parameter pack?
I tried the following code, but gcc 4.8.1 gives "error: parameter packs not expanded"
template<int... N>
struct ARRAY_OF_DIMS
{
static constexpr size_t NDIM = sizeof...(N);
static const int DIMS[NDIM];
};
template<int... N>
const int ARRAY_OF_DIMS<N>::DIMS[ARRAY_OF_DIMS<N>::NDIM] = { N... };
Try with:
template<int... N>
const int ARRAY_OF_DIMS<N...>::DIMS[ARRAY_OF_DIMS<N...>::NDIM] = { N... };
The parameter pack in ARRAY_OF_DIMS<N>
is the one that is not being expanded. Every parameter pack that is not an argument to sizeof...
has to be expanded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With