Boost logo

Boost :

Subject: Re: [boost] Review Request: Introduction of boost::string namespace and string-conversion functions
From: David Abrahams (dave_at_[hidden])
Date: 2009-02-11 16:53:21


on Wed Feb 11 2009, Andrey Semashev <andrey.semashev-AT-gmail.com> wrote:

> Vladimir.Batov_at_[hidden] wrote:
>> int i;
>> std::string s;
>>
>> 1) int i_from_s = boost::string::to<int>(s); // throws
>
> bs::to_string?

The above is converting a string to an int, so to_string would be
inappropriate. I.e. string::to and to_string are grammatically different.

>> 2) std::string s_from_i = boost::string::from<int>(i);
>
> bs::from_string?

Ditto. Plus, specifying int explicitly above is not only wasted, but
error-prone.

>> 3) bool s_is_i = boost::string::is<int>(i);
>
> I like the way it is.
>
>>
>> 7) int i_from_s = boost::string::to<int>(s)(-1)(std::hex)(yet-another-manipulator);
>
> Everything looks fine with me, except that I would suggest using a more explicit
> syntax for the default value specification. Like this:
>
> boost::string::to<int>(s).with_default(-1);

boost::string::to<int>(s, _default=-1)

?

see Boost.Parameter

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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