diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index b7c24008c..0579fa922 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -184,10 +184,10 @@ template , { for (auto it = this->begin(); it != this->end(); ++it) { - if (m_compare(it->first, key) // NOLINT(cppcoreguidelines-missing-std-forward) - { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) + if (m_compare(it->first, key)) // NOLINT(cppcoreguidelines-missing-std-forward) + { + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) { it->~value_type(); // Destroy but keep allocation new (&*it) value_type{std::move(*next)}; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index d55be0026..30e7f88aa 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19102,10 +19102,10 @@ template , { for (auto it = this->begin(); it != this->end(); ++it) { - if (m_compare(it->first, key) // NOLINT(cppcoreguidelines-missing-std-forward) - { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) + if (m_compare(it->first, key)) // NOLINT(cppcoreguidelines-missing-std-forward) + { + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) { it->~value_type(); // Destroy but keep allocation new (&*it) value_type{std::move(*next)};