std::unordered_map, can you access the elements in a bucket with its bucket number? [duplicate]

社会主义新天地 提交于 2021-02-19 08:01:09

问题


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


回答1:


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;
} 


来源:https://stackoverflow.com/questions/32043034/stdunordered-map-can-you-access-the-elements-in-a-bucket-with-its-bucket-numb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!