Search the web
Sign In
New User? Sign Up
boost · C++ Boost
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
a lexical_cast<> bug?   Message List  
Reply | Forward Message #15023 of 27136 |
While I was working with the lexical_cast program under VC6 I noticed the
following (suprising) behaviour:

string s("123.456");
double d = lexical_cast<double>(s); // this will succeed
int i = lexical_cast<int>(s); // this will throw

It turns out that the lexical_cast to int will throw because the stream
operator into int stops at the decimal point. Therefore lexical cast says
that the int operator did not "succeed" because it did not read the full
string -- even though it reads the integer part of the string and
initializes the local result to 123 just fine. It's a bit of a surprise
from a user point of view that this fails. So the question is:
A. Is it intended that the class should throw in this case?
B. If it is intended / this kind of cast is not allowed it seems to me like
a strong warning in the docs should be added.

IMHO - given the documentation, my preference would be to modify
lexical_cast to support casting of a string to an int even when the string
contains a fractional part.






Fri Jul 20, 2001 11:37 pm

cjoy@...
Send Email Send Email

Forward
Message #15023 of 27136 |
Expand Messages Author Sort by Date

While I was working with the lexical_cast program under VC6 I noticed the following (suprising) behaviour: string s("123.456"); double d =...
Corwin Joy
cjoy@...
Send Email
Jul 20, 2001
11:38 pm

I believe this is the documented (and reasonable) behavior. You are really asking for 2 conversion from string->double and then from double to int with ...
Jeff Garland
jeff@...
Send Email
Jul 21, 2001
12:01 am

... From: "Jeff Garland" <jeff@...> To: <boost@yahoogroups.com> Sent: Friday, July 20, 2001 7:00 PM Subject: RE: [boost] a lexical_cast<>...
Corwin Joy
cjoy@...
Send Email
Jul 21, 2001
12:12 am

... I totally agree that these usage subtleties would make excellent additions to the documentation :-) Jeff...
Jeff Garland
jeff@...
Send Email
Jul 21, 2001
12:16 am

... [...] ... This is intentional behaviour. The original version of lexical_cast that was submitted truncated at the decimal point and should be considered ...
Kevlin Henney
kevlin@...
Send Email
Jul 21, 2001
5:50 pm

Hello, I recently discovered even more surprising behavior of lexical_cast (at least on VC++6sp4): locale::global(locale("german")); // ... int i = 12345; ...
Kostya Altukhov
kostya@...
Send Email
Jul 23, 2001
7:53 am

... From: "Kostya Altukhov" <kostya@...> To: <boost@yahoogroups.com> Sent: Monday, July 23, 2001 2:54 AM Subject: Re: [boost] a lexical_cast<> bug? ......
Corwin Joy
cjoy@...
Send Email
Jul 23, 2001
9:18 am

... This is almost but not quite the right conclusion. The only reason lexical_cast is broken using locales under VC is because locale support under VC is...
Kevlin Henney
kevlin@...
Send Email
Jul 27, 2001
12:03 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help