Boost logo

Boost :

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


On 05/18/2014 11:45 PM, Vladimir Batov wrote:
> Vladimir Batov <vb.mail.247 <at> gmail.com> writes:
>
>> Andrzej Krzemienski <akrzemi1 <at> gmail.com> writes:
>>
>>> I personally do not like this trick to force me to type this "from" in
>>> "convert<int>::from".
>> I just had another look and there seems no value anymore in potential
>> specializations on TypeIn, TypeOut. It's because all the "smartness" and
>> type-handling has been moved to converters. So, *there seems*, the "from"
>> can be dropped. That is,
>>
>> int v = boost::convert<int>(str, cnv).value();
>>
>> instead
>>
>> int v = boost::convert<int>::from(str, cnv).value();
>>
>> and
>>
>> std::transform(
>> strings.begin(),
>> strings.end(),
>> std::back_inserter(integers),
>> convert<int, string>(ccnv(std::hex)).value_or(-1));
>>
>> instead
>>
>> std::transform(
>> strings.begin(),
>> strings.end(),
>> std::back_inserter(integers),
>> convert<int>::from<string>(ccnv(std::hex)).value_or(-1));
>>
>> I am on the fence (the "from" has been with me for some time). Any
>> strong/weak :-) preferences, any for/against arguments?
>>

Given a few people were not happy with boost::convert::from() interface
I've added boost::cnv() for now (so that the names do not clash while
both exist).

     int v = boost::cnv<int>(str, cnv).value();

does look cleaner and somewhat similar to lexical_cast deployment (for
better or worse). However, I feel similarly confused about

     boost::cnv<int, string>(cnv).value_or(-1);

as I always felt about lexical_cast when I had to specify both types

     boost::lexical_cast<int, string>("char string");

compared to more explicit

     convert<int>::from<string>(cnv).value_or(-1);

I am easy about both ways and will go with whatever the majority settles
on. Any feelings/preferences/arguments for one or the other?


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