Declare member variables from variadic template parameter : <p>Obviously the code below doesn't compile in C++. But I have a case where I'd like to parameterize a class with zero or more data items based on template parameters.</p>

<p>Is there any way I can declare a class whose data members depend on variadic template parameters so I can access each of them? or some other way to achieve what I'd like?</p>

<p>This came up in a real program which I've solved an entirely different way but now I'm interested in the more abstract problem of how I might have done this.</p>

<pre><code>template &lt;typename... Types&gt; class Data
{
    // Declare a variable of each type in the parameter pack
    // This is NOT valid C++ and won't compile...
    Types... items;
};

struct Item1
{
    int a;
};

struct Item2
{
    float x, y, z;
};

struct Item3
{
    std::string name;
}

int main()
{
    Data&lt;Item1, Item2&gt; data1;
    Data&lt;Item3&gt; data2;
}
</code></pre>
