From 15e757c42b5584f941807205be05a2f5444c83ea Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 27 Aug 2017 10:41:39 +0200 Subject: [PATCH] :hammer: trying to fix memory issue with valarray --- src/json.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index ef55a93c..897f8581 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -667,11 +667,10 @@ struct external_constructor enable_if_t::value, int> = 0> static void construct(BasicJsonType& j, const std::valarray& arr) { - using std::begin; - using std::end; j.m_type = value_t::array; j.m_value = value_t::array; - j.m_value.array = j.template create(begin(arr), end(arr)); + j.m_value.array->resize(arr.size()); + std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin()); j.assert_invariant(); } }; @@ -1112,10 +1111,7 @@ void from_json(const BasicJsonType& j, std::valarray& l) JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); } l.resize(j.size()); - for (size_t i = 0; i < j.size(); ++i) - { - l[i] = j[i]; - } + std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l)); } template