title: How do I best force-flatten a (one dimensional) vector for N values?
body: <p>I need something that behaves like an <code>std::vector</code> (interface/features/etc.) but I need it to be flat, i.e. it mustn't dynamically allocate a buffer. Clearly, this doesn't work in general, as the available size must be determined at compile time. But I want the type to be able to deal with <code>N</code> objects without additional allocations, and <strong>only if further items are pushed</strong> resort to dynamic allocation.</p>
  
  <p>Some implementations of <code>std::vector</code> already do this, but only to the extent that it uses its existing members if the accumulated size of the content fits (I believe about three pointers-worth of payload). So, <strong>firstly</strong>, this is not a guarantee and <strong>secondly</strong> it is not configurable at compile time.</p>
  
  <p>My thoughts are that I could either</p>
  
  <ul>
  <li><strong>A)</strong> self-cook a type (probably bad because I'd loose the ridiculous performance optimisations from <code>vector</code>)</li>
  <li><strong>B)</strong> use some sort of <code>variant&lt;vector&lt;T&gt;,array&lt;T,N&gt;&gt;</code> with an access wrapper (oh, the boilerplate)</li>
  <li><strong>C)</strong> come up with a <code>MyAllocator&lt;T,N&gt;</code> that has an <code>array&lt;T,N&gt;</code> member which then may be used to hold the first <code>N</code> items and after this defer to <code>allocator&lt;T&gt;</code> but I'm not sure if this can work because I cannot find out whether <code>vector</code> must permanently hold an instance of its allocator type as a member (I believe it does not)</li>
  </ul>
  
  <p>I figure I'm not the first person to want this, so perhaps there are already approaches to this? Some empirical values or perhaps even a free library?</p>