title: C++1y template variables for conditional variable type and initialization
body: <p>I have <em>some</em> code that looks like this:</p>
  
  <pre><code>// filexd.h
  function() {
    // nDim is a compile time constant
    #if DIMENSIONS == 2
      static const int a[nDim] = {1,0};
    #elif DIMENSIONS == 3
      static const int a[nDim] = {2,0,1};
    #else
      #error "Unknown # of dimensions"
    #end
    // do stuff with a...
  }
  </code></pre>
  
  <p>This file is included by others that redefine the macro DIMENSIONS. What I would like to have is something like this: </p>
  
  <pre><code>static const int a[nDim] = (nDim == 2) ? {0,1} : {1,0,2};
  </code></pre>
  
  <p>I dont want to use a function template specialization or tag dispatch as 99% of the code is identical in both cases. I would like to preserve the same function composition that I already had, and the local semantics of the variable a. So the question is:</p>
  
  <p><strong>How can I avoid using macros in this situation?</strong></p>
  
  <p>Could I use C++1y template variables here? Would the following work?</p>
  
  <pre><code>// filexd.h
  function() {
  
    // The general case should fail somehow, maybe displaying a nice error message.
    template&lt;int nDim&gt; constexpr int stencil[nDim] = throw();
    // And then define the variable for both cases:
    template&lt;&gt; constexpr int stencil&lt;2&gt;[2] = {1, 0};  
    template&lt;&gt; constexpr int stencil&lt;3&gt;[3] = {2, 0, 1};
  
    static const stencil&lt;nDim&gt; a;
    for(int i = 0; i &lt; nDim; ++i) {
      /// do stuff with a[i]
    }
  }
  </code></pre>
  
  <p><strong>Could I declare the stencil template variable with its specializations inside the function itself?</strong></p>