Junior — Middle
Do objects in std::unordered_map preserve the order of insertion?
sobes.tech AI
Answer from AI
No, objects in std::unordered_map do not preserve the order of insertion of elements. This container is implemented based on a hash table, and the order of elements is determined by the internal arrangement in the buckets, which does not guarantee the preservation of insertion order. If a container with preserved insertion order is needed, it is better to use std::map (sorted by key) or std::vector with an additional structure for searching.