I need to know how many items in parameter pack of a variadic templete.
my code:
#include <iostream>
using namespace std;
template <int... Entries>
struct StaticArray
{
int size = sizeof... (Entries);// line A
//int array[size] = {Entries...};// line B
};
int main()
{
StaticArray<1,2,3,4> sa;
cout << sa.size << endl;
return 0;
}
I got compilation error on line A.
if change this line to
static const unsigned short int size = sizeof...(Arguments)
It can be compiled. my first question is why I need "static const unsigned short" to get compiled. as you can see, I need a size to put in on my array. my final goal is able to print this array out in main function.
please help. thanks.. my ideal comes from this website but i dont know how to make it works http://thenewcpp.wordpress.com/2011/11/23/variadic-templates-part-1-2/