top | item 46274183

(no title)

dubi_steinkek | 2 months ago

Why is this a perf footgun? As someone who doesn't write a lot of c++, I don't see anything intuitively wrong.

Is it that iterating over map yields something other than `std::pair`, but which can be converted to `std::pair` (with nontrivial cost) and that result is bound by reference?

discuss

order

nemetroid|2 months ago

Close, it is a std::pair, but it differs in constness. Iterating a std::map<K, V> yields std::pair<const K, V>, so you have:

  std::pair<const std::string, int>
vs

  std::pair<std::string, int>

1718627440|2 months ago

And what does casting const change, that would involve runtime inefficiencies?