From e8ab313dde28d6b81049993f1952f747523a1b9f Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 23 Oct 2026 10:24:17 +0200 Subject: [PATCH] 2.4.8: ordered_map: share erase_impl between the key erase overloads (#5891) Signed-off-by: Niels Lohmann --- include/nlohmann/ordered_map.hpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index e5f9164f6..831261219 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -125,6 +125,19 @@ private: Container::pop_back(); } + /// @brief remove the entry with the given key; returns the number of removed entries + template + size_type erase_impl(const K& key) + { + const auto it = find_impl(*this, key); + if (it != this->end()) + { + erase_at(it); + return 1; + } + return 0; + } + public: template::value, int> = 0> @@ -214,26 +227,14 @@ public: size_type erase(const key_type& key) { - const auto it = find_impl(*this, key); - if (it != this->end()) - { - erase_at(it); - return 1; - } - return 0; + return erase_impl(key); } template::value, int> = 0> size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) { - const auto it = find_impl(*this, key); - if (it != this->end()) - { - erase_at(it); - return 1; - } - return 0; + return erase_impl(key); } iterator erase(iterator pos)