Accessing 'key' and 'value' in std algorithms #4304
-
Is there any way to do something like the following: const auto comparison_func{[&other_json](const auto _iter) {
if (other_json.contains(_iter.key()) && other_json[_iter.key()] == _iter.value()) {
return true;
}
return false;
}};
// Ensure 'other_json' has all elements in 'must_match'
if (std::all_of(std::cbegin(must_match), std::cend(must_match), comparison_func)) {
// Do something if there's a match
} I understand that you can access the key and value using range-based for loops, but was curious about this method. In my testing it doesn't work, but it could just be me mishandling or misunderstanding something, so I thought it would be good to ask. |
Beta Was this translation helpful? Give feedback.
Answered by
nlohmann
Mar 5, 2024
Replies: 1 comment 1 reply
-
You may want to check https://json.nlohmann.me/api/basic_json/items/ |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MartinFlores751
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may want to check https://json.nlohmann.me/api/basic_json/items/