title: C++: Can I have non-static member variable templates?
body: <p>I'm trying to write a bit of code that requires me to have a lot of <code>std::array</code>s in a container class. These arrays are all of varying sizes (all consecutive from 2-16, if that matters), and there is exactly one of each size. I want to put them in a container class, and be able to access them with templates.</p>
  
  <p>It's probably easier to explain with code. I want something like this:</p>
  
  <pre><code>class ContainerClass {
  
  public:
     // I want to declare some number of arrays right here, all of different
     // sizes, ranging from 2-16. I'd like to be able to access them as
     // arr&lt;2&gt; through arr&lt;16&gt;.
  
     // This code gives a compiler error, understandably. 
     // But this is what I'd think it'd look like.
     template &lt;size_t N&gt; // I also need to find a way to restrict N to 2 through 16.
     std::array&lt;int, N&gt; arr;
  
     // An example method of how I want to be able to use this.
     template &lt;size_t N&gt;
     void printOutArr() {
         for (int i = 0; i &lt; N; i++) {
             std::cout &lt;&lt; arr&lt;N&gt;[i] &lt;&lt; std::endl;
         }
     }
  };
  </code></pre>
  
  <p>I'd like the code to expand out as if it just had 15 arrays in it, from 2-16. Like this, but with templates:</p>
  
  <pre><code>class ContainerClass {
  
  public:
      std::array&lt;int, 2&gt; arr2;
      std::array&lt;int, 3&gt; arr3;
      std::array&lt;int, 4&gt; arr4;
      std::array&lt;int, 5&gt; arr5;
     // ... and so on.
  };
  </code></pre>
  
  <p>From what I understand, C++ supports variable templates, but it seems like it's only for static members in classes. Is there an alternative that could behave similarly (preferably with as little overhead as possible)?</p>
  
  <p>If you need more information, please ask.</p>
  
  <p>Thanks in advance.</p>