Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

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

 

  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

 

 

 

 

 

Advice

 

 

 

 

 

 

External links

 

  1. SGI page about std::map

 

 

 

 

 

References

 

  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'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict