use get_to instead of get for array as inplace assignment to avoid calling constructor and losing the data

This commit is contained in:
shuibao 2022-10-10 18:06:46 +08:00
parent a3e6e26dc8
commit e2c1831223
2 changed files with 12 additions and 4 deletions

View File

@ -186,7 +186,9 @@ auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines
{
for (std::size_t i = 0; i < N; ++i)
{
arr[i] = j.at(i).template get<T>();
// inplace assignment to avoid calling constructor and losing the data of its members
// arr[i] = j.at(i).template get<T>();
j.at(i).get_to(arr[i]);
}
}
@ -203,7 +205,9 @@ auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
{
for (std::size_t i = 0; i < N; ++i)
{
arr[i] = j.at(i).template get<T>();
// inplace assignment to avoid calling constructor and losing the data of its members
// arr[i] = j.at(i).template get<T>();
j.at(i).get_to(arr[i]);
}
}

View File

@ -4746,7 +4746,9 @@ auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines
{
for (std::size_t i = 0; i < N; ++i)
{
arr[i] = j.at(i).template get<T>();
// inplace assignment to avoid calling constructor and losing the data of its members
// arr[i] = j.at(i).template get<T>();
j.at(i).get_to(arr[i]);
}
}
@ -4763,7 +4765,9 @@ auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
{
for (std::size_t i = 0; i < N; ++i)
{
arr[i] = j.at(i).template get<T>();
// inplace assignment to avoid calling constructor and losing the data of its members
// arr[i] = j.at(i).template get<T>();
j.at(i).get_to(arr[i]);
}
}