Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-05-11 00:52:12


> Message du 11/05/11 01:18
> De : "Vladimir Batov"
> A : boost_at_[hidden]
> Copie à :
> Objet : Re: [boost] [review] string convert

> Something old. I am again having doubts if specializations will work well for
>
> struct convert
> {
> template to(S const&, identity::type const* =...);
> };

Maybe you should specialize the converter instead of the function to ;-) as c++ desn't allows to specialize the preceding schema.

> I did look at Vicente's approach and it still (as the original 'convert') boils
> down to the "tmpl<> class { tmpl<> func }" construct.

No. Boost.Conversion doesn't partially specialize the inner function.

> The problem is that some
> partial specializations are not such in the strict definition of the concept.
> Namely, string-to-type conversion of the original 'convert' had to be done (IMO)
> with 'enable_if' as it was not a partial specialization as such but rather a
> particular *implementation* for a group of string-related classes. Then,
> string-to-bool provided another implementation -- actual specialization --
> template<> struct convert. I am under impression that such a scenario will
> not work with the above (where T and S are together) as I suspect it won't work
> with Vicente's library either. In other words, I am again having suspicions that
> T and S need to be separated, i.e.
>
> template
> struct convert
> {
> template from(S const&, ...);
> };
>
> I guess, I need to find time to actually try it again.
>
> Vicente, if you are reading this, do you actually have a working example of
> semi-generic string-to-any-type "specialization" and, then string-to-bool
> complete specialization?

Boost.Conversion is based on two configuration points. First overloading of convert_to in a namespace reachable using ADL and second partial template specialization of a convert_to functor (with two type template parameters Target and Source) for the case where there are some issues with function template ordering or for std types (as we can not add any thing to the std namespace).

The library contains a lot of examples of partial specializations as for example the optional conversions. I have added a dummy complete specialization for std::string, bool and everything is OK.

Best,
Vicente


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