Boost logo

Boost :

Subject: Re: [boost] construe_cast, call for interest and feedback
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2010-10-08 08:18:41

> Secondly, since this
> release, boost::construe_cast<std::string, tag::bin>(23) resulting in
> a std::string("10111") and visa versa. The user has the ability to add
> functionality here by implementing extra tags, by default tag::bin,
> tag::oct and tag::hex are implemented, with more to follow.

I use boost::lexical_cast for conversions from string. For conversions to
string I rarely use boost::lexical_cast. Most of the time I need formated
conversions, and I use boost::format:

lexical_cast<int>( "12" )
lexical_cast<string>( 12 )
str( format("0x%04x") % 12 )

When I need control over output format, I usually need more then just
tag::hex, etc., and I like the printf/boost::format syntax for it. The
alternative I dislike:
( ostringstream() << "0x" << hex << setw(4) << setfill('0') << 12 ).str()

Once I experienced having to fall back from boost::format to sprintf for
efficiency reasons.

1. For conversions from string I consider lexical_cast<T>( string )
sufficient, but I can imagine efficiency can be improved - if mesurements
say so.
2. For unformated conversions to string: same as point 1.
3. For formated conversions to string: a more efficient boost::format would
be something I would like to see (just a user's point of view, I have no
idea how this could be implemented).


Boost list run by bdawes at, gregod at, cpdaniel at, john at