forked from boostorg/conversion
Merge lexical_cast from trunk :
* force SunCC compiler to use fallback version of lexical_cast (with fallbak version SunCC can pass at least some tests) * removed trailing whitespaces [SVN r78565]
This commit is contained in:
@@ -6,9 +6,9 @@ using quickbook ;
|
|||||||
import boostbook : boostbook ;
|
import boostbook : boostbook ;
|
||||||
|
|
||||||
xml lexical_cast : lexical_cast.qbk ;
|
xml lexical_cast : lexical_cast.qbk ;
|
||||||
boostbook standalone
|
boostbook standalone
|
||||||
:
|
:
|
||||||
lexical_cast
|
lexical_cast
|
||||||
:
|
:
|
||||||
<xsl:param>boost.root=../../../..
|
<xsl:param>boost.root=../../../..
|
||||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
||||||
|
@@ -34,7 +34,7 @@ The standard C++ library offers `stringstream` for the kind of in-core formattin
|
|||||||
|
|
||||||
The `lexical_cast` function template offers a convenient and consistent form for supporting common conversions to and from arbitrary types when they are represented as text. The simplification it offers is in expression-level convenience for such conversions. For more involved conversions, such as where precision or formatting need tighter control than is offered by the default behavior of `lexical_cast`, the conventional `std::stringstream` approach is recommended. Where the conversions are numeric to numeric, __numericcast__ may offer more reasonable behavior than `lexical_cast`.
|
The `lexical_cast` function template offers a convenient and consistent form for supporting common conversions to and from arbitrary types when they are represented as text. The simplification it offers is in expression-level convenience for such conversions. For more involved conversions, such as where precision or formatting need tighter control than is offered by the default behavior of `lexical_cast`, the conventional `std::stringstream` approach is recommended. Where the conversions are numeric to numeric, __numericcast__ 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, [@http://www.gotw.ca/publications/mill19.htm The String Formatters of Manor Farm]. Also, take a look at the [link boost_lexical_cast.performance Performance] section.
|
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, [@http://www.gotw.ca/publications/mill19.htm The String Formatters of Manor Farm]. Also, take a look at the [link boost_lexical_cast.performance Performance] section.
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section Examples]
|
[section Examples]
|
||||||
@@ -105,8 +105,8 @@ The character type of the underlying stream is assumed to be `char` unless eithe
|
|||||||
* `boost::iterator_range<WideCharPtr>`, where `WideCharPtr` is a pointer to wide-character or pointer to const wide-character
|
* `boost::iterator_range<WideCharPtr>`, where `WideCharPtr` is a pointer to wide-character or pointer to const wide-character
|
||||||
|
|
||||||
[important Many compilers and runtime libraries fail to make conversions using new Unicode characters. Make shure that the following code compiles and outputs nonzero values, before using new types:
|
[important Many compilers and runtime libraries fail to make conversions using new Unicode characters. Make shure that the following code compiles and outputs nonzero values, before using new types:
|
||||||
``
|
``
|
||||||
std::cout
|
std::cout
|
||||||
<< booat::lexical_cast<std::u32string>(1.0).size()
|
<< booat::lexical_cast<std::u32string>(1.0).size()
|
||||||
<< " "
|
<< " "
|
||||||
<< booat::lexical_cast<std::u16string>(1.0).size();
|
<< booat::lexical_cast<std::u16string>(1.0).size();
|
||||||
@@ -151,13 +151,13 @@ Consider the following example:
|
|||||||
return data_length;
|
return data_length;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator << (std::ostream& ostr, const example_class& rhs) {
|
inline std::ostream& operator << (std::ostream& ostr, const example_class& rhs) {
|
||||||
return ostr << boost::make_iterator_range(rhs.data(), rhs.data() + rhs.size());
|
return ostr << boost::make_iterator_range(rhs.data(), rhs.data() + rhs.size());
|
||||||
}
|
}
|
||||||
``
|
``
|
||||||
|
|
||||||
This is a good generic solution for most use cases.
|
This is a good generic solution for most use cases.
|
||||||
But we can make it even faster for some performance critical applications. During conversion, we loose speed at:
|
But we can make it even faster for some performance critical applications. During conversion, we loose speed at:
|
||||||
|
|
||||||
* `std::ostream` construction (it makes some heap allocations)
|
* `std::ostream` construction (it makes some heap allocations)
|
||||||
@@ -182,35 +182,35 @@ Now `boost::lexical_cast<some_type>(example_class_instance)` conversions won't c
|
|||||||
[section Frequently Asked Questions]
|
[section Frequently Asked Questions]
|
||||||
|
|
||||||
* [*Question:] Why does `lexical_cast<int8_t>("127")` throw `bad_lexical_cast`?
|
* [*Question:] Why does `lexical_cast<int8_t>("127")` throw `bad_lexical_cast`?
|
||||||
* [*Answer:] The type `int8_t` is a `typedef` to `char` or `signed char`. Lexical conversion to these types is simply reading a byte from source but since the source has more than one byte, the exception is thrown.
|
* [*Answer:] The type `int8_t` is a `typedef` to `char` or `signed char`. Lexical conversion to these types is simply reading a byte from source but since the source has more than one byte, the exception is thrown.
|
||||||
Please use other integer types such as `int` or `short int`. If bounds checking is important, you can also
|
Please use other integer types such as `int` or `short int`. If bounds checking is important, you can also
|
||||||
call __numericcast__:
|
call __numericcast__:
|
||||||
`numeric_cast<int8_t>(lexical_cast<int>("127"));`
|
`numeric_cast<int8_t>(lexical_cast<int>("127"));`
|
||||||
|
|
||||||
[pre
|
[pre
|
||||||
]
|
]
|
||||||
|
|
||||||
* [*Question:] Why does `lexical_cast<unsigned char>("127")` throw `bad_lexical_cast`?
|
* [*Question:] Why does `lexical_cast<unsigned char>("127")` throw `bad_lexical_cast`?
|
||||||
* [*Answer:] Lexical conversion to any char type is simply reading a byte from source. But since the source has more than one byte, the exception is thrown.
|
* [*Answer:] Lexical conversion to any char type is simply reading a byte from source. But since the source has more than one byte, the exception is thrown.
|
||||||
Please use other integer types such as `int` or `short int`. If bounds checking is important, you can also
|
Please use other integer types such as `int` or `short int`. If bounds checking is important, you can also
|
||||||
call __numericcast__:
|
call __numericcast__:
|
||||||
`numeric_cast<unsigned char>(lexical_cast<int>("127"));`
|
`numeric_cast<unsigned char>(lexical_cast<int>("127"));`
|
||||||
|
|
||||||
[pre
|
[pre
|
||||||
]
|
]
|
||||||
|
|
||||||
* [*Question:] What does `lexical_cast<std::string>` of an `int8_t` or `uint8_t` not do what I expect?
|
* [*Question:] What does `lexical_cast<std::string>` of an `int8_t` or `uint8_t` not do what I expect?
|
||||||
* [*Answer:] As above, note that int8_t and uint8_t are actually chars and are formatted as such. To avoid
|
* [*Answer:] As above, note that int8_t and uint8_t are actually chars and are formatted as such. To avoid
|
||||||
this, cast to an integer type first: `lexical_cast<std::string>(static_cast<int>(n));`
|
this, cast to an integer type first: `lexical_cast<std::string>(static_cast<int>(n));`
|
||||||
|
|
||||||
[pre
|
[pre
|
||||||
]
|
]
|
||||||
|
|
||||||
* [*Question:] The implementation always resets the `ios_base::skipws` flag of an underlying stream object.
|
* [*Question:] The implementation always resets the `ios_base::skipws` flag of an underlying stream object.
|
||||||
It breaks my `operator>>` that works only in presence of this flag. Can you remove code that resets the flag?
|
It breaks my `operator>>` that works only in presence of this flag. Can you remove code that resets the flag?
|
||||||
* [*Answer:] May be in a future version. There is no requirement in
|
* [*Answer:] May be in a future version. There is no requirement in
|
||||||
__proposallong__ to reset the flag but
|
__proposallong__ to reset the flag but
|
||||||
remember that __proposalshort__ is not yet accepted by the committee. By the way, it's a great opportunity to
|
remember that __proposalshort__ is not yet accepted by the committee. By the way, it's a great opportunity to
|
||||||
make your `operator>>` conform to the standard.
|
make your `operator>>` conform to the standard.
|
||||||
Read a good C++ book, study `std::sentry` and [@boost:libs/io/doc/ios_state.html `ios_state_saver`].
|
Read a good C++ book, study `std::sentry` and [@boost:libs/io/doc/ios_state.html `ios_state_saver`].
|
||||||
|
|
||||||
@@ -218,17 +218,17 @@ Read a good C++ book, study `std::sentry` and [@boost:libs/io/doc/ios_state.html
|
|||||||
]
|
]
|
||||||
|
|
||||||
* [*Question:] Why `std::cout << boost::lexical_cast<unsigned int>("-1");` does not throw, but outputs 4294967295?
|
* [*Question:] Why `std::cout << boost::lexical_cast<unsigned int>("-1");` does not throw, but outputs 4294967295?
|
||||||
* [*Answer:] `boost::lexical_cast` has the behavior of `std::stringstream`, which uses `num_get` functions of
|
* [*Answer:] `boost::lexical_cast` has the behavior of `std::stringstream`, which uses `num_get` functions of
|
||||||
`std::locale` to convert numbers. If we look at the Programming languages — C++, we'll see, that `num_get` uses
|
`std::locale` to convert numbers. If we look at the Programming languages — C++, we'll see, that `num_get` uses
|
||||||
the rules of `scanf` for conversions. And in the C99 standard for unsigned input value minus sign is optional, so
|
the rules of `scanf` for conversions. And in the C99 standard for unsigned input value minus sign is optional, so
|
||||||
if a negative number is read, no errors will arise and the result will be the two's complement.
|
if a negative number is read, no errors will arise and the result will be the two's complement.
|
||||||
|
|
||||||
[pre
|
[pre
|
||||||
]
|
]
|
||||||
|
|
||||||
* [*Question:] Why `boost::lexical_cast<int>(L'A');` outputs 65 and `boost::lexical_cast<wchar_t>(L"65");` does not throw?
|
* [*Question:] Why `boost::lexical_cast<int>(L'A');` outputs 65 and `boost::lexical_cast<wchar_t>(L"65");` does not throw?
|
||||||
* [*Answer:] If you are using an old version of Visual Studio or compile code with /Zc:wchar_t- flag,
|
* [*Answer:] If you are using an old version of Visual Studio or compile code with /Zc:wchar_t- flag,
|
||||||
`boost::lexical_cast` sees single `wchar_t` character as `unsigned short`. It is not a `boost::lexical_cast` mistake, but a
|
`boost::lexical_cast` sees single `wchar_t` character as `unsigned short`. It is not a `boost::lexical_cast` mistake, but a
|
||||||
limitation of compiler options that you use.
|
limitation of compiler options that you use.
|
||||||
|
|
||||||
[pre
|
[pre
|
||||||
@@ -236,7 +236,7 @@ limitation of compiler options that you use.
|
|||||||
|
|
||||||
* [*Question:] Why `boost::lexical_cast<double>("-1.#IND");` throws `boost::bad_lexical_cast`?
|
* [*Question:] Why `boost::lexical_cast<double>("-1.#IND");` throws `boost::bad_lexical_cast`?
|
||||||
* [*Answer:] `"-1.#IND"` is a compiler extension, that violates standard. You shall input `"-nan"`, `"nan"`, `"inf"`
|
* [*Answer:] `"-1.#IND"` is a compiler extension, that violates standard. You shall input `"-nan"`, `"nan"`, `"inf"`
|
||||||
, `"-inf"` (case insensitive) strings to get NaN and Inf values. `boost::lexical_cast<string>` outputs `"-nan"`, `"nan"`,
|
, `"-inf"` (case insensitive) strings to get NaN and Inf values. `boost::lexical_cast<string>` outputs `"-nan"`, `"nan"`,
|
||||||
`"inf"`, `"-inf"` strings, when has NaN or Inf input values.
|
`"inf"`, `"-inf"` strings, when has NaN or Inf input values.
|
||||||
|
|
||||||
* [*Question:] What is the fastest way to convert a non zero terminated string or a substring using `boost::lexical_cast`?
|
* [*Question:] What is the fastest way to convert a non zero terminated string or a substring using `boost::lexical_cast`?
|
||||||
@@ -246,21 +246,21 @@ limitation of compiler options that you use.
|
|||||||
|
|
||||||
[section Changes]
|
[section Changes]
|
||||||
* [*boost 1.50.0 :]
|
* [*boost 1.50.0 :]
|
||||||
|
|
||||||
* `boost::bad_lexical_cast` exception is now globaly visible and can be catched even if code is compiled with -fvisibility=hidden.
|
* `boost::bad_lexical_cast` exception is now globaly visible and can be catched even if code is compiled with -fvisibility=hidden.
|
||||||
* Now it is possible to compile library with disabled exceptions.
|
* Now it is possible to compile library with disabled exceptions.
|
||||||
* Better performance, less memory usage and bugfixes for `boost::iterator_range<character_type*>` conversions.
|
* Better performance, less memory usage and bugfixes for `boost::iterator_range<character_type*>` conversions.
|
||||||
|
|
||||||
* [*boost 1.49.0 :]
|
* [*boost 1.49.0 :]
|
||||||
|
|
||||||
* Restored work with typedefed wchar_t (compilation flag /Zc:wchar_t- for Visual Studio).
|
* Restored work with typedefed wchar_t (compilation flag /Zc:wchar_t- for Visual Studio).
|
||||||
* Better performance and less memory usage for `boost::container::basic_string` conversions.
|
* Better performance and less memory usage for `boost::container::basic_string` conversions.
|
||||||
|
|
||||||
* [*boost 1.48.0 :]
|
* [*boost 1.48.0 :]
|
||||||
|
|
||||||
* Added code to work with Inf and NaN on any platform.
|
* Added code to work with Inf and NaN on any platform.
|
||||||
* Better performance and less memory usage for conversions to float type (and to double type, if `sizeof(double) < sizeof(long double)`).
|
* Better performance and less memory usage for conversions to float type (and to double type, if `sizeof(double) < sizeof(long double)`).
|
||||||
|
|
||||||
* [*boost 1.47.0 :]
|
* [*boost 1.47.0 :]
|
||||||
|
|
||||||
* Optimizations for "C" and other locales without number grouping.
|
* Optimizations for "C" and other locales without number grouping.
|
||||||
@@ -283,7 +283,7 @@ limitation of compiler options that you use.
|
|||||||
* The previous version of 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.
|
* The previous version of 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.
|
||||||
* The previous version of 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`.
|
* The previous version of 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`.
|
||||||
* The previous version of `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.
|
* The previous version of `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.
|
||||||
* The previous version of `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.
|
* The previous version of `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.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
@@ -328,7 +328,7 @@ All the tests measure execution speed in milliseconds for 10000 iterations of th
|
|||||||
``]
|
``]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
Fastest results are highlitened with "!!! *x* !!!".
|
Fastest results are highlitened with "!!! *x* !!!".
|
||||||
Do not use this results to compare compilers, because tests were taken on different hardware.
|
Do not use this results to compare compilers, because tests were taken on different hardware.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
@@ -69,12 +69,12 @@ namespace boost
|
|||||||
{
|
{
|
||||||
// exception used to indicate runtime lexical_cast failure
|
// exception used to indicate runtime lexical_cast failure
|
||||||
class BOOST_SYMBOL_VISIBLE bad_lexical_cast :
|
class BOOST_SYMBOL_VISIBLE bad_lexical_cast :
|
||||||
// workaround MSVC bug with std::bad_cast when _HAS_EXCEPTIONS == 0
|
// workaround MSVC bug with std::bad_cast when _HAS_EXCEPTIONS == 0
|
||||||
#if defined(BOOST_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
|
#if defined(BOOST_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
|
||||||
public std::exception
|
public std::exception
|
||||||
#else
|
#else
|
||||||
public std::bad_cast
|
public std::bad_cast
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__BORLANDC__) && BOOST_WORKAROUND( __BORLANDC__, < 0x560 )
|
#if defined(__BORLANDC__) && BOOST_WORKAROUND( __BORLANDC__, < 0x560 )
|
||||||
// under bcc32 5.5.1 bad_cast doesn't derive from exception
|
// under bcc32 5.5.1 bad_cast doesn't derive from exception
|
||||||
@@ -134,7 +134,7 @@ namespace boost
|
|||||||
}
|
}
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(__SUNPRO_CC)
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
@@ -147,9 +147,7 @@ namespace boost
|
|||||||
#include <boost/math/special_functions/sign.hpp>
|
#include <boost/math/special_functions/sign.hpp>
|
||||||
#include <boost/math/special_functions/fpclassify.hpp>
|
#include <boost/math/special_functions/fpclassify.hpp>
|
||||||
#include <boost/range/iterator_range_core.hpp>
|
#include <boost/range/iterator_range_core.hpp>
|
||||||
#if !defined(__SUNPRO_CC)
|
|
||||||
#include <boost/container/container_fwd.hpp>
|
#include <boost/container/container_fwd.hpp>
|
||||||
#endif // !defined(__SUNPRO_CC)
|
|
||||||
#ifndef BOOST_NO_CWCHAR
|
#ifndef BOOST_NO_CWCHAR
|
||||||
# include <cwchar>
|
# include <cwchar>
|
||||||
#endif
|
#endif
|
||||||
@@ -170,13 +168,13 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
typedef CharT type;
|
typedef CharT type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct widest_char< not_a_character_type, not_a_character_type >
|
struct widest_char< not_a_character_type, not_a_character_type >
|
||||||
{
|
{
|
||||||
typedef char type;
|
typedef char type;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace detail // is_char_or_wchar<...> and stream_char<...> templates
|
namespace detail // is_char_or_wchar<...> and stream_char<...> templates
|
||||||
{
|
{
|
||||||
@@ -243,7 +241,7 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT*>::type type;
|
typedef BOOST_DEDUCED_TYPENAME stream_char<CharT*>::type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename CharT>
|
template<typename CharT>
|
||||||
struct stream_char<iterator_range<const CharT*> >
|
struct stream_char<iterator_range<const CharT*> >
|
||||||
{
|
{
|
||||||
@@ -256,13 +254,11 @@ namespace boost {
|
|||||||
typedef CharT type;
|
typedef CharT type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined(__SUNPRO_CC)
|
|
||||||
template<class CharT, class Traits, class Alloc>
|
template<class CharT, class Traits, class Alloc>
|
||||||
struct stream_char< ::boost::container::basic_string<CharT, Traits, Alloc> >
|
struct stream_char< ::boost::container::basic_string<CharT, Traits, Alloc> >
|
||||||
{
|
{
|
||||||
typedef CharT type;
|
typedef CharT type;
|
||||||
};
|
};
|
||||||
#endif // !defined(__SUNPRO_CC)
|
|
||||||
|
|
||||||
#if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
#if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||||
template<>
|
template<>
|
||||||
@@ -312,7 +308,6 @@ namespace boost {
|
|||||||
typedef Traits type;
|
typedef Traits type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined(__SUNPRO_CC)
|
|
||||||
template<class CharT, class Traits, class Alloc, class Source>
|
template<class CharT, class Traits, class Alloc, class Source>
|
||||||
struct deduce_char_traits< CharT
|
struct deduce_char_traits< CharT
|
||||||
, ::boost::container::basic_string<CharT,Traits,Alloc>
|
, ::boost::container::basic_string<CharT,Traits,Alloc>
|
||||||
@@ -366,7 +361,6 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
typedef Traits type;
|
typedef Traits type;
|
||||||
};
|
};
|
||||||
#endif // !defined(__SUNPRO_CC)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace detail // lcast_src_length
|
namespace detail // lcast_src_length
|
||||||
@@ -436,7 +430,7 @@ namespace boost {
|
|||||||
// -1.23456789e-123456
|
// -1.23456789e-123456
|
||||||
// ^ sign
|
// ^ sign
|
||||||
// ^ leading digit
|
// ^ leading digit
|
||||||
// ^ decimal point
|
// ^ decimal point
|
||||||
// ^^^^^^^^ lcast_precision<Source>::value
|
// ^^^^^^^^ lcast_precision<Source>::value
|
||||||
// ^ "e"
|
// ^ "e"
|
||||||
// ^ exponent sign
|
// ^ exponent sign
|
||||||
@@ -1389,7 +1383,6 @@ namespace boost {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(__SUNPRO_CC)
|
|
||||||
template<class Alloc>
|
template<class Alloc>
|
||||||
bool operator<<(::boost::container::basic_string<CharT,Traits,Alloc> const& str)
|
bool operator<<(::boost::container::basic_string<CharT,Traits,Alloc> const& str)
|
||||||
{
|
{
|
||||||
@@ -1397,7 +1390,7 @@ namespace boost {
|
|||||||
finish = start + str.length();
|
finish = start + str.length();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif // !defined(__SUNPRO_CC)
|
|
||||||
bool operator<<(bool value)
|
bool operator<<(bool value)
|
||||||
{
|
{
|
||||||
CharT const czero = lcast_char_constants<CharT>::zero;
|
CharT const czero = lcast_char_constants<CharT>::zero;
|
||||||
@@ -1410,14 +1403,14 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
start = rng.begin();
|
start = rng.begin();
|
||||||
finish = rng.end();
|
finish = rng.end();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<<(const iterator_range<const CharT*>& rng)
|
bool operator<<(const iterator_range<const CharT*>& rng)
|
||||||
{
|
{
|
||||||
start = const_cast<CharT*>(rng.begin());
|
start = const_cast<CharT*>(rng.begin());
|
||||||
finish = const_cast<CharT*>(rng.end());
|
finish = const_cast<CharT*>(rng.end());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<<(const iterator_range<const signed char*>& rng)
|
bool operator<<(const iterator_range<const signed char*>& rng)
|
||||||
@@ -1677,10 +1670,9 @@ namespace boost {
|
|||||||
#endif
|
#endif
|
||||||
template<class Alloc>
|
template<class Alloc>
|
||||||
bool operator>>(std::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
|
bool operator>>(std::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
|
||||||
#if !defined(__SUNPRO_CC)
|
|
||||||
template<class Alloc>
|
template<class Alloc>
|
||||||
bool operator>>(::boost::container::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
|
bool operator>>(::boost::container::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
|
||||||
#endif // !defined(__SUNPRO_CC)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* case "-0" || "0" || "+0" : output = false; return true;
|
* case "-0" || "0" || "+0" : output = false; return true;
|
||||||
@@ -1812,13 +1804,12 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||||
};
|
};
|
||||||
#if !defined(__SUNPRO_CC)
|
|
||||||
template<typename CharT, typename Traits, typename Alloc>
|
template<typename CharT, typename Traits, typename Alloc>
|
||||||
struct is_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc> >
|
struct is_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc> >
|
||||||
{
|
{
|
||||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||||
};
|
};
|
||||||
#endif // !defined(__SUNPRO_CC)
|
|
||||||
|
|
||||||
template<typename Target, typename Source>
|
template<typename Target, typename Source>
|
||||||
struct is_arithmetic_and_not_xchars
|
struct is_arithmetic_and_not_xchars
|
||||||
@@ -1866,11 +1857,11 @@ namespace boost {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// this metafunction evaluates to true, if we have optimized comnversion
|
// this metafunction evaluates to true, if we have optimized comnversion
|
||||||
// from Float type to Char array.
|
// from Float type to Char array.
|
||||||
// Must be in sync with lexical_stream_limited_src<Char, ...>::shl_real_type(...)
|
// Must be in sync with lexical_stream_limited_src<Char, ...>::shl_real_type(...)
|
||||||
template <typename Float, typename Char>
|
template <typename Float, typename Char>
|
||||||
struct is_this_float_conversion_optimized
|
struct is_this_float_conversion_optimized
|
||||||
{
|
{
|
||||||
typedef ::boost::type_traits::ice_and<
|
typedef ::boost::type_traits::ice_and<
|
||||||
::boost::is_float<Float>::value,
|
::boost::is_float<Float>::value,
|
||||||
@@ -1904,7 +1895,7 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||||
};
|
};
|
||||||
#if !defined(__SUNPRO_CC)
|
|
||||||
template<typename CharT, typename Traits, typename Alloc>
|
template<typename CharT, typename Traits, typename Alloc>
|
||||||
struct is_char_array_to_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc>, CharT* >
|
struct is_char_array_to_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc>, CharT* >
|
||||||
{
|
{
|
||||||
@@ -1916,7 +1907,6 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||||
};
|
};
|
||||||
#endif // !defined(__SUNPRO_CC)
|
|
||||||
|
|
||||||
#if (defined _MSC_VER)
|
#if (defined _MSC_VER)
|
||||||
# pragma warning( push )
|
# pragma warning( push )
|
||||||
@@ -2262,10 +2252,10 @@ namespace boost {
|
|||||||
template<typename Target, typename Source>
|
template<typename Target, typename Source>
|
||||||
Target lexical_cast(Source arg)
|
Target lexical_cast(Source arg)
|
||||||
{
|
{
|
||||||
typedef typename detail::widest_char<
|
typedef typename detail::widest_char<
|
||||||
BOOST_DEDUCED_TYPENAME detail::stream_char<Target>::type
|
BOOST_DEDUCED_TYPENAME detail::stream_char<Target>::type
|
||||||
, BOOST_DEDUCED_TYPENAME detail::stream_char<Source>::type
|
, BOOST_DEDUCED_TYPENAME detail::stream_char<Source>::type
|
||||||
>::type char_type;
|
>::type char_type;
|
||||||
|
|
||||||
typedef std::char_traits<char_type> traits;
|
typedef std::char_traits<char_type> traits;
|
||||||
detail::lexical_stream<Target, Source, traits> interpreter;
|
detail::lexical_stream<Target, Source, traits> interpreter;
|
||||||
|
@@ -13,17 +13,17 @@ path-constant TEST_DIR : . ;
|
|||||||
|
|
||||||
project performance/test
|
project performance/test
|
||||||
: source-location ./
|
: source-location ./
|
||||||
: requirements
|
: requirements
|
||||||
# <library>/boost/chrono//boost_chrono
|
# <library>/boost/chrono//boost_chrono
|
||||||
# <library>/boost/system//boost_system
|
# <library>/boost/system//boost_system
|
||||||
<link>static
|
<link>static
|
||||||
<target-os>freebsd:<linkflags>"-lrt"
|
<target-os>freebsd:<linkflags>"-lrt"
|
||||||
<target-os>linux:<linkflags>"-lrt"
|
<target-os>linux:<linkflags>"-lrt"
|
||||||
<toolset>gcc:<cxxflags>-fvisibility=hidden
|
<toolset>gcc:<cxxflags>-fvisibility=hidden
|
||||||
<toolset>intel-linux:<cxxflags>-fvisibility=hidden
|
<toolset>intel-linux:<cxxflags>-fvisibility=hidden
|
||||||
<toolset>sun:<cxxflags>-xldscope=hidden
|
<toolset>sun:<cxxflags>-xldscope=hidden
|
||||||
: default-build release
|
: default-build release
|
||||||
;
|
;
|
||||||
|
|
||||||
run performance_test.cpp : $(TEST_DIR) ;
|
run performance_test.cpp : $(TEST_DIR) ;
|
||||||
|
|
||||||
|
@@ -11,20 +11,20 @@ import feature ;
|
|||||||
project
|
project
|
||||||
: requirements
|
: requirements
|
||||||
<library>/boost/test//boost_unit_test_framework
|
<library>/boost/test//boost_unit_test_framework
|
||||||
<link>static
|
<link>static
|
||||||
<toolset>gcc-4.8:<define>BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
|
<toolset>gcc-4.8:<define>BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
|
||||||
;
|
;
|
||||||
|
|
||||||
# Thanks to Steven Watanabe for helping with <nowchar> feature
|
# Thanks to Steven Watanabe for helping with <nowchar> feature
|
||||||
feature.feature nowchar : on :
|
feature.feature nowchar : on :
|
||||||
composite optional propagated link-incompatible ;
|
composite optional propagated link-incompatible ;
|
||||||
feature.compose <nowchar>on : <cxxflags>/Zc:wchar_t- ;
|
feature.compose <nowchar>on : <cxxflags>/Zc:wchar_t- ;
|
||||||
|
|
||||||
test-suite conversion
|
test-suite conversion
|
||||||
: [ run implicit_cast.cpp ]
|
: [ run implicit_cast.cpp ]
|
||||||
[ compile-fail implicit_cast_fail.cpp ]
|
[ compile-fail implicit_cast_fail.cpp ]
|
||||||
[ run ../cast_test.cpp ]
|
[ run ../cast_test.cpp ]
|
||||||
[ run ../numeric_cast_test.cpp ]
|
[ run ../numeric_cast_test.cpp ]
|
||||||
[ run ../lexical_cast_test.cpp ]
|
[ run ../lexical_cast_test.cpp ]
|
||||||
[ run lexical_cast_loopback_test.cpp ]
|
[ run lexical_cast_loopback_test.cpp ]
|
||||||
[ run lexical_cast_abstract_test.cpp ]
|
[ run lexical_cast_abstract_test.cpp ]
|
||||||
@@ -39,7 +39,7 @@ test-suite conversion
|
|||||||
[ compile lexical_cast_typedefed_wchar_test.cpp : <toolset>msvc:<nowchar>on ]
|
[ compile lexical_cast_typedefed_wchar_test.cpp : <toolset>msvc:<nowchar>on ]
|
||||||
[ run lexical_cast_typedefed_wchar_test_runtime.cpp : : : <toolset>msvc:<nowchar>on <toolset>msvc,<stdlib>stlport:<build>no ]
|
[ run lexical_cast_typedefed_wchar_test_runtime.cpp : : : <toolset>msvc:<nowchar>on <toolset>msvc,<stdlib>stlport:<build>no ]
|
||||||
[ run lexical_cast_no_locale_test.cpp : : : <define>BOOST_NO_STD_LOCALE <define>BOOST_LEXICAL_CAST_ASSUME_C_LOCALE ]
|
[ run lexical_cast_no_locale_test.cpp : : : <define>BOOST_NO_STD_LOCALE <define>BOOST_LEXICAL_CAST_ASSUME_C_LOCALE ]
|
||||||
[ run lexical_cast_no_exceptions_test.cpp : : : <define>BOOST_NO_EXCEPTIONS
|
[ run lexical_cast_no_exceptions_test.cpp : : : <define>BOOST_NO_EXCEPTIONS
|
||||||
<toolset>gcc-4.3:<cflags>-fno-exceptions
|
<toolset>gcc-4.3:<cflags>-fno-exceptions
|
||||||
<toolset>gcc-4.4:<cflags>-fno-exceptions
|
<toolset>gcc-4.4:<cflags>-fno-exceptions
|
||||||
<toolset>gcc-4.5:<cflags>-fno-exceptions
|
<toolset>gcc-4.5:<cflags>-fno-exceptions
|
||||||
|
@@ -31,7 +31,7 @@ boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
void testing_boost_containers_basic_string()
|
void testing_boost_containers_basic_string()
|
||||||
{
|
{
|
||||||
BOOST_CHECK("100" == lexical_cast<boost::container::string>("100"));
|
BOOST_CHECK("100" == lexical_cast<boost::container::string>("100"));
|
||||||
BOOST_CHECK(L"100" == lexical_cast<boost::container::wstring>(L"100"));
|
BOOST_CHECK(L"100" == lexical_cast<boost::container::wstring>(L"100"));
|
||||||
|
|
||||||
|
@@ -237,7 +237,7 @@ void test_converion_to_float_types()
|
|||||||
CHECK_CLOSE_ABS_DIFF(-10101.0E-011, test_t);
|
CHECK_CLOSE_ABS_DIFF(-10101.0E-011, test_t);
|
||||||
CHECK_CLOSE_ABS_DIFF(-10101093, test_t);
|
CHECK_CLOSE_ABS_DIFF(-10101093, test_t);
|
||||||
CHECK_CLOSE_ABS_DIFF(10101093, test_t);
|
CHECK_CLOSE_ABS_DIFF(10101093, test_t);
|
||||||
|
|
||||||
CHECK_CLOSE_ABS_DIFF(-.34, test_t);
|
CHECK_CLOSE_ABS_DIFF(-.34, test_t);
|
||||||
CHECK_CLOSE_ABS_DIFF(.34, test_t);
|
CHECK_CLOSE_ABS_DIFF(.34, test_t);
|
||||||
CHECK_CLOSE_ABS_DIFF(.34e10, test_t);
|
CHECK_CLOSE_ABS_DIFF(.34e10, test_t);
|
||||||
|
@@ -138,7 +138,7 @@ void test_it_range_using_char(CharT* one, CharT* eleven)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_char_iterator_ranges()
|
void test_char_iterator_ranges()
|
||||||
{
|
{
|
||||||
typedef char test_char_type;
|
typedef char test_char_type;
|
||||||
test_char_type data1[] = "1";
|
test_char_type data1[] = "1";
|
||||||
@@ -149,7 +149,7 @@ void test_char_iterator_ranges()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void test_unsigned_char_iterator_ranges()
|
void test_unsigned_char_iterator_ranges()
|
||||||
{
|
{
|
||||||
typedef unsigned char test_char_type;
|
typedef unsigned char test_char_type;
|
||||||
test_char_type data1[] = "1";
|
test_char_type data1[] = "1";
|
||||||
@@ -158,7 +158,7 @@ void test_unsigned_char_iterator_ranges()
|
|||||||
test_it_range_using_char(data1, data2);
|
test_it_range_using_char(data1, data2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_signed_char_iterator_ranges()
|
void test_signed_char_iterator_ranges()
|
||||||
{
|
{
|
||||||
typedef signed char test_char_type;
|
typedef signed char test_char_type;
|
||||||
test_char_type data1[] = "1";
|
test_char_type data1[] = "1";
|
||||||
@@ -167,7 +167,7 @@ void test_signed_char_iterator_ranges()
|
|||||||
test_it_range_using_char(data1, data2);
|
test_it_range_using_char(data1, data2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_wchar_iterator_ranges()
|
void test_wchar_iterator_ranges()
|
||||||
{
|
{
|
||||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||||
typedef wchar_t test_char_type;
|
typedef wchar_t test_char_type;
|
||||||
@@ -179,7 +179,7 @@ void test_wchar_iterator_ranges()
|
|||||||
BOOST_CHECK(true);
|
BOOST_CHECK(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_char16_iterator_ranges()
|
void test_char16_iterator_ranges()
|
||||||
{
|
{
|
||||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||||
typedef char16_t test_char_type;
|
typedef char16_t test_char_type;
|
||||||
@@ -191,7 +191,7 @@ void test_char16_iterator_ranges()
|
|||||||
BOOST_CHECK(true);
|
BOOST_CHECK(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_char32_iterator_ranges()
|
void test_char32_iterator_ranges()
|
||||||
{
|
{
|
||||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||||
typedef char32_t test_char_type;
|
typedef char32_t test_char_type;
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
#error "This test must be compiled with -DBOOST_NO_EXCEPTIONS"
|
#error "This test must be compiled with -DBOOST_NO_EXCEPTIONS"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool g_was_exception = false;
|
bool g_was_exception = false;
|
||||||
|
|
||||||
@@ -60,25 +60,25 @@ inline std::istream& operator>> (std::istream& i, Escape& rhs)
|
|||||||
void test_exceptions_off()
|
void test_exceptions_off()
|
||||||
{
|
{
|
||||||
Escape v("");
|
Escape v("");
|
||||||
|
|
||||||
g_was_exception = false;
|
g_was_exception = false;
|
||||||
lexical_cast<char>(v);
|
lexical_cast<char>(v);
|
||||||
BOOST_CHECK(g_was_exception);
|
BOOST_CHECK(g_was_exception);
|
||||||
|
|
||||||
g_was_exception = false;
|
g_was_exception = false;
|
||||||
lexical_cast<unsigned char>(v);
|
lexical_cast<unsigned char>(v);
|
||||||
BOOST_CHECK(g_was_exception);
|
BOOST_CHECK(g_was_exception);
|
||||||
|
|
||||||
v = lexical_cast<Escape>(100);
|
v = lexical_cast<Escape>(100);
|
||||||
BOOST_CHECK_EQUAL(lexical_cast<int>(v), 100);
|
BOOST_CHECK_EQUAL(lexical_cast<int>(v), 100);
|
||||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(v), 100u);
|
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(v), 100u);
|
||||||
|
|
||||||
v = lexical_cast<Escape>(0.0);
|
v = lexical_cast<Escape>(0.0);
|
||||||
BOOST_CHECK_EQUAL(lexical_cast<double>(v), 0.0);
|
BOOST_CHECK_EQUAL(lexical_cast<double>(v), 0.0);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(lexical_cast<short>(100), 100);
|
BOOST_CHECK_EQUAL(lexical_cast<short>(100), 100);
|
||||||
BOOST_CHECK_EQUAL(lexical_cast<float>(0.0), 0.0);
|
BOOST_CHECK_EQUAL(lexical_cast<float>(0.0), 0.0);
|
||||||
|
|
||||||
g_was_exception = false;
|
g_was_exception = false;
|
||||||
lexical_cast<short>(700000);
|
lexical_cast<short>(700000);
|
||||||
BOOST_CHECK(g_was_exception);
|
BOOST_CHECK(g_was_exception);
|
||||||
|
@@ -23,12 +23,12 @@
|
|||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
||||||
// Testing compilation and some basic usage with BOOST_NO_STD_LOCALE
|
// Testing compilation and some basic usage with BOOST_NO_STD_LOCALE
|
||||||
// Tests are mainly copyied from lexical_cast_empty_input_test.cpp (something
|
// Tests are mainly copyied from lexical_cast_empty_input_test.cpp (something
|
||||||
// new added to test_empty_3)
|
// new added to test_empty_3)
|
||||||
|
|
||||||
#ifndef BOOST_NO_STD_LOCALE
|
#ifndef BOOST_NO_STD_LOCALE
|
||||||
#error "This test must be compiled with -DBOOST_NO_STD_LOCALE"
|
#error "This test must be compiled with -DBOOST_NO_STD_LOCALE"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@@ -106,15 +106,15 @@ void test_empty_3()
|
|||||||
{
|
{
|
||||||
Escape v("");
|
Escape v("");
|
||||||
do_test_on_empty_input(v);
|
do_test_on_empty_input(v);
|
||||||
|
|
||||||
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
|
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
|
||||||
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
|
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
|
||||||
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
|
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
|
||||||
|
|
||||||
v = lexical_cast<Escape>(100);
|
v = lexical_cast<Escape>(100);
|
||||||
BOOST_CHECK_EQUAL(lexical_cast<int>(v), 100);
|
BOOST_CHECK_EQUAL(lexical_cast<int>(v), 100);
|
||||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(v), 100u);
|
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(v), 100u);
|
||||||
|
|
||||||
v = lexical_cast<Escape>(0.0);
|
v = lexical_cast<Escape>(0.0);
|
||||||
BOOST_CHECK_EQUAL(lexical_cast<double>(v), 0.0);
|
BOOST_CHECK_EQUAL(lexical_cast<double>(v), 0.0);
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ void test_typedefed_wchar_t_runtime()
|
|||||||
|
|
||||||
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(L'A'), 65);
|
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(L'A'), 65);
|
||||||
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(L'B'), 66);
|
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(L'B'), 66);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(boost::lexical_cast<wchar_t>(L"65"), 65);
|
BOOST_CHECK_EQUAL(boost::lexical_cast<wchar_t>(L"65"), 65);
|
||||||
BOOST_CHECK_EQUAL(boost::lexical_cast<wchar_t>(L"66"), 66);
|
BOOST_CHECK_EQUAL(boost::lexical_cast<wchar_t>(L"66"), 66);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user