如何循环multimap只为每个键获取第一个键值对?

rsk*_*k82 1 c++ iteration multimap

例如,如果我有这样的mmap:

alice -> 30
bob -> 23
josh -> 20
josh -> 30
andy -> 40
andy -> 40
Run Code Online (Sandbox Code Playgroud)

只得到这对:

alice -> 30
bob -> 23
josh -> 20
andy -> 40
Run Code Online (Sandbox Code Playgroud)

Vik*_*ehr 5

这应该尽可能干净,有效:

for(auto it = m.begin(); it != m.end(); it = m.upper_bound(it->first)) {
  std::cout << it->first << ":" << it->second << std::endl;
}
Run Code Online (Sandbox Code Playgroud)