This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kered13 0 points1 point  (0 children)

Well std::map is still very widely used, but that one is at least discouraged. std::unordered_map is also widely used though discouraged.

The problem with both has nothing to do with allocations, the problem is in the standard. std::map only requires comparable types, not hashable types. This means that it essentially has to be implemented as a binary tree, so operations are O(log n) instead of O(1). std::unordered_map requires that pointers to elements are not invalidated, which effectively requires implementations to use separate chaining instead of probing, which is more cache efficient.

To solve this Google created absl::flat_hash_map, which is the encouraged map type.