Commit 65dfbf2b by Abseil Team Committed by Copybara-Service

Clarify function comment for `erase` by stating that this idiom only works for…

Clarify function comment for `erase` by stating that this idiom only works for "some" standard containers.

If you use this idiom with `std::vector` or `absl::btree_map` you can end up either skipping elements or dereferencing an invalid iterator.

PiperOrigin-RevId: 639892758
Change-Id: Ic5c213667b4b1e8c39813ee237aaffe320a8eb27
parent d06b8277
...@@ -3105,7 +3105,7 @@ class raw_hash_set { ...@@ -3105,7 +3105,7 @@ class raw_hash_set {
// this method returns void to reduce algorithmic complexity to O(1). The // this method returns void to reduce algorithmic complexity to O(1). The
// iterator is invalidated, so any increment should be done before calling // iterator is invalidated, so any increment should be done before calling
// erase. In order to erase while iterating across a map, use the following // erase. In order to erase while iterating across a map, use the following
// idiom (which also works for standard containers): // idiom (which also works for some standard containers):
// //
// for (auto it = m.begin(), end = m.end(); it != end;) { // for (auto it = m.begin(), end = m.end(); it != end;) {
// // `erase()` will invalidate `it`, so advance `it` first. // // `erase()` will invalidate `it`, so advance `it` first.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment