|
Boost Users : |
From: Terje Slettebų (terje.s_at_[hidden])
Date: 2002-05-22 15:46:02
>--- In Boost-Users_at_y..., Tom Matelich <tmatelich_at_z...> wrote:
> I and many others have requested fixes for this for a very long time.
> Basically, it involves creating class templates to do the actual
conversion.
> It's not the most complicated system, just nobody has done it yet. If you
> search the boost list archives, you'll see a lot of mail about this.
There
> is no quick solution to your problem though.
I've searched the archive, now, and see that there's been quite a few
propositions for changes, but apparently none of them have ended up in the
lexical_cast implementation.
There's also a couple of propositions, here
(http://groups.yahoo.com/group/boost/files/lexical_cast_propositions/).
Some of the proposed changes are:
- wlexical_cast - A version that can use wide characters
- basic_lexical_cast - A version that takes the interpreter (stringstream)
as a parameter, to support things like changing locale
- Being able to set number base (dec, oct or hex). This would be implicitly
possible using basic_lexical_cast
- Being able to set precision for numerical conversions. This may also be
done with basic_lexical_cast
- Checking for change of sign, when using unsigned numbers. This is
addressed using an integer adapter, in the above lexical_cast_propositions
One problem with doing these changes, after having talked with Kevlin Henney
a while ago (without knowing it had been already proposed, I proposed an
extra parameter, for setting the number base). is that he prefers to not
have extra parameters in the interface, as it then will no longer look like
a cast, and it may be less generic, depending on the way it's done. For
example, a base-setting argument wouldn't make much sense if you converted
from floating point to string.
In any case, I have actually just now made a version of lexical_cast, that
fixes the problem pointed out by OP, here, and I've made it available in the
Boost files section
(http://groups.yahoo.com/group/boost/files/lexical_cast_proposition/). I've
also put a unit test for it, there. Feedback is welcome.
It doesn't change the interface in any way, so it should be ok.
The new version supports conversion between string and char, including char
containing whitespace, and when the string is empty, or containing only
whitespace.
If the source or destination (or both) is basic_string or char/wchar_t, it
will set the interpreter to use the char type used, so it implicitely
supports wide characters. Wide character support requires partial
specialisation if one of the operands is not either basic_string or
char/wchar_t.
In the case where the source is basic_string, it also uses pass by const
reference, for efficiency.
It's tested on Intel C++ 6.0, MSVC 6.0 and BCC 5.6.
Regards,
Terje
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net