6 ms·
even if you take the string as `const std::string &` you will still end up with implicit string construction if someone passes a char* . Sure you can use std::s
by hendzen 7y ago
even if you take the string as `const std::string &` you will still end up with implicit string construction if someone passes a char* . Sure you can use std::string_view as an argument type to prevent this simple case, but it doesn't work in all cases.
Consider a std::map<std::string, Blah> for example, if you have a char* and you want to index in to the map you are going to also end up with an intermediate string construction b/c STL associative containers don't have heterogenous lookup. Note that this was fixed in std::map::find in C++14 [0], but still is there for operator[].
[0] - https://en.cppreference.com/w/cpp/container/map/find https://en.cppreference.com/w/cpp/container/map/find