title: How to static_assert the size of a std::array member
body: <p>I would like to be explicit about array size restrictions on a member variable, to stop others from accidentally making silly changes.  The following naive attempt will not compile:</p>
  
  <pre><code>struct Foo
  {
      std::array&lt; int, 1024 &gt; some_array;
      static_assert( (some_array.size() % 256) == 0, "Size must be multiple of 256" );
      //^ (clang) error: invalid use of non-static data member 'some_array'
  };
  </code></pre>
  
  <p>Even though <code>std::array::size</code> is a <em>constexpr</em>, I can't directly use <code>static_assert</code> like that because neither the function nor my member variable is static.</p>
  
  <p>The solution I came up with is to use <code>decltype</code> (since I don't want to typedef the array) as follows:</p>
  
  <pre><code>static_assert( (decltype(some_array)().size() % 256) == 0, "Size must be multiple of 256" );
  </code></pre>
  
  <p>This looks like it's default-constructing an <em>rvalue</em>, which I didn't think is a <em>constexpr</em>.</p>
  
  <p>Why does this work?</p>
  
  <p>Is there a cleaner way to achieve the static assertion?</p>