- lib:
boost/libs/lexical_cast
- repo:
boostorg/lexical_cast
- commit:
c519e650
, 2017-02-24
Header <boost/lexical_cast.hpp>
class bad_lexical_cast : public std::bad_cast;
template <typename Target, typename Source>
Target lexical_cast(const Source &);
template <typename Target>
Target lexical_cast(const [signed][unsigned] char*, std::size_t count);
template <typename Target, typename Source>
bool try_lexical_convert(const Source&, Target&);
template <typename Target, typename CharT>
bool try_lexical_convert(const CharT*, std::size_t, Target&);
-
lexical_cast
requireTarget
to be default-constructible and copy-constructible. -
bad_lexical_cast
is thrown bylexical_cast
when conversion failed. -
Direct assignment is performed when
Target
andSource
are- the same character type, or converting between
char
,signed char
orunsigned char
- the same
std::basic_string<CharT>
type, or from array/pointer ofCharT
tostd::basic_string<CharT>
- the same character type, or converting between
-
When both types are arithmetic types (except character types), perform checked converting
- When
Target
is unsigned, andSource
is signed or floating-point and< 0
, then negate the source - If the value will loss precision after convert, then conversion fail, otherwise assign to
Target
- When
-
Otherwise, perform
std::stringstream
based converting.- Recognize
Source
as character type, [const] pointer of,iterator_range
of,basic_string
of, andarray
of, for stage 1 type - Prefer using
stringstream
overwstringstream
, for stage 2 type - Defined optimized istream and ostream like classes providing
<<
and>>
for all primitive types - If unsupported by optimized stream-like types, use stringstream types.
- Recognize
<boost/config.hpp>
,<boost/detail/workaround.hpp>
<boost/limits.hpp>
<boost/static_assert.hpp>
<boost/noncopyable.hpp>
<boost/throw_exception.hpp>
<boost/mpl/if.hpp>
,<boost/mpl/bool.hpp>
<boost/mpl/identity.hpp>
,<boost/mpl/eval_if.hpp>
<boost/type_traits/is_arithmetic.hpp>
,<boost/type_traits/is_integral.hpp>
,<boost/type_traits/is_float.hpp>
<boost/type_traits/is_same.hpp>
,<boost/type_traits/is_base_of.hpp>
<boost/type_traits/is_signed.hpp>
,<boost/type_traits/make_unsigned.hpp>
<boost/type_traits/is_pointer.hpp>
,<boost/type_traits/is_abstract.hpp>
<boost/type_traits/has_left_shift.hpp>
,<boost/type_traits/has_right_shift.hpp>
<boost/math/special_functions/sign.hpp>
,<boost/math/special_functions/fpclassify.hpp>
<boost/numeric/conversion/cast.hpp>
<boost/integer.hpp>
<boost/integer_traits.hpp>
<boost/range/iterator_range_core.hpp>
<boost/array.hpp>
<boost/container/container_fwd.hpp>
- Proposals:
- N1973 - Lexical Conversion Library Proposal for TR2 (not accepted)
- P0117R0 - Generic
to_string
/to_wstring
functions