title: Proper initialization of static constexpr array in class template?
body: <p>Static class members in C++ have caused a little confusion for me due to the standard's verbiage:</p>
  <blockquote>
  <p><em>9.4.2  Static data members</em> <strong>[class.static.data]</strong></p>
  <p>The declaration of a static data member in its class definition is not a  definition...</p>
  </blockquote>
  <p>However a <em>constexpr</em> is required to be initialized (AFAIK, couldn't find a quote from the standard) at its declaration (e.g., in the class definition).</p>
  <p>Because of the restrictions on constexpr I had actually forgotten about the requisite for static members to be defined outside of the class, until I tried accessing a static constexpr array. <a href="https://stackoverflow.com/questions/8016780/undefined-reference-to-static-constexpr-char">This related question</a> provides the correct way of defining the array member, but I'm interested as to the implications on this definition in a class template.</p>
  <p>This is what I ended up with:</p>
  <pre><code>template&lt;typename T&gt;
  class MyClass
  {
  private:
    static constexpr std::size_t _lut[256] = { /* ... */ };
    T _data;
  
  public:
    static constexpr std::size_t GetValue(std::size_t n) noexcept
    {
      return _lut[n &amp; 255];
    }
  
    // ...
  };
  
  template&lt;typename T&gt;
  constexpr std::size_t MyClass&lt;T&gt;::_lut[256];
  </code></pre>
  <p><strong>Is this the right syntax?</strong> Particularly the use of template in the definition feels awkward, but GCC seems to be linking everything appropriately.</p>
  <p>As a follow-up question, should non-array static constexpr members be similarly defined (with template definition outside of class)?</p>