8

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... };
1
  • 2
    If the solution is indeed correct you should mark it so (the check mark next to his answer). Also consider marking answers to some of your other answers correct if there are correct answers. Commented Jun 11, 2013 at 16:27

1 Answer 1

14

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.