title: Is it safe to use emplace_back with a container of unique_ptrs?
body: <p>Consider the following:</p>
  
  <pre><code>std::vector&lt;std::unique_ptr&lt;int&gt;&gt; ptrsToInts;
  ptrsToInts.emplace_back(new int);
  </code></pre>
  
  <p>If reallocation occurs in the vector, and that fails (throwing <code>std::bad_alloc</code>), am I "safe" or will I leak an <code>int</code>?</p>
  
  <p>C++11 23.3.6.5 [vector.modifiers]/1 says:</p>
  
  <blockquote>
    <p>If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move assignment operator of <code>T</code> or by any <code>InputIterator</code> operation there are no effects.</p>
  </blockquote>
  
  <p>which seems to indicate that this is a potential problem. That is, if there are "no effects", then no <code>unique_ptr</code> ever was constructed, and therefore the destructor behavior one would rely on to <code>delete</code> that pointer would not occur. (Which might indicate that <code>emplace_back</code> should be banned for containers of <code>unique_ptr</code>s)</p>