C ++标准的哪一部分要求set :: erase立即调用析构函数 [英] What section of the C++ standard requires that set::erase calls destructors promptly

查看:395
本文介绍了C ++标准的哪一部分要求set :: erase立即调用析构函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++ 11标准的哪个部分(这里是一个副本的标准草案)需要如std :: set,std :: map,std :: unordered_set和std :: unordered_map的关联容器来立即调用从它们中删除的对象的析构函数?



换句话说 - 是标准兼容的关联容器允许延迟(不elide!)他们对它们存储的键和值的键和/或值析构函数的调用? p>

如果没有,标准中的哪个部分禁止它?



我问,因为我对延迟删除感兴趣称为弱删除)。这是一种从实际数据保留在其中的结构中擦除键(或键/值对)的方法,但是包含它的节点被标记为死。这些有时称为墓碑。它们用于许多有关数据结构的理论论文,有时在实践中使用



一个非常简单的例子是在开放寻址的哈希表中删除,有时用墓碑来实现。当哈希表最终被重建时,所有的析构函数被调用,并且墓碑的键/值对可以被实际最终删除和释放。

解决方案

对于描述 erase 调用的要求的关联容器,表中有一般要求。



例如 aererase(q) |删除 q 指向的元素。



映射的元素类型是一个键和一个值的对。没有明显的解释擦除,不涉及正确销毁元素(键和值)。我怀疑这个标准对这种情况有更明确的说法。


What section of the C++11 standard (here's a copy of a draft standard) requires associative containers like std::set, std::map, std::unordered_set, and std::unordered_map to immediately call destructors of objects that are erased from them?

To put it another way - are standard-compliant associative containers allowed to delay (not elide!) their calls to the key and/or value destructors of the keys and values they store?

If not, what section in the standard forbids it?

I ask because I am interested in lazy deletions (sometimes called weak deletions) in associative containers. This is a method of "erasing" a key (or key/value pair) from a structure in which the actual data remains in place, but the node containing it is marked as dead. These are sometimes called tombstones. They are used in many theory papers about data structures, and sometimes used in practice.

A very simple example is deletion in open-addressed hash tables, which is sometimes implemented with tombstones. When the hash table is eventually rebuilt, all the destructors are called and the tombstoned key/value pairs can be actually and finally deleted and deallocated.

解决方案

There are general requirements in the table for associative containers which describe the requirements for erase calls.

E.g. a.erase(q) | erases the element pointed to by q.

The element type for map is a pair of a key and a value. There is no sensible interpretation of "erases" that doesn't involve the proper destruction of the element (key and value). I doubt there is anything more explicitly worded for this situation in the standard.

这篇关于C ++标准的哪一部分要求set :: erase立即调用析构函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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