Re:Making a Go program 70% faster with a one character change
by a_t48 on Monday November 14, 2022 @04:38PM
(#33601543)
That only matters if you're storing it. It mainly just encourages never using a map with constant values. As an API writer it would be neat to be able to accept a `const unordered_map<key, const val>&` to promise "I won't touch the map nor its contents" but doing so mans you aren't compatible with most real world usages of map. It matters also if you want to make a copy of the map. Imagine I want a function `void maybeMakeCopyAndStore(const unordered_map<std::string, const ExpensiveStruct>&`. As I don't want to always make a copy, I don't want to accept a moved value. I would like to promise to my caller that I don't touch the passed in struct. But I also need to be compatible with caller code that likely mutates the values.
[ Parent
| on HN ]
There are no comments on this comment yet.