
on Wed Feb 18 2009, "Vladimir Batov" <batov-AT-people.net.au> wrote:
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.
Not just a nuisance; it reads incorrectly, as "convert to -1." I think it would be better to always require the destination type, so: boost::convert::to<string>(-1, "not convertible"); and using boost::convert::to; to<string>(-1, "not convertible); looks good, too. If you want a name without angle brackets, boost::convert::to_string(-1, "not convertible"); works for me. Hmm, how do I convert to a hex string? -- Dave Abrahams BoostPro Computing http://www.boostpro.com