On Wednesday 18 July 2007 18:07, Erik Johansson wrote: > If it crashes when using a reference, something must serious wrong > with his compiler. After all, the string is copied (again) when it is > added to the map.
Yes, that is right. I need to get a backtrace to find out what is going on. I'll switch it back to const std::string& in the morning. > > Perhaps you should add that to the coding style? > > if (pending.length()) = If has some length > > if (pending.size()) = If has some size > > if (!pending.empty()) = If not empty > > > > All seem the same to me... > > It's all about intent, and I guessed that you wanted to check if the > string was non-empty, not that the length was non-zero. It's a tiny > tiny difference, but I'm a bit pedantic from time to time... (If you > disagree I hope that you ignore me or scream at me loudly :)) Well, C++ is a language, and like most languages (Computer and Human) there are multiple ways to express the same intent. People can argue about which one is the most correct, but in the end everyone that is fluent understands them. > If nothing else, empty() may actually (in some strange, badly > implemented, probably non-existing) implementations be faster than > length(). Think not storing the length, only a char pointer... We can always run g++ -S and take a look at the assembly, but with -O2, I bet it all comes out the same... If there are any implementations out there, I bet they will have much bigger problems than a few extra instructions. Jon -- ________________________________________________________ Jon Keating ICQ: 16325723 [EMAIL PROTECTED] MSN: [EMAIL PROTECTED] http://www.licq.org GPG: 2290A71F http://www.thejon.org HOME: Minamiashigara, Japan
