Boost logo

Boost :

Subject: Re: [boost] [convert] Now with Boost.Parameter interface.
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-07-04 16:23:30


Hi,
----- Original Message -----
From: "Gottlob Frege" <gottlobfrege_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, July 02, 2009 6:55 PM
Subject: Re: [boost] [convert] Now with Boost.Parameter interface.

On Thursday, July 2, 2009, Scott McMurray <me22.ca+boost_at_[hidden]> wrote:
> 2009/7/2 Stewart, Robert <Robert.Stewart_at_[hidden]>:
>>
>> Why not with the syntax Dave has been suggesting:
>>
>> converter<int>(locale_ = loc, throw_ = true).from(str, 0);
>>
>
> To me, that's the nicest one yet proposed.
>

I think that the only complaint was that it limits the number of
params, whereas the other version does not. But if you have more than
10 params, I think you have bigger problems.

> And it'd be quite reasonable, instead of statics, to just use

I didn't see that as a static, but as a constructor call.

> convert<int>().from(str, 0), since that's already common from function
> objects.
>
> And actually, why not spell from() as operator(), so it can be a
> proper function object?
>
> transform( istream_iterator<string>(cin), istream_iterator<string>(),
> back_inserter(v), convert<int>(locale_ = loc, base_ = 16, throw_ =
> false, default_ = 0));

I have followed this thread and I would like to share with you my view. IMO we need a converter function and a convert free function that returns the To type. With the interface below we should be able to

* make a conversion using a default converter (which could throw if the conversion fails)

int i = convert<int>(str);

* make a conversion using a specific converter constructed form these coverter parameters

int i=convert<int>(str, (locale_ = loc, base_ = 16, throw_ = false, default_ = 0));

Note that we can also have

int i=convert<int>(str, (locale_ = loc)(base_ = 16)(throw_ = false)(default_ = 0));

if the converter_parameters defines the operator().

* transform using a converter functor

transform( istream_iterator<string>(cin), istream_iterator<string>(),
back_inserter(v), converter<int>((locale_ = loc, base_ = 16, throw_ =
false, default_ = 0)));

The class converter_parameters is used to store all the parameters related to the conversion. It should be close to the internal representation of the current converter convert_detail::implementation<TypeIn, TypeOut> but without the TypeIn

template <typename To>
class converter_parameters {
...
}

The converter class is the functor class realizing the conversion using the conversion parameters
template <typename To>
class converter {
    converter();
    converter(converter_parameters<To> const&);
    template <typenam From> To operator()(From);
};

the convert function now return the out type (To) and not a converter

template <typename To, typename From>
To convert(From f, converter<To> const&cv) {
    return cv(f);
}

template <typename To, typename From>
To convert(From f, converter_parameters<To> const&cvp) {
    converter<To> cv(cvp);
    return convert(f, cv);
}

template <typename To, typename From>
To convert(From f) {
    converter<To> cv;
    return convert(f, cv)
}

I dont' think the current implementation needs to much changes to be adapted to this proposal.

HTH,
Vicente


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