Visual C ++的std :: map的实现 [英] Visual C++'s implementation of std::map

查看:491
本文介绍了Visual C ++的std :: map的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Visual C ++中实现std :: map?

How is std::map implemented in Visual C++?

我知道一些树数据结构只是在删除节点时将节点标记为已删除,而不是删除它们马上。我需要确保我的元素永远不会与不再在地图中的元素进行比较。

I know that some tree data structures just flag nodes as deleted when they are removed, instead of removing them right away. I need to make sure that my elements are never compared to elements which are no longer in the map.

编辑:

我知道实现可能是正确的wrt。合同,这要求我有一个完全弱的排序元素类型。

I know that the implementation is probably correct wrt. the contract, which requires me to have a total weak ordering on the element type. However, I only have a partial ordering, which is not able to compare elements which are not live at the same time.

推荐答案

但是,我只有一个部分顺序,不能比较不同时居住的元素。无论实现是否维护已被擦除的节点,当节点被擦除时,它必须调用包含的对象析构函数。之后,它不可能将对象传递给比较函数,因为这将导致未定义的行为,这将使其成为不合格的实现。

Whether the implementation maintains nodes that have been erased or not, it must call the contained object destructor when the node is erased. After that, it cannot possibly pass the object to a comparison function as that would cause undefined behavior, which would make it a non-conforming implementation.

这篇关于Visual C ++的std :: map的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆