You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for (auto element : j) {
std::cout << element << '\n';
}
Does this end up creating a copy of each array element during each iteration?
Are
for (const auto &element : j) {
std::cout << element << '\n';
}
and
for (auto &element : j) {
element["a"]=...;
}
better alternatives or is the version in the readme the optimal usage for all scenarios?
(In some sense this is just a basic c++ question. I don't really know how ranged for loop work in c++, or how to actually check what is happening in each of the scenarios, but in any case I am specifically curious about it works for basic_json's implementation)
Thanks!
The text was updated successfully, but these errors were encountered:
Yes, that first version will copy the elements. The second version is better. The third version is the required form if you want to change the elements of the j object itself.
Given that the the library aims to implement a highly performant json class, update the example so that beginners who perform benchmarks are more likely to use the library efficiently. cf. nlohmann#214
cheers
In the Readme, the following example is provided:
Does this end up creating a copy of each array element during each iteration?
Are
and
better alternatives or is the version in the readme the optimal usage for all scenarios?
(In some sense this is just a basic c++ question. I don't really know how ranged for loop work in c++, or how to actually check what is happening in each of the scenarios, but in any case I am specifically curious about it works for basic_json's implementation)
Thanks!
The text was updated successfully, but these errors were encountered: