This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Qualify make_move_iterator in vector::insert for input iterators
ClosedPublic

Authored by logan-5 on Feb 8 2020, 1:51 PM.

Details

Summary

Unqualified calls to make_move_iterator in the vector::insert overload for input iterators lead to ADL issues: https://gcc.godbolt.org/z/bmcNbh

As a bookkeeping question, are these ADL fixes more useful as tiny separate patches like this, or would it be less annoying if they were bundled together in a larger patch?

Diff Detail

Event Timeline

logan-5 created this revision.Feb 8 2020, 1:51 PM

I don't understand the actual algorithm being used in insert-with-input-iterators, but the ADL change certainly looks good to me. :)

I don't understand the actual algorithm being used in insert-with-input-iterators

Seems reasonable enough to me:

  1. insert up to capacity at the end of the vector
  2. construct any additional elements that would overflow capacity in a scratch buffer, then see how big it is (because input iterators), and reserve new capacity (if exception is thrown, destroy items from step 1--easy since they're still sitting at the end)
  3. rotate items from step 1 into place, and then insert() the scratch buffer after those

I'm not sure why you'd insert() the scratch buffer instead of just moving its elements onto the vector's end and then rotating all the elements into place at once, but maybe the insert() overload called for the scratch buffer does things more efficiently somehow.

ldionne accepted this revision.Feb 11 2020, 1:58 AM

Thanks for the patch!

This revision is now accepted and ready to land.Feb 11 2020, 1:58 AM
This revision was automatically updated to reflect the committed changes.