std :: unordered_map,您可以使用存储桶编号访问存储桶中的元素吗? [英] std::unordered_map, can you access the elements in a bucket with its bucket number?

查看:68
本文介绍了std :: unordered_map,您可以使用存储桶编号访问存储桶中的元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 std :: unordered_map ,您是否可以访问某些存储区 i 中的元素如果其 bucket_size 不为零?

for std::unordered_map, can you access the elements in some bucket i if its bucket_size is not zero?

推荐答案

答案是使用 std :: unordered_map :: begin(bucket_num) std :: unordered_map :: cbegin(bucket_num)获取指向该存储桶第一个元素并迭代到存储桶末尾的迭代器 std :: unordered_map :: end(bucket_num)

The answer is to use std::unordered_map::begin(bucket_num) or std::unordered_map::cbegin(bucket_num) to get the iterator pointing to the the first element to that bucket and iterate to the end of the bucket std::unordered_map::end(bucket_num)

for ( auto it = u_map.begin(bucket_num); it!= u_map.end(bucket_num); ++it)
{
   cout<<it->first<<", "<<it->second<<endl;
} 

这篇关于std :: unordered_map,您可以使用存储桶编号访问存储桶中的元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆