title: Non-type template argument is not a constant expression
body: <p>I have the following code:</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;cstdio&gt;
  #include &lt;atomic&gt;
  
  enum ATYPE { Undefined = 0, typeA, typeB, typeC };
  
  template&lt;ATYPE TYPE = Undefined&gt;
  struct Object
  {
      Object() { counter++; }
      static std::atomic&lt;int&gt; counter;
  };
  
  template&lt;ATYPE TYPE&gt;
  std::atomic&lt;int&gt; Object&lt;TYPE&gt;::counter(1);
  
  template&lt;ATYPE TYPE&gt;
  void test()
  {
      printf("in test\n");
      Object&lt;TYPE&gt; o;
  }
  
  int main(int argc, char **argv)
  {
      test&lt;typeA&gt;();
      printf("%d\n", Object&lt;typeA&gt;::counter.load());
      Object&lt;typeA&gt;::counter.store(0);
      for (int i = 0; i &lt; sizeof(ATYPE); ++i) {
          Object&lt;static_cast&lt;ATYPE&gt;(i)&gt;::counter.store(0);
      }
      return 0;
  }
  </code></pre>
  
  <p>When I compile with the following command line:</p>
  
  <pre><code>clang++ -o test -std=c++11 -stdlib=libc++ test.cpp
  </code></pre>
  
  <p>I get the following errors:</p>
  
  <pre><code>test.cpp:32:20: error: non-type template argument is not a constant expression
  Object&lt;static_cast&lt;ATYPE&gt;(i)&gt;::counter.store(0);
  ^~~~~~~~~~~~~~~~~~~~~
  test.cpp:32:39: note: read of non-const variable 'i' is not allowed in a constant expression
  Object&lt;static_cast&lt;ATYPE&gt;(i)&gt;::counter.store(0);
  ^
  testray.cpp:31:18: note: declared here
  for (int i = 0; i &lt; sizeof(ATYPE); ++i) {
  </code></pre>
  
  <p>I understand the problem I believe. The argument of the template needs to be a constexpr and i clearly is not. So the question is, are they possible changes I can do to get this working. By this working, I mean, can I somehow have a better way of resetting these static counters from this template class for each type in ATYPE, other than just doing it manually:</p>
  
  <pre><code>Object&lt;Undefined&gt;::counter.store(0);
  Object&lt;typeA&gt;::counter.store(0);
  ...
  </code></pre>
  
  <p>Which is not so elegant and practical when ATYPE contains many types.</p>
  
  <p>Thanks a lot for your help and advices.</p>