#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Item1{int id; int data;};
vector<Item1> v1 = {{.id=1,.data=42},{.id=2,.data=69}};
struct Item2{int id; string data;};
vector<Item2> v2 = {{.id=1, .data="banana"},{.id=3,.data="coconut"}};
vector<int> select;
auto ret = ranges::set_intersection(v1,v2,back_inserter(select),{},&Item1::id,&Item2::id);
How do I get the result which should be
[[{.id=1,.data=42}, {.id=1, .data="banana"}]]
?
std::ranges::set_intersectiondoesn't do what you want hereYou need a different algorithm, one that will use the values from both ranges. Adapting the possible implementation of
set_intersectionAnd then you'll need to put them into a container that can hold the joined type.
Finally you can
See it on coliru