title: Placement new with move constructor vs move assignment in folly small_vector
body: <p>While researching ideas for a constexpr vector-like container, I ran into <a href="https://github.com/facebook/folly/blob/master/folly/small_vector.h" rel="nofollow noreferrer">folly's small_vector container</a>. I was reading through the implementation and was confused by this part of <code>moveObjectsRightAndCreate</code>:</p>
  <pre class="lang-cpp prettyprint-override"><code>    for (; in != first &amp;&amp; out &gt; lastConstructed;) {
        // Out must be decremented before an exception can be thrown so that
        // the rollback guard knows where to start.
        --out;
        new (out) T(std::move(*(--in)));
      }
      for (; in != first;) {
        --out;
        *out = std::move(*(--in));
      }
      for (; out &gt; lastConstructed;) {
        --out;
        new (out) T(create());
      }
      for (; out != first;) {
        --out;
        *out = create();
      }
  </code></pre>
  <p>My understanding is this: For parts of the array where memory was uninitialized, they use placement new with <code>std::move</code>. For parts of the array where objects were previously moved from, they use move assignment.</p>
  <p>It seems like the primary difference is whether the move constructor or move assignment is used, but I'm not really sure I understand the implications of these choices. Why not use placement new for both cases? Why not use move assignment for both cases? Since we know the size of the array, we will never call the destructor on uninitialized memory anyway, right?</p>