On Thu, Jan 7, 2010 at 1:28 PM, Peter Kasting <pkast...@google.com> wrote: > If you have ever used any of the EmptyXXX() functions, or ever will, please > read on. > These functions (in string_util.h and gurl.h) are meant for a single, > specific use case: > const std::string& MyClass::foo() const { > return (everything == OK) ? member_string : EmptyString(); > } > Here you cannot return "string()", because it's destroyed before the > function returns, and the caller receives garbage; and you don't want to > have the function return by value, because you can access the member > variable directly and save a copy. The utility functions give you a global > empty string that you can safely return a const reference to. > DON'T USE THESE OUTSIDE THIS CASE. You should never use these as > initializers, arguments to functions, or return values in functions that > return by value. Just use the default constructor; that's what it's there > for.
Out of curiosity, what is wrong with using EmptyString() in those cases? Is there a correctness problem? Unnecessary inclusion of string_util.h? - a
-- Chromium Developers mailing list: chromium-dev@googlegroups.com View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev