On this page
std::map
Prev: std::span | Up: containers | Next: std::variant
Rel: std::unordered_map
Ref: cppreference — std::map
Tags: #public #prog #cpp #stdlib #containers #tier/standard
Overview
std::map<K, V> (<map>) is an ordered associative container (typically a red-black tree) with guaranteed O(log n) lookup, insertion, and deletion, keeping keys sorted at all times.
When to Prefer Over std::unordered_map
- You need deterministic sorted iteration or range queries (
lower_bound,upper_bound). - You want worst-case O(log n) guarantees without hash-collision attacks or rehash spikes.
- Otherwise, prefer std::unordered_map for faster average lookup.
Linked from
Related notes
- tuts/cpp/stdlib/containers/span Linked here; links to this page; shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/unordered_map Linked here; links to this page; shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/variant Linked here; links to this page; shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers Linked here; links to this page; shared tags: #containers, #cpp, #prog, #stdlib
- tuts/cpp/stdlib/containers/array shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/expected shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/optional shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/string shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/string_view shared tags: #containers, #cpp, #prog, #stdlib, #tier
- tuts/cpp/stdlib/containers/vector shared tags: #containers, #cpp, #prog, #stdlib, #tier