我在 STL::map 中保留一个基于键 A 的结构 B。我正在编写代码,根据旧值对上述 map 主体的任何成员的任何更新,我将打印一条警报。
我不知道该怎么做。我研究过互联网。任何帮助,将不胜感激。谢谢。
最佳答案
如果用作键和值的类型定义了operator==
,最简单但代价高昂的解决方案是保留映射的备份,然后比较两个映射:
std::map<key,value> the_map;
std::map<key,value> test_copy; // hidden from the rest of the code
// copied from the_map on particular instants
bool map_has_changed() {
return the_map != test_copy;
}
关于c++ - 我如何比较 std::map 的正文成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5647820/