当密钥不存在时,unordered_multimap::bucket(key)
应该返回什么?
参考资料说它应该返回包含密钥的桶的桶号,但没有说明当 unordered_multimap 中不存在该密钥时会发生什么。
我自己尝试过,但得到的结果不正确:
std::unordered_multimap<std::string, std::string> m = {{"jack", "foo"}, {"jill", "bar"}};
std::cout << "jack is in bucket " << m.bucket("jack") << std::endl;
std::cout << "jill is in bucket " << m.bucket("jill") << std::endl;
std::cout << "bjarne is in bucket " << m.bucket("bjarne") << std::endl;
输出是:
jack is in bucket 3
jill is in bucket 4
bjarne is in bucket 4
这是否意味着我必须使用 sayunordered_multimap::count(key) == 0
来捕获不存在的键?