I was playing around today with some timing code and discovered that when asigning a string literal to std::string, that it was around 10% faster (with a short 12 char string, so likly even bigger difference for large strings) to do so with a literal of known length (using the sizeof operator) than not. (Only tested with the VC9 compiler, so I guess other compilers may do it better).
std::string a("Hello World!");
std::string b("Hello World!", sizeof("Hello World!");//10% faster in my tests
Now the reason I suspect is for a it has to call strlen (VC9 goes into assembly which isnt a strong point of mine so I cant be 100% sure) to get the string length, then do the same as the second case does anyway.
Given how long std::string has been around, and how common the first case is (especially if you include +, =, +=, etc operators and equivalent methods) in real world programs how come it doesn't optimise the first case into the second? It seems a really simple one as well to just say if it's an std::basic_string object and a literal, compile it as if it was written like b?