diff --git a/lexical_cast.htm b/lexical_cast.htm index 6b52fb5..1215a52 100644 --- a/lexical_cast.htm +++ b/lexical_cast.htm @@ -1,3 +1,4 @@ +
@@ -8,7 +9,7 @@lexical_cast
bad_lexical_cast
For instance, there are a number of limitations with the family of standard C
functions typified by atoi
:
-
lexical_cast
, the conventional
stringstream
approach is recommended. Where the conversions are
numeric to numeric, numeric_cast
- may offer more reasonable behavior than lexical_cast
- .
+ may offer more reasonable behavior than lexical_cast
.
For a good discussion of the options and issues involved in string-based
formatting, including comparison of stringstream
, lexical_cast
,
and others, see Herb Sutter's article,
- The String Formatters of Manor Farm
- .
+ The String Formatters of Manor Farm.
arg
into a std::stringstream
- and then out as a Target
object. Note that spaces are significant
- in any conversion and are not skipped. If the conversion is unsuccessful, a
- bad_lexical_cast
- exception is thrown.
+ Returns the result of streaming arg
into a
+ standard library string-based stream and then out as a Target
object.
+ Where Target
is either std::string
+ or std::wstring
, stream extraction takes the whole content
+ of the string, including spaces, rather than relying on the default
+ operator>>
behavior.
+ If the conversion is unsuccessful, a
+ bad_lexical_cast
exception is thrown.
The requirements on the argument and result types are: -
Source
is OutputStreamable, meaning that an operator<<
is defined that takes a std::ostream
or std::wostream
object on the
left hand side and an instance of the argument type on the right.
Source
and Target
are CopyConstructible [20.1.3].
- Target
is InputStreamable, meaning that an operator>>
is defined that takes a std::istream
or std::wistream
object on the left hand side
and an instance of the result type on the right.
Source
and Target
are CopyConstructible [20.1.3].
+ Target
is DefaultConstructible, meaning that it is possible
to default-initialize an object of that type [8.5, 20.1.4].
char
unless
- the either the Source
or the Target
type is wchar_t
- or a wide-character string type either wchar_t *
or std::wstring
- in which case wchar_t
is used.
+ either the Source
or the Target
requires wide-character
+ streaming, in which case the underlying stream uses wchar_t
.
+ Source
types that require wide-character streaming are wchar_t
,
+ wchar_t *
, and std::wstring
. Target
types that
+ require wide-character streaming are wchar_t
and std::wstring
.
Where a higher degree of control is required over conversions, std::stringstream
and std::wstringstream
offer a more appropriate path. Where non-stream-based conversions are
required, lexical_cast
- is the wrong tool for the job, and is not special-cased for such scenarios.
+ is the wrong tool for the job and is not special-cased for such scenarios.
bad_lexical_cast
lexical_cast
failure.
- +
lexical_cast
used the default stream precision for reading
+ and writing floating-point numbers. For numerics that have a corresponding specialization of
+ std::numeric_limits
, the current version now chooses a precision to match.
+ lexical_cast
did not support conversion to or from any
+ wide-character-based types. For compilers with full language and library support for wide characters,
+ lexical_cast
now supports conversions from wchar_t
, wchar_t *
,
+ and std::wstring
and to wchar_t
and std::wstring
.
+ lexical_cast
assumed that the conventional stream extractor
+ operators were sufficient for reading values. However, string I/O is asymmetric, with the result
+ that spaces play the role of I/O separators rather than string content. The current version fixes
+ this error for std::string
and, where supported, std::wstring
:
+ lexical_cast<std::string>("Hello, World")
succeeds instead of failing with
+ a bad_lexical_cast
exception.
+ lexical_cast
allowed unsafe and meaningless conversions to
+ pointers. The current version now throws a bad_lexical_cast
for conversions to pointers:
+ lexical_cast<char *>("Goodbye, World")
now throws an exception instead of
+ causing undefined behavior.
+