I have my map in the following form:
const google::protobuf::Map<string, nrtprofile::RedisNewsMetric> map=redisNewsMessage.ig();
How should I iterate through the map to get all the keys and corresponding values?
You iterate through a google::protobuf::Map
in exactly the same way as a std::unordered_map
.
for (auto & pair : map)
{
doSomethingWithKey(pair.first);
doSomethingWithValue(pair.second);
}
If you have a C++17 compiler, you can use a structured binding to split that further
for (auto & [key, value] : map)
{
doSomethingWithKey(key);
doSomethingWithValue(value);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With