I am serializing some internal structures to Json and would like to populate an array with null json values, storing a pointer to each null value and then later filling that value with the appropriate data. Eg:
json arr = json::array();
arr.emplace_back(nullptr);
auto* ptr0 = &arr.at(0);
arr.emplace_back(nullptr);
auto* ptr1 = &arr.at(1);
arr.emplace_back(nullptr);
auto* ptr2 = &arr.at(2);
//Some time later:
*ptr0 = 0;
*ptr1 = 1;
*ptr2 = 2;
However, this apparently yields an array where the first two elements are null, and only the last element in the array contains the actual data (an integer == 2).
I am not sure if I am simply using the API incorrectly, or there is an actual issue that needs to be addressed. I would very much appreciate any help, thanks!
I am serializing some internal structures to Json and would like to populate an array with null json values, storing a pointer to each null value and then later filling that value with the appropriate data. Eg:
However, this apparently yields an array where the first two elements are null, and only the last element in the array contains the actual data (an integer == 2).
I am not sure if I am simply using the API incorrectly, or there is an actual issue that needs to be addressed. I would very much appreciate any help, thanks!