(almost) always do this with std::map!
std::map<key, value, std::less<>> to easily enable transparent comparators
What happens if you do it with a key type of std::string and you try to .find("raw string literal") by accident instead of .find("string view literal"sv)? Does it try to construct a std::string for every comparison, or does it just miss out on the optimization of checking the length first before checking the string content? Does it even matter?
what about std::unordered_map with std::hash<> and std::equal_to<>? and also the other containers using hashes and keys?
What happens if you do it with a key type of
std::stringand you try to.find("raw string literal")by accident instead of.find("string view literal"sv)? Does it try to construct astd::stringfor every comparison, or does it just miss out on the optimization of checking the length first before checking the string content? Does it even matter?
Yes, the point here is to avoid creating the extra strings, because the std::less<> has templated arguments and will compare anything comparable without forcing it into one type or the other.