|
Boost : |
Subject: Re: [boost] Boost.Convert+Boost.Parameter
From: Vladimir Batov (batov_at_[hidden])
Date: 2009-02-28 03:22:08
> "Andrey Semashev" <andrey.semashev_at_[hidden]> wrote
> convert< string >((param1 = val1, param2 = val2, ...));
Andrey,
I started playing with your example integrating it in to the conversion
framework and managed to get it working. Thank you for the example and that
parameter_type extension. The whole thing seems to rely on that facility.
Well, the interface I am using (without Boost.Parameter) is
int i = convert::to<int>(str);
int i = convert::from(str, -1);
(almost what I initially started from :-) ) I tried to get rid of 'to&from'
(several times) but in the end decided I needed to keep the two variations
as the 'from' deduces both (TypeIn, TypeOut) parameters from the signature
when the 'to' requires TypeOut explicitly specified. Having both named
convert() reads wrong for the 'to' specialization:
int i = convert<int>(str);
and I could not stand it. Another option would be to ditch 'to' altogether
but I am not sure how it might be taken. Also I tried deducing TypeOut
parameter for 'to' as well via
template<class TypeIn>
implementation
{
template<class TypeOut> operator TypeOut()
};
but did not get too far either.
Well, I digressed from my original post about Boost.Parameter as I did not
want us to get bogged down with convert::to and convert::from again (and BTW
you cannot shortcut them so they are very much like convert_to,
convert_from). OK. What I got working (thanks to your help) is
int i = convert::to<int>(str, radix_ = 10);
int i = convert::from(str, default_ = -1);
int i = convert::from(str, (default_ = -1, radix_ = 10));
I understand the benefits of passing additional conversion parameters like
'radix_ = 10' down to the conversion *implementation*. However, I feel these
parameters are of no value (and not accessible) to the "casual" user (as
opposed to the conversion implementer)... unlike I/O Stream-based approach
which allows the user to write his own manipulator and deploy it like
int i = convert::from(str, -1) >> my_special_formatter;
Is my understanding correct or you have some ideas of getting that *user*
extensibility with Boost.Parameter?
Secondly, I kinda like the explicitness of
int i = convert::from(str, default_ = -1);
however, does it really add much (apart from verbosity) compared with
int i = convert::from(str, -1);
I do not feel the above line is the trickiest in the whole Boost so that we
need to get out of our way to spell out every damn thing. What do you think?
That leads me to my question. Would that be sensible to have it as follows:
int i = convert::to<int>(str, (radix_ = 10, locale_= ...));
int i = convert::from(str, -1, (radix_ = 10, locale_= ...));
or you might have something else in mind?
Best,
V.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk