Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What section of the C++ standard requires that set::erase calls destructors promptly

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.

like image 432
jbapple Avatar asked Jan 22 '14 06:01

jbapple


1 Answers

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.

like image 55
CB Bailey Avatar answered Sep 18 '22 12:09

CB Bailey