Boost logo

Boost :

Subject: Re: [boost] Convert library -- Andrzej's review
From: Vladimir Batov (Vladimir.Batov_at_[hidden])
Date: 2014-05-20 21:29:00


On 05/20/2014 07:15 PM, Rob Stewart wrote:

> I don't mind the clear separation of the input and output types, but
> if "from" can be avoided easily, do so.

Encouraged ;-) I could not resist the itch and got rid of "::from".
Updated the code and the docs.

> Shorter is better when clarity is not lost, but I'm unclear on the
> need to specify the input type.

Indeed, it's not needed as often. Still, sometimes we might want to
force a particular type:

     boost::cstringstream_converter cnv;

     boost::convert<string>(-1, cnv).value() == "-1";
     boost::convert<string, unsigned int>(-1, cnv).value() == 4294967295;

although one might argue for

     boost::convert<string>(uint(-1), cnv).value() == 4294967295;

So, I agree, the need to specify the input type is mute right now.

> > boost::cnv<int, string>(cnv).value_or(-1);
> > boost::lexical_cast<int, string>("char string");
> I haven't begun my review yet, though I intend to do so, so I might
> find the answer myself, but why is it necessary to specify "string" in
> that example? Can the converter be expected to understand a string
> literal as well as a std::string?

Indeed, that was a bad example and the explicit specification of in-type
was not necessary.


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