Does an iterator iterate through boost::unordered_set or boost::unordered_map in the same order as long as the set's unchanged?

StackOverflow https://stackoverflow.com/questions/12729393

  •  05-07-2021
  •  | 
  •  

문제

Does an iterator iterate through boost::unordered_set or boost::unordered_map in the same order as long as the set or the map is unchanged?

도움이 되었습니까?

해결책

Some implementations of a hash map will reorder the items that hash to the same bin, putting the most recently accessed item at the front of a list, as an optimization. This would change the order. I'm not aware that boost::unordered_map does this, but in the future you might end up substituting std::unordered_map and it will all depend on your compiler's implementation.

다른 팁

It should be deterministic but as long as they are so-called unordered, you should not rely on this to iterate over your elements.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top