Title
Stability of erasure in unordered associative containers
Status
c++14
Section
[unord.req]
Submitter
Joaquín M López Muñoz

Created on 2014-01-21.00:00:00 last changed 131 months ago

Messages

Date: 2014-02-14.07:07:05

Proposed resolution:

This wording is relative to N3797.

  1. Modify [unord.req], p14 as indicated:

    -14- The insert and emplace members shall not affect the validity of references to container elements, but may invalidate all iterators to the container. The erase members shall invalidate only iterators and references to the erased elements, and preserve the relative order of the elements that are not erased.

Date: 2014-02-13.00:00:00

[ 2014-02-13 Issaquah: Move to Immediate ]

Date: 2014-01-21.00:00:00

Issue 518 resolution for unordered associative containers, modelled after that of issue 371, which is related to associative containers, states that insertion, erasure and rehashing preserve the relative ordering of equivalent elements. Unfortunately, this is not sufficient to guarantee the validity of code such as this:

std::unordered_multimap<int, int> m;
auto i = m.begin();
while (i != m.end()) {
  if (pred(i))
    m.erase(i++);
  else
    ++i;
}

(which is a direct translation from multimap to unordered_multimap of the motivating example in 371), or even this:

std::unordered_multimap<int, int> m;
auto p = m.equal_range(k);
while (p.first != p.second) {
  if (pred(p.first))
    m.erase((p.first)++);
  else
    ++(p.first);
}

because the relative ordering of non-equivalent elements elements could potentially change after erasure (not that any actual implementation does that, anyway). Such an underspecification does not happen for regular associative containers, where the relative ordering of non-equivalent elements is kept by design.

History
Date User Action Args
2014-02-27 17:03:20adminsetstatus: wp -> c++14
2014-02-20 13:52:38adminsetstatus: immediate -> wp
2014-02-14 07:07:05adminsetmessages: + msg6860
2014-02-14 07:07:05adminsetstatus: new -> immediate
2014-01-21 21:36:58adminsetmessages: + msg6801
2014-01-21 00:00:00admincreate