On May 20, 2014 12:34:01 AM EDT, Vladimir Batov
On 05/18/2014 11:45 PM, Vladimir Batov wrote:
Vladimir Batov
writes: Andrzej Krzemienski
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
(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
(cnv).value_or(-1); as I always felt about lexical_cast when I had to specify both types
boost::lexical_cast
("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)