Boost logo

Boost :

Subject: Re: [boost] Convert library -- Andrzej's review
From: Vladimir Batov (vb.mail.247_at_[hidden])
Date: 2014-05-18 09:45:50


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".
>
> It's been a while and OTOH I do not remember what/how it was exactly but the
> main purpose of "from" is to separate TypeIn from TypeOut. Not
>
> template<class TypeOut, class TypeIn, class Converter>
> optional<TypeOut> convert(TypeIn, Converter)
>
> but
>
> template<class TypeOut>
> struct convert
> {
> static optional<TypeOut> from(TypeIn, Converter);
> }
>
> That way (at least I felt so back then) it was the only way to provide the
> ability to *reliably* specialize separately on TypeIn and/or TypeOut. Again,
> maybe that original decision/design is not valid or important and needs to
> be revisited.

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?


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