
anony wrote:
I'd like to do something like:
boost::uint16_t b(std::lexical_castboost::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