title: Unable to avoid copying while pushing objects with copy-construcor into a vector
body: <p>I'm trying to avoid copying with <code>emplace_back()</code> and <code>reserve()</code>. But when I've tried to do it, i caught myself getting 3 copies for reason i cannot really understand. <code>reserve()</code> actually helps to avoid copying, but <code>emplace_back()</code> actually does nothing with it (works the same way as <code>push_back()</code> in this case). Here's the code:</p>
  <pre class="lang-cpp prettyprint-override"><code>struct Vertex
  {
      size_t x, y, z;
  
      Vertex(size_t x, size_t y, size_t z)
      {
          this-&gt;x = x;
          this-&gt;y = y;
          this-&gt;z = z;
      }
  
      Vertex(const Vertex&amp; v)
          : x(v.x), y(v.y), z(v.z)
      {
          std::cout &lt;&lt; &quot;\nCOPIED!\n&quot;;
      }
  };
  
  int main()
  {
      std::vector&lt;Vertex&gt; vert;
  
      vert.reserve(3);
      vert.emplace_back(Vertex(1, 2, 3));
      vert.emplace_back(Vertex(4, 5, 6));
      vert.emplace_back(Vertex(7, 8, 9));
  
      return 0;
  }
  </code></pre>
  <p>The output is 3 times 'COPIED!'. Well i tried to something like this:</p>
  <pre><code>    vert.emplace_back(std::move(Vertex(1, 2, 3)));
      vert.emplace_back(std::move(Vertex(4, 5, 6)));
      vert.emplace_back(std::move(Vertex(7, 8, 9)));
  </code></pre>
  <p>to convert my objects into r-values, but again i got 3 times 'COPIED!'.</p>
  <p>Then i tried to push the same object 3 times with <code>std::move</code> and without and again got the same result:</p>
  <pre><code>    Vertex vertex(1, 2, 3);
      vert.emplace_back(vertex);
      vert.emplace_back(vertex);
      vert.emplace_back(vertex);
  </code></pre>
  <p>or</p>
  <pre><code>    Vertex vertex(1, 2, 3);
      vert.emplace_back(std::move(vertex));
      vert.emplace_back(std::move(vertex));
      vert.emplace_back(std::move(vertex));
  </code></pre>
  <p>I don't understand what am i doing wrong. I use MSVS 2022 Preview C++14. Also i tried to do it on C++14/17/20 and same result. Is there a way to get rid of all of the copies? Or maybe i understand situation wrong?</p>