c++ - 我如何比较 std::map 的正文成员?

标签 c++ stl dictionary comparison compare

我在 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/

相关文章:

c# - C 中的 SortedDictionary

html - Qt 中 HTTP GET 响应的奇怪编码

c++ - 为什么 std::string 对象的最大大小是 4611686018427387897?

python - 为 pandas 中数据框的列的组合创建字典

dictionary - 如何(不安全地)将 map 反射(reflect)为约束?

c++ - 派生对象的 boost 序列化不调用派生的序列化()

c++ - IO运算符重载错误

c++ - vector vector 的初始化?

c++ - 在映射中使用对作为键 (C++/STL)

c++ - vector map C++