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 :: call function from separate bash script 
Cpp :: how to print a word in c++ 
Cpp :: how to make randomizer c++ 
Cpp :: c++ prime number 
Cpp :: c++ stl vector get iterator from index 
Cpp :: std::future 
Cpp :: C++ rename function 
Cpp :: namespace file linking c++ 
Cpp :: pow without math.h 
Cpp :: unordered map c++ 
Cpp :: C++ to specify size and value 
Cpp :: c++ preprocessor commands 
Cpp :: right shift in c++ 
Cpp :: transpose matrix c++ vectors 
Cpp :: c++ switch case 
Cpp :: build a prefix array cpp 
Cpp :: << in C++ 
Cpp :: bubble sort function in c++ 
Cpp :: is there garbage collection in c++ 
Cpp :: logisch oder 
Cpp :: c ++ The output should be (abc),(def),(ghw) 
Cpp :: Maximum Weight Difference codechef solution c++ 
Cpp :: arduino bleutooth module hc-05 with led 
Cpp :: c++ error missing terminating character 
Cpp :: How to remove the % in zsh that show after running c++ file 
Cpp :: cpp module 42 
Cpp :: 10^18 data type in c++ 
Cpp :: . Single-line comments start with two forward slashes (//). 
Cpp :: c++ reverse bits 
Cpp :: how to i convert C++ into C 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =