title: Uses for cpp struct variables passed in templates
body: <p>I just want to ask if there are any uses for passing variables in cpp as template arguments</p>
  <pre><code>template&lt;int a&gt; struct foo {
      int x = a;
  };
  
  int main() {
      foo&lt;2&gt; bar;
      std::cout &lt;&lt; bar.x;
  }
  </code></pre>
  <p>Something like this compiles, works and <code>cout</code>'s 2 but the same thing can be done by doing</p>
  <pre><code>struct foo {
      int x;
      foo(int a) : x(a) {}
  };
  
  int main() {
      foo bar(2);
      std::cout &lt;&lt; bar.x;
  }
  </code></pre>
  <p>So what is the point of using variables in template arguments? I can also see a big flaw in using the first method: the variable <code>a</code> uses memory and isn't destructed after <code>x</code> is changed, as it would be after the constructor is called in the second example. It might be helpful if you showed some reasonable uses for that.</p>