diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 38bab3806..13685dd10 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1639,16 +1639,19 @@ class basic_json m_type = value_t::object; m_value = value_t::object; - std::for_each(init.begin(), init.end(), [this](const detail::json_ref& element_ref) + for (auto& element_ref : init) { auto element = element_ref.moved_or_copied(); + auto res = m_value.object->emplace( + std::move(*((*element.m_value.array)[0].m_value.string)), + std::move((*element.m_value.array)[1])); + #if JSON_DIAGNOSTICS - (*element.m_value.array)[1].m_parent = this; + res.first->second.m_parent = this; +#else + static_cast(res); // unused variable - fix warning #endif - m_value.object->emplace( - std::move(*((*element.m_value.array)[0].m_value.string)), - std::move((*element.m_value.array)[1])); - }); + } } else { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 2e9768f77..59a829b5f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -18275,16 +18275,19 @@ class basic_json m_type = value_t::object; m_value = value_t::object; - std::for_each(init.begin(), init.end(), [this](const detail::json_ref& element_ref) + for (auto& element_ref : init) { auto element = element_ref.moved_or_copied(); + auto res = m_value.object->emplace( + std::move(*((*element.m_value.array)[0].m_value.string)), + std::move((*element.m_value.array)[1])); + #if JSON_DIAGNOSTICS - (*element.m_value.array)[1].m_parent = this; + res.first->second.m_parent = this; +#else + static_cast(res); // unused variable - fix warning #endif - m_value.object->emplace( - std::move(*((*element.m_value.array)[0].m_value.string)), - std::move((*element.m_value.array)[1])); - }); + } } else {