|
Boost : |
Subject: Re: [boost] Formal Review Request: Boost.String.Convert
From: Vladimir Batov (batov_at_[hidden])
Date: 2009-02-18 06:55:55
>> convert::to<wstring>
>
> Why not just convert_to<wstring>?
>
> Is the problem with convert by itself that it leaves the reader worrying
> about 'to' and/or 'from'?
>
> - leaving one feeling 'what?'
>
> Direction matters.
Yes, once I got comfortable with boost::convert::to I realized that after
generalization the 'from' is obviously redundant as string-from-int can
always be transformed to int-to-string. So, 'from' died out. When only 'to'
left, I asked myself what it was doing on its own.
I do agree in principle that having direction helps (even only somewhat) but
'to' does not seem to work. It all starts nicely:
string s = boost::convert::to<int>(-1)
Above 'to' does seem natural (IMHO of course) as the line kind of reads as
"convert to int". However, with the default parameter it becomes
string s = boost::convert::to(-1, "failed to convert")
i.e. 'to' becomes a nuisance. In that setting I much prefer
string s = boost::convert(-1, "failed to convert")
which answers the "convert what" question as it reads as "convert int".
Granted, the conversion destination becomes somewhat subtle. However, I do
not feel it is too subtle to get one confused. More so, I feel the convert
family is well discriminated (with enable_if) so that
Wstring WIDE_str = boost::convert(-1, "failed to convert")
will not compile. Therefore, I feel very safe with just
string s = boost::convert(-1, "failed to convert").
That thought took me all the way from boost::string::convert() to
boost::convert(). That looks like a reasonable and logical compromise which
might not be as nice as "convert::to<int>" but overall holds better. I am OK
with that. Others..?
V.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk