Created
February 5, 2023 01:44
-
-
Save Aposhian/7820fe82a2b629fb15ba38f65efef858 to your computer and use it in GitHub Desktop.
transform dissimilar containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <set> | |
#include <vector> | |
#include <algorithm> | |
#include <iostream> | |
struct Data | |
{ | |
Data(int d) | |
: data(d) {} | |
int data; | |
}; | |
int main() | |
{ | |
std::set<int> set; | |
set.insert(0); | |
set.insert(1); | |
std::vector<Data> output; | |
std::transform( | |
set.begin(), | |
set.end(), | |
std::back_inserter(output), | |
[](const int & code) { | |
return Data{code}; | |
} | |
); | |
for (const auto & data : output) { | |
std::cout << data.data << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment