|
Boost Users : |
Subject: Re: [Boost-users] boost::lexical_cast<> with hex strings?
From: Michael Caisse (boost_at_[hidden])
Date: 2010-07-15 15:04:43
anony wrote:
> I'd like to do something like:
>
> boost::uint16_t b(std::lexical_cast<boost::uint16_t>("xa"));
>
> I have no control of the string stream that lexical_cast uses
> internally, so how could I implement this?
>
> P.S.: There are a lot of false statements made about this functionality
> on the web, some people claim that boost::lexical_cast<> can do the
> conversion out of the box, but this is not so in my tests.
>
> _______________________________________________
>
Long ago I made this change in a vendor drop of boost. It worked well
for me then; however, I have replaced all of my string conversions with
qi/karma semantics since.
I personally think this should be the default behavior in lexical_cast.
The diff is from 1.37.0 IIRC but I don't think lexical_cast changes much.
hth
michael
Index: trunk/firmware/vendor/boost/boost/lexical_cast.hpp
===================================================================
--- trunk/firmware/vendor/boost/boost/lexical_cast.hpp (revision 582)
+++ trunk/firmware/vendor/boost/boost/lexical_cast.hpp (revision 632)
@@ -571,4 +571,5 @@
{
stream.unsetf(std::ios::skipws);
+ stream.setf( std::ios::fmtflags(), std::ios::basefield );
lcast_set_precision(stream, (Source*)0, (Target*)0);
}
@@ -758,4 +759,5 @@
std::basic_istream<CharT> stream(static_cast<Base*>(this));
stream.unsetf(std::ios::skipws);
+ stream.setf( std::ios::fmtflags(), std::ios::basefield );
lcast_set_precision(stream, (InputStreamable*)0);
#if (defined _MSC_VER)
-- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net