|
Boost : |
Subject: Re: [boost] [Conversion] Review
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2011-08-29 11:42:54
2011/8/28 Vicente J. Botet Escriba <vicente.botet_at_[hidden]>:
> Le 28/08/11 09:43, Antony Polukhin a écrit :
>> * What is your evaluation of the design?
>>
>> It is simple and looks good. But consider the following situation:
>> lexical_cast<char>(1) and numeric_cast<char>(1) will produce output.
>> It must be documented, which cast will your library use in which
>> cases.
>
> The documentation of header <boost/conversion/std/string.hpp> includes
> "Include this file when using conversions from/to |std::string| via
> |lexical_cast|. "
And that`s were the problems begin! If user included this header, all
his conversion will convert convert_to<char>(1) as lexical cast does?
And what if the user whants conversions, like numeric cast does?
More examples: Two developers are working on different parts of
project. Developer #1 uses convert_to<char>(1) in his code and wants
behavior like numeric_cast. He also uses some headers, which is
maintained by Developer #2. At one day Developer #2 includes
<boost/conversion/std/string.hpp> in one of his headers. And we get
really hard detectable errors!
>> There must be some tags, to allow user to choose, which conversion is
>> required. There are some dummy::type_tag tags in source code, but
>> looks like they are not used, and not documented!
>
> They are used to overload the conversion functions. The class is documented
> here
> https://svn.boost.org/svn/boost/sandbox/conversion/libs/conversion_ext/doc/html/boost/conversion/dummy/type_tag.html.
> This
> https://svn.boost.org/svn/boost/sandbox/conversion/libs/conversion_ext/doc/html/boost/conversion/users_guide.html#boost.conversion.users_guide.tutorial.how_to_specialize_extrinsic_conversions_
> tutorial section explains how to use it.
I could not determinate, for what are this tags used from the
documentation. Can we use them, to call numeric_cast instead of
lexical_cast? Can we use them, to call Boost.Coerce instead of
lexical_cast? can we use them, to support some parameters for
Boost.Coerce?
> Could you elaborate on how you see the library can use these tags?
Some thing like this:
convert_to<char>(1, numeric_tag);
convert_to<char>(1, coerence_base<16>);
convert_to<pair<char, char> >(make_pair(1,1), lexical_tag);
convert_to<double>(1); // We can also convert without tags
Best regards,
Antony Polukhin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk