Boost logo

Boost :

Subject: Re: [boost] Convert library -- Andrzej's review
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2014-05-20 05:15:56


On May 20, 2014 12:34:01 AM EDT, Vladimir Batov <Vladimir.Batov_at_[hidden]> wrote:
>
>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 don't mind the clear separation of the input and output types, but if "from" can be avoided easily, do so.

>>> 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?

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

>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");

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?

>compared to more explicit
>
> convert<int>::from<string>(cnv).value_or(-1);

The ordering of the two types is logical, and each is closely coupled with what it affects (return type and parameter type), but the "from" form leaves no room for misinterpretation.

___
Rob

(Sent from my portable computation engine)


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