flat/flatassoarray.cpp

The following code example is taken from the book
C++23 - The Complete Guide by Nicolai M. Josuttis, Leanpub, 2026
The code is licensed under a Creative Commons Attribution 4.0 International License. Creative Commons License

// raw code

#include <print>
#include <string>
#include <flat_map>

int main()
{
  std::flat_map<std::string, double> fm;

  // "insert or update" some elements in(to) the collection:
  fm["Rome"] = 18.5;     // insert
  fm["Kiev"] = 32.8;     // insert
  fm["London"] = 24.1;   // insert
  fm["Berlin"] = 22.6;   // insert

  std::println("{}", fm);

  fm["London"] = 28.9;   // update

  std::println("{}", fm);
}