Skip to content

Instantly share code, notes, and snippets.

@Aposhian
Created February 5, 2023 01:44
Show Gist options
  • Save Aposhian/7820fe82a2b629fb15ba38f65efef858 to your computer and use it in GitHub Desktop.
Save Aposhian/7820fe82a2b629fb15ba38f65efef858 to your computer and use it in GitHub Desktop.
transform dissimilar containers
#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