我有一张地图:
std::map<long, std::vector<Rule>> Rules;
规则:
struct Rule
{
int m_id= -1;
std::wstring m_ruleName;
double m_angleValue;
};
我想要取回以m_ruleName;
分组的所有规则值示例: 地图:
1->R{1,file1,90}
2->R{2,file2,80}
3->R{2,file1,80}
期待:输出std :: map输出;
输出
file1:1,3
file2:2
我怎样才能用std :: transform?
做到这一点尝试使用我的变换:
std::transform(Rules.begin(), Rules.end(), std::back_inserter(labelsInSettingsFile), [&](std::pair<long, std::vector<Rules>>& rule) {
std::vector<long> labels;
for (auto fileName : rule.second)
{
if (labelsInSettingsFile.find(fileName.m_positionName) != labelsInSettingsFile.end())
{
labelsInSettingsFile.at(fileName.m_positionName).push_back(rule.first);
continue;
}
return std::make_pair(fileName.m_positionName, labels);
}
return std::make_pair<std::wstring, std::vector<long>>(L"", {});
});