我正在尝试使用std :: set_intersection来查找具有公共绑定"name"字段的2种完全不同类型的数据结构之间的公共元素.
我在这里查看了以下输入链接描述,但它似乎迫使我沿着路线在我试图避免的两种不同结构类型之间进行自定义转换(因为这些类型来自第三方)
下面的代码片段显示了我想要实现的目标.
// common field used for set intersection
typedef struct StructA {
std::string mCommonField;
float mFloatValue;
} StructA;
typedef struct StructB {
std::string mCommonField;
int mValue1;
short mValue2;
} StructB;
// initially unsorted list
std::vector<StructA> aStructs = {{"hello", 1.0f}, {"goodbye", 2.0f}, {"foo", 3.0f}};
// initially unsorted list
std::vector<StructB> bStructs = {{"hello", 1, 2}, {"goodbye", 3, 4}, {"bar", 5, 6}};
// sorting both sets before calling std::intersection
std::sort(aStructs.begin(), aStructs.end(),
[](const StructA& …Run Code Online (Sandbox Code Playgroud)