Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
140 lines (80 sloc) 1.91 KB






(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.













std::map code snippets


Note that among these are also more general container code snippets.


  1. IsKeyInMap, checks if a key is in a std::map
  2. GetKeyWithMaxValue, get the key with the highest value
  3. GetValueInMap, get a value in a std::map
  4. Check if a key is in a std::map, IsKeyInMap
  5. Get a value in a std::map, GetValueInMap
  6. LoopReader, reading a container looped
  7. Reading a container looped, LoopReader








  • A std::map is usually implemented as a red-black tree [1]






External links


  1. SGI page about std::map








  1. 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'