Boost logo

Boost :

Subject: Re: [boost] Boost review of the Convert library is ongoing
From: Vladimir Batov (Vladimir.Batov_at_[hidden])
Date: 2014-05-21 18:53:06


On 05/22/2014 01:54 AM, feverzsj wrote:
> hi, list
> here are some personal opinions/thoughts on the convert lib:
>
> 1. in most cases, I found directly use of the converter would be more
> convenient:
>
> int v = -1; // default value
> // no need to give the type of 'v'
> bool re = printf_converter()("123", v); // on failure, return
> false, and 'v' is untouched
>
> so, I suggest add a default convert function using a default converter:
>
> template<class Src, class Dst>
> bool convert(Src const& src, Dst& dst)
> {
> return default_converter()(src, dst);
> }

I am not the "list" ;-) but I'll take the liberty of replying. :-) I
feel that one particular message that I am trying to make just does not
make it. :-( It might be that my reasoning/idea behind that message is
wrong or I might be a bad messenger. Still, I'll try again.

Indeed, converters can be called directly. However, I advocate that
calling various conversions via one(!) familiar/known boost::convert()
interface ensures *known* behavior, better readability, better
adaptivity to requirement changes (when one needs to upgrade/replace
already deployed converter, etc.).

string res = lexical_cast<string>(foo);
string res = foo.str();

Above both are foo-to-string converters. Uhm, well, at least we *know*
that the first one *is* and we *guess* that the second one *might* be also.

IMO #1 is *instantly* recognizable and understood what it does and the
purpose of the call. As for #2 we might *guess* what it does but in
reality we do not know until we diverge and learn what foo.str()
*actually* does, what its caveats, etc.

> 2. besides the generic ones, sprintf/sscanf converter still lacks some
> format support from sprintf/sscanf:
> for example: auto-determined integer string, plus sign, padding, float
> point format, etc.
> with most formats being supported, this converter would be the most
> powerful, precise and efficient one;
>
> 3. printf_converter() uses snprintf(), while on msvc the return value
> semantic is not standard conform;
>
> 4. printf_converter() uses fixed length char buf, while it is totaly
> possible to remove this restrict with a standard conform snprintf();
>

I have not tried to provide full-blown converters. They all marked as
work-in-progress and proof-of-concept. For my every-day work I am
content with std::sstream-based one and I do not feel I have the
capacity to provide all imaginable converters... that was not the idea
anyway. So, if you feel some converter(s) is/are lacking in
functionality, please feel free to submit it/them. I'll gladly
incorporate and mention your contribution... well, if the "convert"
succeeds through this ongoing review... which you might have forgotten
to vote on... :-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk