Answers for "unordered_set to vector"

C++
0

unordered_set to vector

Before C++17
vector.insert(vector.end(), set.begin(), set.end());

After C++17
vector.reserve(set.size());
for (auto it = set.begin(); it != set.end(); ) {
    vector.push_back(std::move(set.extract(it++).value()));
}
Posted by: Guest on August-29-2021

Browse Popular Code Answers by Language