summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-07-12 11:16:51 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-07-12 11:20:42 -0700
commit52e905e760765c88e1fae96a6649f80e51c28c55 (patch)
tree751fc5ea91a76292cf4ee6a47e43ed0acb09359c /absl
parent90099691acc77ad8a91addd4b2655fd6a1378993 (diff)
Improve documentation on erase.
PiperOrigin-RevId: 460509198 Change-Id: I6d85443cc3f568230f3a3d46b63358129654ddb9
Diffstat (limited to 'absl')
-rw-r--r--absl/container/flat_hash_map.h6
-rw-r--r--absl/container/flat_hash_set.h6
2 files changed, 8 insertions, 4 deletions
diff --git a/absl/container/flat_hash_map.h b/absl/container/flat_hash_map.h
index e6bdbd9e..006e478a 100644
--- a/absl/container/flat_hash_map.h
+++ b/absl/container/flat_hash_map.h
@@ -228,9 +228,11 @@ class flat_hash_map : public absl::container_internal::raw_hash_map<
// NOTE: returning `void` in this case is different than that of STL
// containers in general and `std::unordered_map` in particular (which
// return an iterator to the element following the erased element). If that
- // iterator is needed, simply post increment the iterator:
+ // iterator is needed, copy the iterator before erasing:
//
- // map.erase(it++);
+ // // `erase()` will invalidate `it`, so advance `it` first.
+ // auto copy_it = it++;
+ // m.erase(copy_it);
//
// iterator erase(const_iterator first, const_iterator last):
//
diff --git a/absl/container/flat_hash_set.h b/absl/container/flat_hash_set.h
index 4938c703..7bb1fa90 100644
--- a/absl/container/flat_hash_set.h
+++ b/absl/container/flat_hash_set.h
@@ -220,9 +220,11 @@ class flat_hash_set
// NOTE: returning `void` in this case is different than that of STL
// containers in general and `std::unordered_set` in particular (which
// return an iterator to the element following the erased element). If that
- // iterator is needed, simply post increment the iterator:
+ // iterator is needed, copy the iterator before erasing:
//
- // set.erase(it++);
+ // // `erase()` will invalidate `it`, so advance `it` first.
+ // auto copy_it = it++;
+ // set.erase(copy_it);
//
// iterator erase(const_iterator first, const_iterator last):
//