The vector is not needed after this so I would like the pairs to be moved from the vector to the map, rather than copied. I know I could loop over the vector and insert each pair, one by one.
1 2 3 4
for (auto& p : vec)
{
map.insert(std::move(p));
}
But I would like to know if there is something as short as just calling insert.
Does anyone know if this is guaranteed to work? I can't see anything that says the insert function has to be implemented in a way that can take advantage of move iterators. The standard just says "some generic algorithms can be called with move iterators to replace copying with moving", and then it gives one example of how you can use it to populate a vector by passing two move iterators to the constructor.
I'm going to mark this thread as solved because it's "good enough" for my use case. If copying happened it just means the code is less efficient, but it would still work.