title: How do vector elements preserve their original address after a vector std::move?
body: <p>As you can see in the output, the objects of the vector <code>pre</code> not only "moved" to the vector <code>post</code>, but also preserved their original address space in memory. What is really going on behind this move? Is this behaviour expected? Say I need to have a separate vector of pointers to these objects, is it safe to assume that after this move the objects will always have their original addresses?</p>
  
  <p><em>Actually, I have a class containing a vector like this and the vector of pointers I mentioned as members. I have also deleted the copy ctors, and defined the move ones for the class.</em></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  struct B {
      int val = 0;   
      B(int aInt) : val(aInt) {  };
  };
  
  int main() {
  
      std::vector&lt;B&gt; pre;
  
      pre.push_back(B(1));
      pre.push_back(B(2));
      std::cout &lt;&lt; "pre-move:\t" &lt;&lt; (void*)&amp;pre.at(0) &lt;&lt; '\n';
      std::cout &lt;&lt; "pre-move:\t" &lt;&lt; (void*)&amp;pre.at(1) &lt;&lt; '\n';
  
      std::vector&lt;B&gt; post(std::move(pre));
  
      std::cout &lt;&lt; "post-move:\t" &lt;&lt; (void*)&amp;post.at(0) &lt;&lt; '\n';
      std::cout &lt;&lt; "post-move:\t" &lt;&lt; (void*)&amp;post.at(1) &lt;&lt; '\n';
  
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>pre-move:   0x1d7b150 
  pre-move:   0x1d7b154 &lt;------|
  post-move:  0x1d7b150        |
  post-move:  0x1d7b154 &lt;------|
  </code></pre>