title: Use the right alignment for a buffer which is supposed to hold a struct in C++
body: <p>Suppose we have some struct, say</p>
  
  <pre><code>struct S
  {
    double a, b;
    ~S(); // S doesn't have to be POD
  };
  </code></pre>
  
  <p>Such a struct should typically have an alignment of 8, as the size of its largest contained type is 8.</p>
  
  <p>Now imagine we want to declare a placeholder struct to hold the value of <code>S</code>:</p>
  
  <pre><code>struct Placeholder
  {
    char bytes[ sizeof( S ) ];
  };
  </code></pre>
  
  <p>Now we want to place it inside of another class:</p>
  
  <pre><code>class User
  {
    char someChar;
    Placeholder holder;
  public:
    // Don't mind that this is hacky -- this just shows a possible use but
    // that's not the point of the question
    User() { new ( holder.bytes ) S; }
    ~User() {  ( ( S * )( holder.bytes ) )-&gt;~S(); }
  };
  </code></pre>
  
  <p>Problem is, <code>Placeholder</code> is now aligned incorrectly within <code>User</code>. Since the compiler knows that <code>Placeholder</code> is made of chars, not doubles, it would typically use an alignment of 1.</p>
  
  <p>Is there a way to declare <code>Placeholder</code> with the alignment matching that of <code>S</code> in C++03? Note that <code>S</code> is not a POD type. I also understand C++11 has <code>alignas</code>, but this is not universally available yet, so I'd rather not count on it if possible.</p>
  
  <p><strong>Update</strong>: just to clarify, this should work for any <code>S</code> - we don't know what it contains.</p>