Re:Mapping Strings in C++
by charles-salvia on Wednesday April 12, 2017 @08:47PM
(#14103117)
The point is apparently to return "type_t::num_types" if the key doesn't exist in the map. Using at() throws an exception if the key doesn't exist.
Re:Mapping Strings in C++
by user5994461 on Thursday April 13, 2017 @05:19AM
(#14105369)
That's an artificial requirements, you can do the same with at() or change the requirements.
Catching all errors to return a default type is an arguable decision.
If you really want to mess around, you compare "map.at(key)" against "map[key]". at return a const, [] is not const and allows to create the key (if I remember well).
To conclude, if you really really want to show off your optimization skill, you optimize return types: "auto &&" vs "auto &" vs "auto" vs a few other ones.
Can't help you with that last one. One decade of C++ and still struggling with reference, value copy, left-value reference...
That reminds me how bad C++ is a mess. 5 minutes of optimizations and my brain is already hurting. Good thing I moved to DevOps. More pay, less hassle.