title: How to do c++ aligned array allocation?
body: <p>I'd like to modify an array allocation:</p>
  
  <pre><code> float * a = new float[n] ;
  </code></pre>
  
  <p>to use an aligned allocator.  I was inclined to try to use placement new and posix_memalign (or the new c++11 equivalent), but see that <a href="https://stackoverflow.com/questions/15254/can-placement-new-for-arrays-be-used-in-a-portable-way">placement new with arrays is problematic with array allocations</a>, because the <a href="https://stackoverflow.com/questions/8720425/array-placement-new-requires-unspecified-overhead-in-the-buffer">compiler may need to have additional storage for count or other metadata</a>.</p>
  
  <p>I tried:</p>
  
  <pre><code>int main()
  {
     float * a = new alignas(16) float[3] ;
  
     a[2] = 0.0 ;
  
     return a[2] ;
  }
  </code></pre>
  
  <p>but the compiler seems to indicate that the alignas is ignored:</p>
  
  <pre><code>$ g++ -std=c++11 t.cc -Werror
  t.cc: In function ‘int main()’:
  t.cc:4:39: error: attribute ignored [-Werror=attributes]
      float * a = new alignas(16) float[3] ;
                                         ^
  t.cc:4:39: note: an attribute that appertains to a type-specifier is ignored
  </code></pre>
  
  <p>It looks like the proper way to use alignas is in a <a href="https://stackoverflow.com/a/27517755/189270">structure declaration declare a structure with alignas</a>, but that will only work with a fixed size.</p>
  
  <p>There is also a  aligned_storage template, but I think that will also only work with fixed sizes.</p>
  
  <p>Is there any standard way to do an aligned array allocation that will invoke the constructor on all the elements?</p>