summaryrefslogtreecommitdiff
path: root/source/core
diff options
context:
space:
mode:
authorRonan <ro.cailleau@gmail.com>2025-04-18 22:03:23 +0200
committerGitHub <noreply@github.com>2025-04-18 20:03:23 +0000
commita597a0358f2c2b8ec1b71b7959861658a2c06ecc (patch)
tree877102efaa37819b3f0f15976726099b22aadffa /source/core
parentb4af953972fe5425be33dd064d840d12b6c1eb39 (diff)
Fixed crash in slang-ir-autodiff-loop-analysis.cpp (#6831)
* Added Dictionary::erase(iterator) and fixed crashing when filtering a dictionary in slang-ir-autodiff-loop-analysis.cpp * Added Dictionary::removeIf(Predicate) * Removed Dictionary::erase(it) --------- Co-authored-by: Julius Ikkala <julius.ikkala@gmail.com>
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-dictionary.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h
index 639978a08..d35255a8c 100644
--- a/source/core/slang-dictionary.h
+++ b/source/core/slang-dictionary.h
@@ -148,6 +148,25 @@ public:
// Erases the value at the specified key if it exists
void remove(const TKey& key) { map.erase(key); }
+ // Removes all values satifying the predicate:
+ // bool predicate(pair<Key, Value>)
+ template<typename Predicate>
+ void removeIf(Predicate&& predicate)
+ {
+ auto it = begin();
+ while (it != end())
+ {
+ if (predicate(*it))
+ {
+ it = map.erase(it);
+ }
+ else
+ {
+ ++it;
+ }
+ }
+ }
+
// Reserves enough space for the specified number of values
void reserve(Index size) { map.reserve(std::size_t(size)); };