The static iterator_wrapper function is a means to access objects' keys in a range for. Example:
json j_object = {{"one", 1}, {"two", 2}};
for (auto& x : json::iterator_wrapper(j_object)) {
std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
}
I never was happy about the name of the function and there were several issues where users expected json to behave as a map so that .first and .second could be used.
Question 1
As for the name: What about replacing the static iterator_wrapper function by a member function items (name motivated by Python)?
Usage:
json j_object = {{"one", 1}, {"two", 2}};
for (auto& x : j_object.items()) {
std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
}
Question 2
One could even think about supporting .first and .second, but this would mean pre-computing the values for .key() and .value() which would mean a bit of overhead.
What do you think?
The static
iterator_wrapperfunction is a means to access objects' keys in a range for. Example:json j_object = {{"one", 1}, {"two", 2}}; for (auto& x : json::iterator_wrapper(j_object)) { std::cout << "key: " << x.key() << ", value: " << x.value() << '\n'; }I never was happy about the name of the function and there were several issues where users expected
jsonto behave as a map so that.firstand.secondcould be used.Question 1
As for the name: What about replacing the static
iterator_wrapperfunction by a member functionitems(name motivated by Python)?Usage:
json j_object = {{"one", 1}, {"two", 2}}; for (auto& x : j_object.items()) { std::cout << "key: " << x.key() << ", value: " << x.value() << '\n'; }Question 2
One could even think about supporting
.firstand.second, but this would mean pre-computing the values for.key()and.value()which would mean a bit of overhead.What do you think?