C ++使用.find()和struct作为map中的键
|
我所有无法访问BOOST或STL的人,我的结构和映射类似于以下伪指令:
struct s_map_key{
int a;
int b;
bool operator<(const s_map_key& smk) const
{
if (a < smk.a)
{
return true;
} else if (a == smk.a)
{
if (b < smk.b)
{
return true;
}
else if (b == smk.b)
{
return true;
}
}
return false;
}
};
int main(int argc, char* argv[])
{
std::multimap<s_map_key, std::string> myMap;
for(int i = 0; i <10; i++)
{
s_map_key smk;
smk.a = i;
smk.b = 2;
myMap.insert(std::make_pair(smk, \"test\"));
}
s_map_key smk;
smk.a = 3;
std::multimap<s_map_key, std::string>::iterator x = myMap.find(smk);
if(x != myMap.end())
{
std::cout << x->first.a <<std::endl;
std::cout << x->first.b <<std::endl;
}
return 0;
}
我想做的是在A = 2,B = 2或A&B = 2的所有情况下搜索多图。我不确定,但是,我认为我需要在结构中为\创建谓词。寻找\”。有想法吗?
没有找到相关结果
已邀请:
2 个回复
募磷
或其他任何东西都需要
。但是,您的实现有一个错误。如果操作数相等,则返回“ 3”。
和其他标准库组件使用the5ѭ的假设,因此,如果
和ѭ7equal相等,则
必须为
才能使
工作。
括宠