[Home]LexicalCast

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

Difference (from prior major revision) (no other diffs)

Changed: 1c1,29
http://feisinthedesert.org/images/ticket/broker-sizzla-ticket.html broker sizzla ticket http://feisinthedesert.org/images/ticket/air-cheap-ticket.html air cheap ticket http://feisinthedesert.org/images/ticket/anthrax-concert-ticket.html anthrax concert ticket http://feisinthedesert.org/images/ticket/corrs-concert-ticket.html corrs concert ticket
/Version2 Proposal


http://www.boost.org/libs/conversion/lexical_cast.htm


A nice addition would be a to_string which would not stop parsing when hitting white space of a string. Take a look at the following discussion threads on this topic.

http://lists.boost.org/MailArchives/boost/msg23687.php

http://lists.boost.org/MailArchives/boost/msg23923.php

http://lists.boost.org/MailArchives/boost/msg24086.php




Personally I use this in my c++ wrapper around libxml2 for convenience of putting data types into my attributes or data of nodes.

Caveats:
* If the input is a string, it must not be empty and it must not have spaces. At some point in the future, there will be a string -> string specialization which may help you with this problem.
** I think it's okay to have spaces in the string, if the spaces will be eaten by the casted - to type's operator<<. This isn't true for any of the built-in types, of course, but it might be true for user classes. Extra spaces (or any other chars) on the end are no-nos, though.



I (People/Jeff Garland) have also used lexical cast for xml related conversions. A number of us have run across some edges with this library.

One issue with the library is the handling of doubles being truncated due to the default precision setting of the stream. This doesn't throw an exception, but doesn't give the right correct result either.
std::string s(1.123456789);
double d = lexical_cast<double>(s); //oops truncated due to precision of std::stringstream

You can see this message for more discussion
http://groups.yahoo.com/group/boost/message/15025

/Version2 Proposal
http://www.boost.org/libs/conversion/lexical_cast.htm
A nice addition would be a to_string which would not stop parsing when hitting white space of a string. Take a look at the following discussion threads on this topic.

http://lists.boost.org/MailArchives/boost/msg23687.php

http://lists.boost.org/MailArchives/boost/msg23923.php

http://lists.boost.org/MailArchives/boost/msg24086.php


Personally I use this in my c++ wrapper around libxml2 for convenience of putting data types into my attributes or data of nodes.

Caveats:


I (People/Jeff Garland) have also used lexical cast for xml related conversions. A number of us have run across some edges with this library.

One issue with the library is the handling of doubles being truncated due to the default precision setting of the stream. This doesn't throw an exception, but doesn't give the right correct result either.

 std::string s(1.123456789);
 double d = lexical_cast<double>(s);  //oops truncated due to precision of std::stringstream

You can see this message for more discussion http://groups.yahoo.com/group/boost/message/15025


BOOST WIKI | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited September 23, 2008 6:49 am (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers