Reputation: 31577
I have a set of objects that, during some initializations, I need to keep in an std::map
, but after initialization I only need an std::vector
. What efficient way is there to save the map's values into a vector?
I'm looking either for something with move semantics, or maybe there's some implementation of a map in Boost that would make this easier.
Upvotes: 2
Views: 413
Reputation: 76788
Shouldn't this do the job:
your_vector.reserve(your_map.size());
for(auto& item : your_map) {
your_vector.push_back(std::move(item.second));
}
Upvotes: 3