map::operator[]、at、find、contains 的差异 | STL

本章覆盖:`operator[]`;missing key 会插入默认 mapped value;`at()`;`find()`;C++20 `contains()`;read vs write intent;`if (map[key])` 的隐式插入副作用;mapped type 默认构造要求;热路径查找应避免无意插入;API 选择应表达意图。

本章知识点

  • operator[]
  • missing key 会插入默认 mapped value
  • at()
  • find()
  • C++20 contains()
  • read vs write intent
  • if (map[key]) 的隐式插入副作用
  • mapped type 默认构造要求
  • 热路径查找应避免无意插入
  • API 选择应表达意图