|
Boost : |
From: Stéphane Bronsart (stephane.bronsart_at_[hidden])
Date: 2002-07-03 02:47:13
Hi,
//--------------------------------------------------------------------------
--------------------------------------
A signed long can hold value from -2147483648 to 2147483647
signed long l;
1) l=lexical_cast<signed long>("2147483647"); // Ok l = 2147483647
2) l=lexical_cast<signed long>("2147483648"); // False : no exception
and l = -2147483648
3) l=lexical_cast<signed long>("2147483650"); // OK exception occurs
!!!
Why case 2 don't throw exception and case 3 yes ?
If lexical_cast throw exption with a value 3 unit greater than the limit,
why not with a value 1 greater than the limit ?
//--------------------------------------------------------------------------
--------------------------------------
User had to know that :
signed short i = 60000;
produce a fault value in i.
This behavior is in the C/C++ documentation
Thus I'm agree with you that lexical_cast had to clearly explain WHAT it can
do...
//--------------------------------------------------------------------------
--------------------------------------
My modified lexical_cast is not optimized you said.
I'm agree with you, but generaly I prefer a non-optimized solution which
work (I don't talk about lexical_cast here ) without ambiguity again an
optimized solution with "limit" case and/or undefined result in some (rare)
situation.
//--------------------------------------------------------------------------
--------------------------------------
Don't you think it's time now to :
1) Review lexical_cast implementation and/or documentation : You are the
best guy to do that.
And/Or
2) Provide via boost a "specialized" lexical_cast like feature to perform
well "numeric to string" ONLY and vice/versa convertion.
I'm new in the C/C++ worls, but i seems me crazy that a so used operation is
not yet fixed in the language (or in a "standard" library). All the
programmers around the world had to perform string/integer conversion. It
must be possible to perform this task without using a strstream (heavy).
The final solution, for me, is a "specialized" conversion routine/template
dedicated to string/integer conversion.
//--------------------------------------------------------------------------
--------------------------------------
Regards.
Steph.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk