title: Atomically std::vector::push_back() and return index
body: <p>I need to create a function which appends a value to a vector and returns the index of the value that was just appended.</p>
  
  <p>Example:</p>
  
  <pre><code>int append(std::vector&lt;int&gt;&amp; numbers, int number){
    int retval = numbers.size();
    // what if some other thread calls push_back(number) in between these calls?
    numbers.push_back(number);
    return retval;
  }
  </code></pre>
  
  <p>I would like to do this atomically so that the returned index is always correct even when there may be multiple threads appending values to the vector. It would have been easy if <code>push_back</code> returned the index of the item just added. How can I guarantee that the correct index is returned?</p>