title: Can I rely on contiguous memory in this case?
body: <p>Consider a class:</p>
  
  <pre><code>template &lt;typename T&gt;
  struct A{
    //...many public member functions...
    T x;
    T y;
    T z;
  }
  </code></pre>
  
  <p>And another, similar:</p>
  
  <pre><code>template &lt;typename T&gt;
  struct B{
    //many public member functions
    T x;
    T y;
  }
  </code></pre>
  
  <p>While not specified here, <code>T</code> will always be either <code>float</code> or <code>int</code> or <code>bool</code>.</p>
  
  <p>Now consider another struct:</p>
  
  <pre><code>struct Pair{
    A&lt;float&gt; a;
    B&lt;float&gt; b;
   }
  </code></pre>
  
  <p>Now a <code>vector</code>:</p>
  
  <pre><code> std::vector&lt;Pair&gt; bigBunch;
  </code></pre>
  
  <p>How safe is it to assume that all the <code>x</code>, <code>y</code>, <code>z</code> in <code>bigBunch</code> will be contiguous?  I know that <code>vector</code> guarantees contiguous memory between its <code>Pair</code>s but I also know that <code>struct</code> does not necessarily guarantee contiguous memory since padding can happen. However, I thought padding is only a risk if your <code>struct</code> elements are different types.</p>
  
  <p>I'd like to be able to get a pointer to <code>bigBunch[0].a.x</code> and then know that I can expect a contiguous stream of <code>float</code>s throughout the entire contents of <code>bigBunch</code>. And actually, a pointer to <code>bigBunch[0].a.x</code> would point to the same place as just saying <code>`bigBunch[0].a</code>.</p>
  
  <p>Would it matter if <code>Pair.a</code> and <code>Pair.b</code> were the same or different type, such as mixing <code>int</code>s and <code>float</code> rather than both being the same type (<code>float</code> in this example)?</p>