Boost logo

Boost :

Subject: Re: [boost] [review] Convert library
From: Vladimir Batov (vb.mail.247_at_[hidden])
Date: 2014-05-25 00:51:31

Nelson, Erik - 2 wrote
> Vladimir Batov wrote on Saturday, May 24, 2014 9:40 PM
>>> Habraken wrote
>>> ...
>>> This still doesn't completely satisfy me as I'd like to write
>>> int i = boost::convert
> <int>
> ::from("23");
>>Again, I can't possibly stress more that the (deceivingly simple) usage
examples you insist on do not exist in real >applications -- they are
functionally-incomplete (as they do not handle all possible use-cases).
>>Still, with the post_review branch one can responsibly(!) write
>> int i = boost::convert
> <int>
> (str, cnv).value_or(-1);
> I can't possibly stress more that those cases do exist. I know that in my
> application, ...

Well, we seem to be playing that echo-chamber game. If so, then "I can't
possibly stress more that", if you read Jeroen's post and my reply again,
then you'll notice that he provided

int i = boost::lexical_cast<int>("23");
int j = boost::coerce::as<int>("23");

as the "benchmark" usage examples. I replied that those usage cases do not
exist because in real life they are rather uglier:

int i = -1;

try { i = boost::lexical_cast<int>(str); }
catch (...) {}

Then, you step in and say "... but such deployment does exist in my code
base... Convert "something" to "something else". If it doesn't work, throw
an exception."

Don't you describe my deployment example rather than Jeroen's?

> ... I almost never know some default value_or, so if the conversion
> doesn't work, I *want* an exception. Forcing the programmer to decide
> appropriate default values for every conversion isn't silly- I don't know,
> I just want a valid conversion or an exception.

I dare to ask, did not even bother reading "convert" docs? No one is
*forcing* you to do anything. If you *want* an exception, there is nothing
stopping you from having it.

    int i = boost::lexical_cast<int>(str);
    int j = boost::convert<int>(str, cnv).value();
catch(...) {}

> At any rate, I largely agree with Jeroen's points, and I find the Convert
> interface excessively complex. Specifically, if I have to create a
> conversion object that I then immediately pass as an argument to a
> conversion function, that seems excessively complex to me.

I am not sure how to answer this. Essentially you are saying that

    int i = boost::lexical_cast<int>(str);
    int j = boost::convert<int>(str, lex_cast_converter()).value();

is "too complex" and your particular deployment so far did not need any of
that additional "complexity".

I guess, what you perceive as complexity is the price one has to pay for
flexibility and wide applicability -- the qualities that we usually strive
to have in libraries.

View this message in context:
Sent from the Boost - Dev mailing list archive at

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