From: Terje Slettebø [mailto:tslettebo@chello.no]
From: "Tom Matelich"
I haven't gone and looked at the boost ml archives to track the reason for this down, but the addition of stream.unsetf(std::ios::skipws) in lexical_cast caused some of our code to fail. I've commented it out locally, and was wondering why it was decided this is more appropriate default behavior.
It was done to avoid the problems with throwing exceptions on whitespace. For example, without it, the following would throw a bad_lexical_cast:
lexical_caststd::string(' '); // A space character
What kind of code is the current version failing at?
We have some legacy files that are converted to xml through some process (I didn't write it) and it ends up with space-padded strings for ints. So the test case was dying converting " 86" to an int. I can see its purpose, except that example wouldn't happen because of the std::string overload, right? Tom ----------------------------------------------------------------------- DISCLAIMER: Information contained in this message and/or attachment(s) may contain confidential information of Zetec, Inc. If you have received this transmission in error, please notify the sender by return email. -----------------------------------------------------------------------
From: "Tom Matelich"
From: Terje Slettebø
From: "Tom Matelich"
I haven't gone and looked at the boost ml archives to track the reason for this down, but the addition of stream.unsetf(std::ios::skipws) in lexical_cast caused some of our code to fail. I've commented it out locally, and was wondering why it was decided this is more appropriate default behavior.
It was done to avoid the problems with throwing exceptions on whitespace. For example, without it, the following would throw a bad_lexical_cast:
lexical_caststd::string(' '); // A space character
What kind of code is the current version failing at?
We have some legacy files that are converted to xml through some process (I didn't write it) and it ends up with space-padded strings for ints. So the test case was dying converting " 86" to an int.
Ah, yes. After I read a similar report just now at the Boost list (reply copied here), I guessed it might be about the same thing, which it was.
I can see its purpose, except that example wouldn't happen because of the std::string overload, right?
Right. Apparently, the whitespace skipping only happens for reading _out_ of the stringstream, not into it. However, if the above example is turned around, then ir won't work (without whitespace skipping turned off): lexical_cast<char>(" "); Ironically, cases like the above example was a recurring error report, leading to this change. Regards, Terje
participants (2)
-
Terje Slettebø
-
Tom Matelich