Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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()));
}
Comment

move elements from vector to unordered_set

#include <iostream>
#include <vector>
#include <unordered_set>
 
int main()
{
    std::vector<int> input({ 1, 2, 2, 1, 3, 1, 4 });
 
    std::unordered_set<int> set(input.begin(), input.end());
 
    for (const int &i: set) {
        std::cout << i << " ";
    }
 
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: fizzbuzz c++ 
Cpp :: integer to char c++ 
Cpp :: remove element from vector c++ 
Cpp :: c++ 14 for sublime windoes build system 
Cpp :: c++ print out workds 
Cpp :: C++ float and double Different Precisions For Different Variables 
Cpp :: c detect os 
Cpp :: c++ reverse string 
Cpp :: how many months have 31 days 
Cpp :: descending order c++ 
Cpp :: zero fill in c++ 
Cpp :: C++ New Lines 
Cpp :: list in c++ 
Cpp :: insert in vector 
Cpp :: c++ #define 
Cpp :: attention nlp 
Cpp :: map in c 
Cpp :: c++ set swap 
Cpp :: c++ initialise array 
Cpp :: passing custom function in sort cpp 
Cpp :: how to grab numbers from string in cpp 
Cpp :: find positive number factorial in C++ 
Cpp :: C++ wchar_t 
Cpp :: C++ program to sizes of data types 
Cpp :: Initialize Vector Iterator Through Vector Using Iterators 
Cpp :: potato 
Cpp :: c++ prime number 
Cpp :: assign one vector to another c++ 
Cpp :: C++ Nested if 
Cpp :: use set to get duplicates in c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =