Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: Boost.Convert
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-02-19 13:45:26


Stewart, Robert wrote:
> On Thursday, February 19, 2009 2:57 AM
> Vladimir Batov wrote:
>> namespace boost
>> {
>> template<class TypeIn, class TypeOut, class Enable =void>
>> class convert;
>
> s/convert/converter/
>
>> int string_to_int = convert<string, int>(str, -1);
>
> int s2i(convert<int>(str, -1));
>
>> int string_to_int = convert<string, int>(str);
>
> s2i = convert<int>(str);
>
>> convert<string, int> string_to_int(str, -1);
>
> converter<string,int> c(str, -1);
>
>> convert<string, int> string_to_int = convert<string, int>(str, -1);
>
> c = convert<int>(str, -1);

I like it. Looks nice and clean.

>> std::transform(
>> integers.begin(),
>> integer.end(),
>> std::back_inserter(strings),
>> convert<string, int>::apply);
>
> s/convert/converter/

...and, I guess, converter< int, string > is more correct in this example.

It looks like the static "apply" will not allow to pass additional
conversion parameters, except by resorting to Boost.Bind or something
similar. Why not simply provide operator() in the converter? Then having
support of Boost.Parameter, we could pass some customization to the
converter constructor:

   std::transform(
          integers.begin(),
          integers.end(),
          std::back_inserter(strings),
          converter<int, string>(radix_ = 16, uppercase_ = true));


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