diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index aa8d35a0f..7ba3ab71f 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -91,11 +91,10 @@ struct external_constructor int > = 0 > static void construct(BasicJsonType& j, const CompatibleStringType& str) { - typename BasicJsonType::json_value value; - value.string = j.template create(str); + auto* created = j.template create(str); j.m_data.m_value.destroy(j.m_data.m_type); j.m_data.m_type = value_t::string; - j.m_data.m_value = value; + j.m_data.m_value.string = created; j.assert_invariant(); } }; @@ -199,11 +198,10 @@ struct external_constructor using std::begin; using std::end; - typename BasicJsonType::json_value value; - value.array = j.template create(begin(arr), end(arr)); + auto* created = j.template create(begin(arr), end(arr)); j.m_data.m_value.destroy(j.m_data.m_type); j.m_data.m_type = value_t::array; - j.m_data.m_value = value; + j.m_data.m_value.array = created; j.set_parents(); j.assert_invariant(); } @@ -293,11 +291,10 @@ struct external_constructor using std::begin; using std::end; - typename BasicJsonType::json_value value; - value.object = j.template create(begin(obj), end(obj)); + auto* created = j.template create(begin(obj), end(obj)); j.m_data.m_value.destroy(j.m_data.m_type); j.m_data.m_type = value_t::object; - j.m_data.m_value = value; + j.m_data.m_value.object = created; j.set_parents(); j.assert_invariant(); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 3f74e166f..118f1cefe 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -6620,11 +6620,10 @@ struct external_constructor int > = 0 > static void construct(BasicJsonType& j, const CompatibleStringType& str) { - typename BasicJsonType::json_value value; - value.string = j.template create(str); + auto* created = j.template create(str); j.m_data.m_value.destroy(j.m_data.m_type); j.m_data.m_type = value_t::string; - j.m_data.m_value = value; + j.m_data.m_value.string = created; j.assert_invariant(); } }; @@ -6728,11 +6727,10 @@ struct external_constructor using std::begin; using std::end; - typename BasicJsonType::json_value value; - value.array = j.template create(begin(arr), end(arr)); + auto* created = j.template create(begin(arr), end(arr)); j.m_data.m_value.destroy(j.m_data.m_type); j.m_data.m_type = value_t::array; - j.m_data.m_value = value; + j.m_data.m_value.array = created; j.set_parents(); j.assert_invariant(); } @@ -6822,11 +6820,10 @@ struct external_constructor using std::begin; using std::end; - typename BasicJsonType::json_value value; - value.object = j.template create(begin(obj), end(obj)); + auto* created = j.template create(begin(obj), end(obj)); j.m_data.m_value.destroy(j.m_data.m_type); j.m_data.m_type = value_t::object; - j.m_data.m_value = value; + j.m_data.m_value.object = created; j.set_parents(); j.assert_invariant(); }