From e7110984f3baad4670eac5bc1fbabb8b1ca7c26f Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Wed, 18 Jul 2018 23:07:31 +0200 Subject: [PATCH] Add Dictionary::erase_checked(key) method Same as erase, but it returns a boolean value indicating whether the pair was erased or not. This method should be removed during the next compatibility breakage, and 'Dictionary::erase(key)' should be changed to return a boolean. (cherry picked from commit 2f69e36cef8acca00ec5445f4aa8ec538bb38e3e) --- core/dictionary.cpp | 5 +++++ core/dictionary.h | 1 + 2 files changed, 6 insertions(+) diff --git a/core/dictionary.cpp b/core/dictionary.cpp index e3f4aa5f280..ed6c8416449 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -114,6 +114,11 @@ void Dictionary::erase(const Variant &p_key) { _p->variant_map.erase(p_key); } +bool Dictionary::erase_checked(const Variant &p_key) { + + return _p->variant_map.erase(p_key); +} + bool Dictionary::operator==(const Dictionary &p_dictionary) const { return _p == p_dictionary._p; diff --git a/core/dictionary.h b/core/dictionary.h index f001f2d5e10..98311ed8944 100644 --- a/core/dictionary.h +++ b/core/dictionary.h @@ -64,6 +64,7 @@ public: bool has_all(const Array &p_keys) const; void erase(const Variant &p_key); + bool erase_checked(const Variant &p_key); bool operator==(const Dictionary &p_dictionary) const;