title: Small Buffer Optimization and alignment
body: <p>I am writing a <em>C++</em> wrapper around a legacy API. This API provides me with a pointer value to keep extra data, and I want to implement the <em>Small Buffer Optimization</em> with it.</p>
  
  <p>I have implemented an <code>is_small_pod</code> <em>metafunction</em> that checks whether a given type is <em>POD</em> and it fits within a <code>void*</code>:</p>
  
  <pre><code>template&lt; typename Type &gt;
  struct is_small_pod
    : std::integral_constant&lt;
          bool
        , std::is_pod&lt; Type &gt;::type::value
          &amp;&amp; sizeof( Type ) &lt;= sizeof( void* )
      &gt;
  {};
  </code></pre>
  
  <p>and I'm setting the value like this:</p>
  
  <pre><code>// void*&amp; param;
  if( detail::is_small_pod&lt; Type &gt;() )
  {
      *static_cast&lt; Type* &gt;( &amp;param ) = value;
  } else {
      param = new Type( value );
  }
  </code></pre>
  
  <p>Am I implementing this optimization correctly? I believe this will fail when the value alignment is not compatible with the <em>alignment</em> of a pointer (odd corner case as it may be). Is that situation even possible, or am I just overthinking it? How should I extend my <em>metafunction</em> to check for compatible <em>alignment</em> as well?</p>