use get_to instead of get for array as inplace assignment to avoid calling constructor and losing the data
This commit is contained in:
parent
a3e6e26dc8
commit
e2c1831223
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user