(C++) std::map
January 9, 2018 · View on GitHub
(C++) std::map
std::map is an STL container for mapping two kinds of data types.
For a std::map<T,U>, T is called the key, and U is called the value. One key can only have one value. If a key needs to have one or more values, use a std::multimap.
Examples
std::map code snippets
Note that among these are also more general container code snippets.
- IsKeyInMap, checks if a key is in a std::map
- GetKeyWithMaxValue, get the key with the highest value
- GetValueInMap, get a value in a std::map
- Check if a key is in a std::map, IsKeyInMap
- Get a value in a std::map, GetValueInMap
- LoopReader, reading a container looped
- Reading a container looped, LoopReader
Advice
- A std::map is usually implemented as a red-black tree [1]
External links
References
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 31.6. Advice. page 924: '[8] A map is usually implemented as a red-black tree'