for (auto [s, n]: my_map)
copies all the data needlessly, better to use for (const auto& [s, n]: my_map) for (auto [s, n]: my_map)
copies all the data needlessly, better to use for (const auto& [s, n]: my_map)- Omitting pointer indirections (loads),
- Not forcing the pointee to have an address (i.e. gotta be in memory, not just registers), and
- Eliminating aliasing questions, potentially leading to better codegen if the function isn't inlined.
1: https://quuxplusone.github.io/blog/2021/11/09/pass-string-vi...