mirror of
https://github.com/boostorg/conversion.git
synced 2026-08-05 21:14:14 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d2464aecc |
@@ -10,13 +10,6 @@
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
|
||||
<title>Header boost/cast.hpp Documentation</title>
|
||||
<style>
|
||||
.copyright
|
||||
{
|
||||
color: #666666;
|
||||
font-size: small;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
@@ -138,9 +131,10 @@ void f( Fruit * fruit ) {
|
||||
-->June 23, 2005<!--webbot bot="Timestamp" endspan i-checksum="30348"
|
||||
--></p>
|
||||
|
||||
<p class="copyright">© Copyright boost.org 1999.
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
<p>© Copyright boost.org 1999. Permission to copy, use, modify, sell
|
||||
and distribute this document is granted provided this copyright notice
|
||||
appears in all copies. This document is provided "as is" without express
|
||||
or implied warranty, and with no claim as to its suitability for any
|
||||
purpose.</p>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
+95
-176
@@ -3,7 +3,7 @@
|
||||
[version 1.0]
|
||||
[copyright 2000-2005 Kevlin Henney]
|
||||
[copyright 2006-2010 Alexander Nasonov]
|
||||
[copyright 2011-2013 Antony Polukhin]
|
||||
[copyright 2011-2012 Antony Polukhin]
|
||||
[category String and text processing]
|
||||
[category Miscellaneous]
|
||||
[license
|
||||
@@ -38,22 +38,47 @@ For a good discussion of the options and issues involved in string-based formatt
|
||||
[endsect]
|
||||
|
||||
[section Examples]
|
||||
The following example treats command line arguments as a sequence of numeric data:
|
||||
``
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
using boost::lexical_cast;
|
||||
using boost::bad_lexical_cast;
|
||||
|
||||
[import ../example/args_to_numbers.cpp]
|
||||
std::vector<short> args;
|
||||
|
||||
[section Strings to numbers conversion] [lexical_cast_args_example] [endsect]
|
||||
|
||||
[import ../example/small_examples.cpp]
|
||||
[section Numbers to strings conversion] [lexical_cast_log_errno] [endsect]
|
||||
[section Converting to string without dynamic memory allocation] [lexical_cast_fixed_buffer] [endsect]
|
||||
[section Converting part of the string] [lexical_cast_substring_conversion] [endsect]
|
||||
|
||||
[import ../example/generic_stringize.cpp]
|
||||
[section Generic programming (Boost.Fusion)] [lexical_cast_stringize] [endsect]
|
||||
|
||||
[import ../example/variant_to_long_double.cpp]
|
||||
[section Generic programming (Boost.Variant)] [lexical_cast_variant_to_long_double] [endsect]
|
||||
while(*++argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
args.push_back(lexical_cast<short>(*argv));
|
||||
}
|
||||
catch(bad_lexical_cast &)
|
||||
{
|
||||
args.push_back(0);
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
``
|
||||
The following example uses numeric data in a string expression:
|
||||
``
|
||||
void log_message(const std::string &);
|
||||
|
||||
void log_errno(int yoko)
|
||||
{
|
||||
log_message("Error " + boost::lexical_cast<std::string>(yoko) + ": " + strerror(yoko));
|
||||
}
|
||||
``
|
||||
Following example converts some number and puts it to file:
|
||||
``
|
||||
int i;
|
||||
FILE* file;
|
||||
...
|
||||
typedef boost::array<char, 50> buf_t; // You can use std::array if your compiler supports it
|
||||
buf_t buffer = boost::lexical_cast<buf_t>(i); // No dynamic memory allocation
|
||||
puts(buffer.begin(), file);
|
||||
``
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
@@ -62,12 +87,8 @@ Library features defined in [@boost:boost/lexical_cast.hpp boost/lexical_cast.hp
|
||||
namespace boost
|
||||
{
|
||||
class bad_lexical_cast;
|
||||
|
||||
template<typename Target, typename Source>
|
||||
Target lexical_cast(const Source& arg);
|
||||
|
||||
template <typename Target>
|
||||
Target lexical_cast(const AnyCharacterType* chars, std::size_t count);
|
||||
}
|
||||
``
|
||||
|
||||
@@ -78,23 +99,17 @@ Library features defined in [@boost:boost/lexical_cast.hpp boost/lexical_cast.hp
|
||||
``
|
||||
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.
|
||||
|
||||
``
|
||||
template <typename Target>
|
||||
Target lexical_cast(const AnyCharacterType* chars, std::size_t count);
|
||||
``
|
||||
Takes an array of `count` characters as input parameter and streams them out as a Target object. If the conversion is unsuccessful, a `bad_lexical_cast` exception is thrown. This call may be useful for processing nonzero terminated array of characters or processing just some part of character array.
|
||||
|
||||
The requirements on the argument and result types for both functions are:
|
||||
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.
|
||||
* 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.
|
||||
* Target is 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].
|
||||
|
||||
The character type of the underlying stream is assumed to be `char` unless either the `Source` or the `Target` requires wide-character streaming, in which case the underlying stream uses `wchar_t`. Following types also can use `char16_t` or `char32_t` for wide-character streaming:
|
||||
The character type of the underlying stream is assumed to be `char` unless either the `Source` or the `Target` requires wide-character streaming, in which case the underlying stream uses `wchar_t`, `char16_t` or `char32_t`. Wide-character streaming is currently detected for:
|
||||
|
||||
* Single character: `char16_t`, `char32_t`
|
||||
* Arrays of characters: `char16_t *`, `char32_t *`, `const char16_t *`, `const char32_t *`
|
||||
* Single character: `wchar_t`, `char16_t`, `char32_t`
|
||||
* Arrays of characters: `wchar_t *`, `char16_t *`, `char32_t *`, `const wchar_t *`, `const char16_t *`, `const char32_t *`
|
||||
* Strings: `std::basic_string`, `boost::containers::basic_string`
|
||||
* `boost::iterator_range<WideCharPtr>`, where `WideCharPtr` is a pointer to wide-character or pointer to const wide-character
|
||||
* `boost::array<CharT, N>` and `std::array<CharT, N>`, `boost::array<const CharT, N>` and `std::array<const CharT, N>`
|
||||
@@ -124,6 +139,56 @@ Exception used to indicate runtime lexical_cast failure.
|
||||
|
||||
[endsect]
|
||||
|
||||
[/ Commenting out bad advise (this will break the ability to get correct function pointers via &lexical_cast<Target, Source>)
|
||||
[section Tuning classes for fast lexical conversions]
|
||||
Because of `boost::lexical_cast` optimizations for `boost::iterator_range<character_type*>`, it is possibile to make very fast lexical conversions for non zero terminated strings, substrings and user-defined classes.
|
||||
|
||||
Consider the following example:
|
||||
``
|
||||
class example_class {
|
||||
char non_zero_terminated_data[10];
|
||||
std::size_t data_length;
|
||||
|
||||
public:
|
||||
example_class();
|
||||
void fill_data();
|
||||
|
||||
const char* data() const {
|
||||
return non_zero_terminated_data;
|
||||
}
|
||||
|
||||
std::size_t size() const {
|
||||
return data_length;
|
||||
}
|
||||
};
|
||||
|
||||
inline std::ostream& operator << (std::ostream& ostr, const example_class& rhs) {
|
||||
return ostr << boost::make_iterator_range(rhs.data(), rhs.data() + rhs.size());
|
||||
}
|
||||
``
|
||||
|
||||
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:
|
||||
|
||||
* `std::ostream` construction (it makes some heap allocations)
|
||||
* `operator <<` (it copyies one by one all the symbols to an instance of `std::ostream`)
|
||||
* `std::ostream` destruction (it makes some heap deallocations)
|
||||
|
||||
We can avoid all of this, by specifieng an overload for `boost::lexical_cast`:
|
||||
``
|
||||
namespace boost {
|
||||
template <class OutT>
|
||||
OutT lexical_cast(const example_class& rhs) {
|
||||
return boost::lexical_cast<OutT>(
|
||||
boost::make_iterator_range(rhs.data(), rhs.data() + rhs.size())
|
||||
);
|
||||
}
|
||||
}
|
||||
``
|
||||
Now `boost::lexical_cast<some_type>(example_class_instance)` conversions won't copy data and construct heavy STL stream objects. See [link boost_lexical_cast.performance Performance] section for info on `boost::iterator_range` conversion performance.
|
||||
[endsect]
|
||||
]
|
||||
|
||||
[section Frequently Asked Questions]
|
||||
|
||||
* [*Question:] Why does `lexical_cast<int8_t>("127")` throw `bad_lexical_cast`?
|
||||
@@ -156,7 +221,7 @@ It breaks my `operator>>` that works only in presence of this flag. Can you remo
|
||||
* [*Answer:] May be in a future version. There is no requirement in
|
||||
__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
|
||||
make your `operator>>` more general.
|
||||
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`].
|
||||
|
||||
[pre
|
||||
@@ -188,32 +253,12 @@ limitation of compiler options that you use.
|
||||
]
|
||||
|
||||
* [*Question:] What is the fastest way to convert a non zero terminated string or a substring using `boost::lexical_cast`?
|
||||
* [*Answer:] Use `boost::iterator_range` for conversion or `lexical_cast` overload with two parameters. For example, if you whant to convert to `int` two characters from a string `str`, you shall write `lexical_cast<int>(make_iterator_range(str.data(), str.data() + 2));` or `lexical_cast<int>(str.data(), 2);`.
|
||||
* [*Answer:] Use `boost::iterator_range` for conversion. For example, if you whant to convert to `int` two characters from a string `str`, you shall write `lexacal_cast<int>(make_iterator_range(str.c_str(), str.c_str() + 2));`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Changes]
|
||||
|
||||
* [*boost 1.54.0 :]
|
||||
|
||||
* Fix some issues with `boost::int128_type` and `boost::uint128_type` conversions. Notify user at compile time
|
||||
if the `std::numeric_limits` are not specialized for 128bit types and `boost::lexical_cast` can not make conversions.
|
||||
|
||||
* [*boost 1.54.0 :]
|
||||
|
||||
* Added code to convert `boost::int128_type` and `boost::uint128_type` types (requires GCC 4.7 or higher).
|
||||
* Conversions to pointers will now fail to compile, instead of throwing at runtime.
|
||||
* Restored ability to get pointers to `lexical_cast` function (was broken in 1.53.0).
|
||||
|
||||
* [*boost 1.53.0 :]
|
||||
|
||||
* Much better input and output streams detection for user defined types.
|
||||
|
||||
* [*boost 1.52.0 :]
|
||||
|
||||
* Restored compilation on MSVC-2003 (was broken in 1.51.0).
|
||||
* Added `lexical_cast(const CharType* chars, std::size_t count)` function overload.
|
||||
|
||||
* [*boost 1.51.0 :]
|
||||
|
||||
* Better performance, less memory usage for `boost::array<character_type, N>` and `std::array<character_type, N>` conversions.
|
||||
@@ -809,132 +854,6 @@ Do not use this results to compare compilers, because tests were taken on differ
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section Microsoft Visual C++ version 11.0]
|
||||
[table:id Performance Table ( Microsoft Visual C++ version 11.0)
|
||||
[[From->To] [lexical_cast] [std::stringstream with construction] [std::stringstream without construction][scanf/printf]]
|
||||
[[ string->char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 7 ]]
|
||||
[[ string->signed char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 8 ]]
|
||||
[[ string->unsigned char ][ !!! *<1* !!! ][ 42 ][ 17 ][ 8 ]]
|
||||
[[ string->int ][ !!! *8* !!! ][ 71 ][ 49 ][ 10 ]]
|
||||
[[ string->short ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]]
|
||||
[[ string->long int ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]]
|
||||
[[ string->long long ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]]
|
||||
[[ string->unsigned int ][ !!! *8* !!! ][ 72 ][ 46 ][ 10 ]]
|
||||
[[ string->unsigned short ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]]
|
||||
[[ string->unsigned long int ][ !!! *8* !!! ][ 70 ][ 45 ][ 10 ]]
|
||||
[[ string->unsigned long long ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]]
|
||||
[[ string->float ][ !!! *14* !!! ][ 586 ][ 559 ][ 37 ]]
|
||||
[[ string->double ][ 601 ][ 618 ][ 592 ][ !!! *37* !!! ]]
|
||||
[[ string->long double ][ 629 ][ 645 ][ 618 ][ !!! *37* !!! ]]
|
||||
[[ string->array<char, 50> ][ !!! *<1* !!! ][ 52 ][ 28 ][ 11 ]]
|
||||
[[ string->string ][ !!! *1* !!! ][ 59 ][ 34 ][ --- ]]
|
||||
[[ string->container::string ][ !!! *2* !!! ][ 54 ][ 31 ][ --- ]]
|
||||
[[ string->char ][ !!! *2* !!! ][ 50 ][ 24 ][ 9 ]]
|
||||
[[ string->signed char ][ !!! *2* !!! ][ 50 ][ 24 ][ 13 ]]
|
||||
[[ string->unsigned char ][ !!! *2* !!! ][ 50 ][ 24 ][ 13 ]]
|
||||
[[ int->string ][ !!! *9* !!! ][ 86 ][ 59 ][ 13 ]]
|
||||
[[ short->string ][ !!! *9* !!! ][ 86 ][ 59 ][ 13 ]]
|
||||
[[ long int->string ][ !!! *9* !!! ][ 87 ][ 59 ][ 13 ]]
|
||||
[[ long long->string ][ !!! *9* !!! ][ 88 ][ 62 ][ 13 ]]
|
||||
[[ unsigned int->string ][ !!! *9* !!! ][ 87 ][ 60 ][ 13 ]]
|
||||
[[ unsigned short->string ][ !!! *9* !!! ][ 91 ][ 63 ][ 13 ]]
|
||||
[[ unsigned long int->string ][ !!! *9* !!! ][ 91 ][ 62 ][ 13 ]]
|
||||
[[ unsigned long long->string ][ !!! *9* !!! ][ 88 ][ 60 ][ 13 ]]
|
||||
[[ float->string ][ 73 ][ 167 ][ 137 ][ !!! *56* !!! ]]
|
||||
[[ double->string ][ 77 ][ 176 ][ 144 ][ !!! *64* !!! ]]
|
||||
[[ long double->string ][ 79 ][ 175 ][ 143 ][ !!! *63* !!! ]]
|
||||
[[ char*->char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 7 ]]
|
||||
[[ char*->signed char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 8 ]]
|
||||
[[ char*->unsigned char ][ !!! *<1* !!! ][ 44 ][ 17 ][ 8 ]]
|
||||
[[ char*->int ][ !!! *8* !!! ][ 70 ][ 47 ][ 10 ]]
|
||||
[[ char*->short ][ !!! *8* !!! ][ 72 ][ 48 ][ 10 ]]
|
||||
[[ char*->long int ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]]
|
||||
[[ char*->long long ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]]
|
||||
[[ char*->unsigned int ][ !!! *8* !!! ][ 72 ][ 46 ][ 10 ]]
|
||||
[[ char*->unsigned short ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]]
|
||||
[[ char*->unsigned long int ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]]
|
||||
[[ char*->unsigned long long ][ !!! *8* !!! ][ 70 ][ 45 ][ 10 ]]
|
||||
[[ char*->float ][ !!! *14* !!! ][ 586 ][ 560 ][ 37 ]]
|
||||
[[ char*->double ][ 598 ][ 617 ][ 597 ][ !!! *40* !!! ]]
|
||||
[[ char*->long double ][ 635 ][ 653 ][ 622 ][ !!! *37* !!! ]]
|
||||
[[ char*->array<char, 50> ][ !!! *1* !!! ][ 53 ][ 28 ][ 11 ]]
|
||||
[[ char*->string ][ !!! *1* !!! ][ 59 ][ 35 ][ --- ]]
|
||||
[[ char*->container::string ][ !!! *3* !!! ][ 54 ][ 30 ][ --- ]]
|
||||
[[ unsigned char*->char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 7 ]]
|
||||
[[ unsigned char*->signed char ][ !!! *<1* !!! ][ 42 ][ 17 ][ 8 ]]
|
||||
[[ unsigned char*->unsigned char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 8 ]]
|
||||
[[ unsigned char*->int ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]]
|
||||
[[ unsigned char*->short ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]]
|
||||
[[ unsigned char*->long int ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]]
|
||||
[[ unsigned char*->long long ][ !!! *8* !!! ][ 72 ][ 47 ][ 11 ]]
|
||||
[[ unsigned char*->unsigned int ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]]
|
||||
[[ unsigned char*->unsigned short ][ !!! *8* !!! ][ 72 ][ 48 ][ 10 ]]
|
||||
[[ unsigned char*->unsigned long int ][ !!! *8* !!! ][ 71 ][ 46 ][ 10 ]]
|
||||
[[ unsigned char*->unsigned long long ][ !!! *8* !!! ][ 70 ][ 45 ][ 11 ]]
|
||||
[[ unsigned char*->float ][ !!! *14* !!! ][ 589 ][ 564 ][ 38 ]]
|
||||
[[ unsigned char*->double ][ 601 ][ 615 ][ 588 ][ !!! *37* !!! ]]
|
||||
[[ unsigned char*->long double ][ 628 ][ 644 ][ 620 ][ !!! *38* !!! ]]
|
||||
[[ unsigned char*->array<char, 50> ][ !!! *1* !!! ][ 54 ][ 28 ][ 11 ]]
|
||||
[[ unsigned char*->string ][ !!! *2* !!! ][ 59 ][ 36 ][ --- ]]
|
||||
[[ unsigned char*->container::string ][ !!! *3* !!! ][ 54 ][ 30 ][ --- ]]
|
||||
[[ signed char*->char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 7 ]]
|
||||
[[ signed char*->signed char ][ !!! *<1* !!! ][ 43 ][ 17 ][ 8 ]]
|
||||
[[ signed char*->unsigned char ][ !!! *<1* !!! ][ 42 ][ 17 ][ 8 ]]
|
||||
[[ signed char*->int ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]]
|
||||
[[ signed char*->short ][ !!! *8* !!! ][ 72 ][ 48 ][ 10 ]]
|
||||
[[ signed char*->long int ][ !!! *8* !!! ][ 71 ][ 47 ][ 10 ]]
|
||||
[[ signed char*->long long ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]]
|
||||
[[ signed char*->unsigned int ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]]
|
||||
[[ signed char*->unsigned short ][ !!! *8* !!! ][ 72 ][ 47 ][ 10 ]]
|
||||
[[ signed char*->unsigned long int ][ !!! *8* !!! ][ 70 ][ 46 ][ 10 ]]
|
||||
[[ signed char*->unsigned long long ][ !!! *8* !!! ][ 70 ][ 46 ][ 11 ]]
|
||||
[[ signed char*->float ][ !!! *14* !!! ][ 586 ][ 562 ][ 37 ]]
|
||||
[[ signed char*->double ][ 603 ][ 615 ][ 589 ][ !!! *37* !!! ]]
|
||||
[[ signed char*->long double ][ 630 ][ 644 ][ 623 ][ !!! *40* !!! ]]
|
||||
[[ signed char*->array<char, 50> ][ !!! *1* !!! ][ 54 ][ 28 ][ 11 ]]
|
||||
[[ signed char*->string ][ !!! *2* !!! ][ 59 ][ 36 ][ --- ]]
|
||||
[[ signed char*->container::string ][ !!! *3* !!! ][ 54 ][ 30 ][ --- ]]
|
||||
[[ iterator_range<char*>->char ][ !!! *<1* !!! ][ 74 ][ 46 ][ 7 ]]
|
||||
[[ iterator_range<char*>->signed char ][ !!! *<1* !!! ][ 75 ][ 46 ][ 8 ]]
|
||||
[[ iterator_range<char*>->unsigned char ][ !!! *<1* !!! ][ 74 ][ 46 ][ 8 ]]
|
||||
[[ iterator_range<char*>->int ][ !!! *8* !!! ][ 98 ][ 70 ][ 10 ]]
|
||||
[[ iterator_range<char*>->short ][ !!! *8* !!! ][ 103 ][ 72 ][ 10 ]]
|
||||
[[ iterator_range<char*>->long int ][ !!! *8* !!! ][ 111 ][ 71 ][ 10 ]]
|
||||
[[ iterator_range<char*>->long long ][ !!! *8* !!! ][ 98 ][ 70 ][ 10 ]]
|
||||
[[ iterator_range<char*>->unsigned int ][ !!! *7* !!! ][ 103 ][ 76 ][ 10 ]]
|
||||
[[ iterator_range<char*>->unsigned short ][ !!! *8* !!! ][ 104 ][ 75 ][ 10 ]]
|
||||
[[ iterator_range<char*>->unsigned long int ][ !!! *7* !!! ][ 104 ][ 71 ][ 10 ]]
|
||||
[[ iterator_range<char*>->unsigned long long ][ !!! *8* !!! ][ 99 ][ 71 ][ 11 ]]
|
||||
[[ iterator_range<char*>->float ][ !!! *13* !!! ][ 123 ][ 93 ][ 37 ]]
|
||||
[[ iterator_range<char*>->double ][ 603 ][ 111 ][ 82 ][ !!! *38* !!! ]]
|
||||
[[ iterator_range<char*>->long double ][ 629 ][ 116 ][ 83 ][ !!! *38* !!! ]]
|
||||
[[ iterator_range<char*>->array<char, 50> ][ !!! *<1* !!! ][ 82 ][ 52 ][ 11 ]]
|
||||
[[ iterator_range<char*>->string ][ !!! *2* !!! ][ 83 ][ 56 ][ --- ]]
|
||||
[[ iterator_range<char*>->container::string ][ !!! *2* !!! ][ 81 ][ 53 ][ --- ]]
|
||||
[[ array<char, 50>->char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 7 ]]
|
||||
[[ array<char, 50>->signed char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 8 ]]
|
||||
[[ array<char, 50>->unsigned char ][ !!! *<1* !!! ][ 41 ][ 17 ][ 8 ]]
|
||||
[[ array<char, 50>->int ][ !!! *8* !!! ][ 73 ][ 46 ][ 10 ]]
|
||||
[[ array<char, 50>->short ][ !!! *8* !!! ][ 73 ][ 47 ][ 10 ]]
|
||||
[[ array<char, 50>->long int ][ !!! *8* !!! ][ 75 ][ 48 ][ 10 ]]
|
||||
[[ array<char, 50>->long long ][ !!! *8* !!! ][ 73 ][ 48 ][ 11 ]]
|
||||
[[ array<char, 50>->unsigned int ][ !!! *8* !!! ][ 73 ][ 47 ][ 10 ]]
|
||||
[[ array<char, 50>->unsigned short ][ !!! *8* !!! ][ 74 ][ 50 ][ 10 ]]
|
||||
[[ array<char, 50>->unsigned long int ][ !!! *8* !!! ][ 71 ][ 46 ][ 10 ]]
|
||||
[[ array<char, 50>->unsigned long long ][ !!! *8* !!! ][ 70 ][ 47 ][ 11 ]]
|
||||
[[ array<char, 50>->float ][ !!! *14* !!! ][ 586 ][ 567 ][ 37 ]]
|
||||
[[ array<char, 50>->double ][ 599 ][ 624 ][ 590 ][ !!! *37* !!! ]]
|
||||
[[ array<char, 50>->long double ][ 632 ][ 643 ][ 618 ][ !!! *37* !!! ]]
|
||||
[[ array<char, 50>->array<char, 50> ][ !!! *1* !!! ][ 52 ][ 28 ][ 11 ]]
|
||||
[[ array<char, 50>->string ][ !!! *2* !!! ][ 59 ][ 34 ][ --- ]]
|
||||
[[ array<char, 50>->container::string ][ !!! *3* !!! ][ 55 ][ 30 ][ --- ]]
|
||||
[[ int->int ][ !!! *<1* !!! ][ 105 ][ 79 ][ --- ]]
|
||||
[[ float->double ][ !!! *<1* !!! ][ 226 ][ 188 ][ --- ]]
|
||||
[[ char->signed char ][ !!! *<1* !!! ][ 40 ][ 16 ][ --- ]]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[/ END of section, generated by performance measuring program ]
|
||||
[endsect]
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright 2013 Antony Polukhin
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See the accompanying file LICENSE_1_0.txt
|
||||
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||
|
||||
//[lexical_cast_args_example
|
||||
//`The following example treats command line arguments as a sequence of numeric data
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <vector>
|
||||
|
||||
int main(int /*argc*/, char * argv[])
|
||||
{
|
||||
using boost::lexical_cast;
|
||||
using boost::bad_lexical_cast;
|
||||
|
||||
std::vector<short> args;
|
||||
|
||||
while (*++argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
args.push_back(lexical_cast<short>(*argv));
|
||||
}
|
||||
catch(const bad_lexical_cast &)
|
||||
{
|
||||
args.push_back(0);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
//] [/lexical_cast_args_example]
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright 2013 Antony Polukhin
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See the accompanying file LICENSE_1_0.txt
|
||||
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||
|
||||
|
||||
//[lexical_cast_stringize
|
||||
/*`
|
||||
In this example we'll make a `stringize` method that accepts a sequence, converts
|
||||
each element of the sequence into string and appends that string to the result.
|
||||
|
||||
Example is based on the example from the [@http://www.packtpub.com/boost-cplusplus-application-development-cookbook/book Boost C++ Application Development Cookbook]
|
||||
by Antony Polukhin, ISBN 9781849514880.
|
||||
|
||||
Step 1: Making a functor that converts any type to a string and remembers result:
|
||||
*/
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
struct stringize_functor {
|
||||
private:
|
||||
std::string& result;
|
||||
|
||||
public:
|
||||
explicit stringize_functor(std::string& res)
|
||||
: result(res)
|
||||
{}
|
||||
|
||||
template <class T>
|
||||
void operator()(const T& v) const {
|
||||
result += boost::lexical_cast<std::string>(v);
|
||||
}
|
||||
};
|
||||
|
||||
//` Step 2: Applying `stringize_functor` to each element in sequence:
|
||||
#include <boost/fusion/include/for_each.hpp>
|
||||
template <class Sequence>
|
||||
std::string stringize(const Sequence& seq) {
|
||||
std::string result;
|
||||
boost::fusion::for_each(seq, stringize_functor(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
//` Step 3: Using the `stringize` with different types:
|
||||
#include <cassert>
|
||||
#include <boost/fusion/adapted/boost_tuple.hpp>
|
||||
#include <boost/fusion/adapted/std_pair.hpp>
|
||||
|
||||
int main() {
|
||||
boost::tuple<char, int, char, int> decim('-', 10, 'e', 5);
|
||||
assert(stringize(decim) == "-10e5");
|
||||
|
||||
std::pair<short, std::string> value_and_type(270, "Kelvin");
|
||||
assert(stringize(value_and_type) == "270Kelvin");
|
||||
}
|
||||
|
||||
//] [/lexical_cast_stringize]
|
||||
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// Copyright 2013 Antony Polukhin
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See the accompanying file LICENSE_1_0.txt
|
||||
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
//[lexical_cast_log_errno
|
||||
//`The following example uses numeric data in a string expression:
|
||||
|
||||
void log_message(const std::string &);
|
||||
|
||||
void log_errno(int yoko)
|
||||
{
|
||||
log_message("Error " + boost::lexical_cast<std::string>(yoko) + ": " + strerror(yoko));
|
||||
}
|
||||
|
||||
//] [/lexical_cast_log_errno]
|
||||
|
||||
|
||||
//[lexical_cast_fixed_buffer
|
||||
//`The following example converts some number and puts it to file:
|
||||
|
||||
void number_to_file(int number, FILE* file)
|
||||
{
|
||||
typedef boost::array<char, 50> buf_t; // You can use std::array if your compiler supports it
|
||||
buf_t buffer = boost::lexical_cast<buf_t>(number); // No dynamic memory allocation
|
||||
fputs(buffer.begin(), file);
|
||||
}
|
||||
|
||||
//] [/lexical_cast_fixed_buffer]
|
||||
|
||||
//[lexical_cast_substring_conversion
|
||||
//`The following example takes part of the string and converts it to `int`:
|
||||
|
||||
int convert_strings_part(const std::string& s, std::size_t pos, std::size_t n)
|
||||
{
|
||||
return boost::lexical_cast<int>(s.data() + pos, n);
|
||||
}
|
||||
|
||||
//] [/lexical_cast_substring_conversion]
|
||||
|
||||
void log_message(const std::string &) {}
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright 2013 Antony Polukhin
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See the accompanying file LICENSE_1_0.txt
|
||||
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||
|
||||
|
||||
//[lexical_cast_variant_to_long_double
|
||||
/*`
|
||||
In this example we'll make a `to_long_double` method that converts value of the Boost.Variant to `long double`.
|
||||
*/
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
#include <cassert>
|
||||
|
||||
struct to_long_double_functor: boost::static_visitor<long double> {
|
||||
template <class T>
|
||||
long double operator()(const T& v) const {
|
||||
// Lexical cast has many optimizations including optimizations for situations that usually
|
||||
// occur in generic programming, like std::string to std::string or arithmetic type to arithmetic type conversion.
|
||||
return boost::lexical_cast<long double>(v);
|
||||
}
|
||||
};
|
||||
|
||||
// Throws `boost::bad_lexical_cast` if value of the variant is not convertible to `long double`
|
||||
template <class Variant>
|
||||
long double to_long_double(const Variant& v) {
|
||||
return boost::apply_visitor(to_long_double_functor(), v);
|
||||
}
|
||||
|
||||
int main() {
|
||||
boost::variant<char, int, std::string> v1('0'), v2("10.0001"), v3(1);
|
||||
|
||||
long double sum = to_long_double(v1) + to_long_double(v2) + to_long_double(v3);
|
||||
assert(sum > 11 && sum < 11.1);
|
||||
}
|
||||
|
||||
//] [/lexical_cast_variant_to_long_double]
|
||||
+15
-2
@@ -50,6 +50,17 @@
|
||||
# include <boost/limits.hpp>
|
||||
# include <boost/detail/select_type.hpp>
|
||||
|
||||
// It has been demonstrated numerous times that MSVC 6.0 fails silently at link
|
||||
// time if you use a template function which has template parameters that don't
|
||||
// appear in the function's argument list.
|
||||
//
|
||||
// TODO: Add this to config.hpp?
|
||||
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
|
||||
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
|
||||
# else
|
||||
# define BOOST_EXPLICIT_DEFAULT_TARGET
|
||||
# endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
// See the documentation for descriptions of how to choose between
|
||||
@@ -62,7 +73,7 @@ namespace boost
|
||||
// section 15.8 exercise 1, page 425.
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target polymorphic_cast(Source* x)
|
||||
inline Target polymorphic_cast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
|
||||
{
|
||||
Target tmp = dynamic_cast<Target>(x);
|
||||
if ( tmp == 0 ) throw std::bad_cast();
|
||||
@@ -81,12 +92,14 @@ namespace boost
|
||||
// Contributed by Dave Abrahams
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target polymorphic_downcast(Source* x)
|
||||
inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
|
||||
{
|
||||
BOOST_ASSERT( dynamic_cast<Target>(x) == x ); // detect logic error
|
||||
return static_cast<Target>(x);
|
||||
}
|
||||
|
||||
# undef BOOST_EXPLICIT_DEFAULT_TARGET
|
||||
|
||||
} // namespace boost
|
||||
|
||||
# include <boost/numeric/conversion/cast.hpp>
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost detail/templated_streams.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2013 John Maddock, Antony Polukhin
|
||||
//
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_DETAIL_BASIC_POINTERBUF_HPP
|
||||
#define BOOST_DETAIL_BASIC_POINTERBUF_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include <streambuf>
|
||||
|
||||
namespace boost { namespace detail {
|
||||
|
||||
//
|
||||
// class basic_pointerbuf:
|
||||
// acts as a stream buffer which wraps around a pair of pointers:
|
||||
//
|
||||
template <class charT, class BufferT >
|
||||
class basic_pointerbuf : public BufferT {
|
||||
protected:
|
||||
typedef BufferT base_type;
|
||||
typedef basic_pointerbuf<charT, BufferT> this_type;
|
||||
typedef typename base_type::int_type int_type;
|
||||
typedef typename base_type::char_type char_type;
|
||||
typedef typename base_type::pos_type pos_type;
|
||||
typedef ::std::streamsize streamsize;
|
||||
typedef typename base_type::off_type off_type;
|
||||
|
||||
public:
|
||||
basic_pointerbuf() : base_type() { setbuf(0, 0); }
|
||||
const charT* getnext() { return this->gptr(); }
|
||||
|
||||
#ifndef BOOST_NO_USING_TEMPLATE
|
||||
using base_type::pptr;
|
||||
using base_type::pbase;
|
||||
#else
|
||||
charT* pptr() const { return base_type::pptr(); }
|
||||
charT* pbase() const { return base_type::pbase(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// VC mistakenly assumes that `setbuf` and other functions are not referenced.
|
||||
// Marking those functions with `inline` suppresses the warnings.
|
||||
// There must be no harm from marking virtual functions as inline: inline virtual
|
||||
// call can be inlined ONLY when the compiler knows the "exact class".
|
||||
inline base_type* setbuf(char_type* s, streamsize n);
|
||||
inline typename this_type::pos_type seekpos(pos_type sp, ::std::ios_base::openmode which);
|
||||
inline typename this_type::pos_type seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which);
|
||||
|
||||
private:
|
||||
basic_pointerbuf& operator=(const basic_pointerbuf&);
|
||||
basic_pointerbuf(const basic_pointerbuf&);
|
||||
};
|
||||
|
||||
template<class charT, class BufferT>
|
||||
BufferT*
|
||||
basic_pointerbuf<charT, BufferT>::setbuf(char_type* s, streamsize n)
|
||||
{
|
||||
this->setg(s, s, s + n);
|
||||
return this;
|
||||
}
|
||||
|
||||
template<class charT, class BufferT>
|
||||
typename basic_pointerbuf<charT, BufferT>::pos_type
|
||||
basic_pointerbuf<charT, BufferT>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which)
|
||||
{
|
||||
typedef typename boost::int_t<sizeof(way) * CHAR_BIT>::least cast_type;
|
||||
|
||||
if(which & ::std::ios_base::out)
|
||||
return pos_type(off_type(-1));
|
||||
std::ptrdiff_t size = this->egptr() - this->eback();
|
||||
std::ptrdiff_t pos = this->gptr() - this->eback();
|
||||
charT* g = this->eback();
|
||||
switch(static_cast<cast_type>(way))
|
||||
{
|
||||
case ::std::ios_base::beg:
|
||||
if((off < 0) || (off > size))
|
||||
return pos_type(off_type(-1));
|
||||
else
|
||||
this->setg(g, g + off, g + size);
|
||||
break;
|
||||
case ::std::ios_base::end:
|
||||
if((off < 0) || (off > size))
|
||||
return pos_type(off_type(-1));
|
||||
else
|
||||
this->setg(g, g + size - off, g + size);
|
||||
break;
|
||||
case ::std::ios_base::cur:
|
||||
{
|
||||
std::ptrdiff_t newpos = static_cast<std::ptrdiff_t>(pos + off);
|
||||
if((newpos < 0) || (newpos > size))
|
||||
return pos_type(off_type(-1));
|
||||
else
|
||||
this->setg(g, g + newpos, g + size);
|
||||
break;
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4244)
|
||||
#endif
|
||||
return static_cast<pos_type>(this->gptr() - this->eback());
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class charT, class BufferT>
|
||||
typename basic_pointerbuf<charT, BufferT>::pos_type
|
||||
basic_pointerbuf<charT, BufferT>::seekpos(pos_type sp, ::std::ios_base::openmode which)
|
||||
{
|
||||
if(which & ::std::ios_base::out)
|
||||
return pos_type(off_type(-1));
|
||||
off_type size = static_cast<off_type>(this->egptr() - this->eback());
|
||||
charT* g = this->eback();
|
||||
if(off_type(sp) <= size)
|
||||
{
|
||||
this->setg(g, g + off_type(sp), g + size);
|
||||
}
|
||||
return pos_type(off_type(-1));
|
||||
}
|
||||
|
||||
}} // namespace boost::detail
|
||||
|
||||
#endif // BOOST_DETAIL_BASIC_POINTERBUF_HPP
|
||||
|
||||
+1202
-1215
File diff suppressed because it is too large
Load Diff
+2
-13
@@ -6,13 +6,6 @@
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Boost Conversion Library</title>
|
||||
<style>
|
||||
.copyright
|
||||
{
|
||||
color: #666666;
|
||||
font-size: small;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
@@ -39,11 +32,7 @@ supplied by several headers:</p>
|
||||
<p>Revised <!--webbot bot="Timestamp" S-Type="EDITED"
|
||||
S-Format="%d %B, %Y" startspan -->June 23, 2005<!--webbot bot="Timestamp" endspan i-checksum="30348" -->
|
||||
</p>
|
||||
<p class="copyright">
|
||||
Copyright 2001 Beman Dawes.
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <boost/type_traits/integral_promotion.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm> // std::transform
|
||||
#include <memory>
|
||||
|
||||
#if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \
|
||||
@@ -67,13 +66,13 @@ void test_conversion_to_bool();
|
||||
void test_conversion_with_nonconst_char();
|
||||
void test_conversion_to_string();
|
||||
void test_conversion_from_to_wchar_t_alias();
|
||||
void test_conversion_to_pointer();
|
||||
void test_conversion_from_wchar_t();
|
||||
void test_conversion_to_wchar_t();
|
||||
void test_conversion_from_wstring();
|
||||
void test_conversion_to_wstring();
|
||||
void test_bad_lexical_cast();
|
||||
void test_no_whitespace_stripping();
|
||||
void test_volatile_types_conversions();
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
void test_traits();
|
||||
void test_wtraits();
|
||||
@@ -82,13 +81,12 @@ void test_wallocator();
|
||||
#endif
|
||||
void test_char_types_conversions();
|
||||
void operators_overload_test();
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
void test_char16_conversions();
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
void test_char32_conversions();
|
||||
#endif
|
||||
void test_getting_pointer_to_function();
|
||||
|
||||
unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
{
|
||||
@@ -99,6 +97,7 @@ unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_to_double));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_to_bool));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_from_to_wchar_t_alias));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_to_pointer));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_to_string));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_with_nonconst_char));
|
||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||
@@ -109,7 +108,6 @@ unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
#endif
|
||||
suite->add(BOOST_TEST_CASE(test_bad_lexical_cast));
|
||||
suite->add(BOOST_TEST_CASE(test_no_whitespace_stripping));
|
||||
suite->add(BOOST_TEST_CASE(test_volatile_types_conversions));
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
suite->add(BOOST_TEST_CASE(&test_traits));
|
||||
suite->add(BOOST_TEST_CASE(&test_wtraits));
|
||||
@@ -119,13 +117,12 @@ unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
|
||||
suite->add(BOOST_TEST_CASE(&test_char_types_conversions));
|
||||
suite->add(BOOST_TEST_CASE(&operators_overload_test));
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
suite->add(BOOST_TEST_CASE(&test_char16_conversions));
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
suite->add(BOOST_TEST_CASE(&test_char32_conversions));
|
||||
#endif
|
||||
suite->add(BOOST_TEST_CASE(&test_getting_pointer_to_function));
|
||||
|
||||
return suite;
|
||||
}
|
||||
@@ -242,15 +239,9 @@ void test_conversion_to_bool()
|
||||
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(0));
|
||||
BOOST_CHECK_THROW(lexical_cast<bool>(123), bad_lexical_cast);
|
||||
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(1.0));
|
||||
BOOST_CHECK_THROW(lexical_cast<bool>(-123), bad_lexical_cast);
|
||||
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(0.0));
|
||||
BOOST_CHECK_THROW(lexical_cast<bool>(1234), bad_lexical_cast);
|
||||
#if !defined(_CRAYC)
|
||||
// Looks like a bug in CRAY compiler (throws bad_lexical_cast)
|
||||
// TODO: localize the bug and report it to developers.
|
||||
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(true));
|
||||
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(false));
|
||||
#endif
|
||||
BOOST_CHECK_EQUAL(true, lexical_cast<bool>("1"));
|
||||
BOOST_CHECK_EQUAL(false, lexical_cast<bool>("0"));
|
||||
BOOST_CHECK_THROW(lexical_cast<bool>(""), bad_lexical_cast);
|
||||
@@ -310,6 +301,14 @@ void test_conversion_from_to_wchar_t_alias()
|
||||
BOOST_CHECK_EQUAL(std::string("123"), lexical_cast<std::string>(123ul));
|
||||
}
|
||||
|
||||
void test_conversion_to_pointer()
|
||||
{
|
||||
BOOST_CHECK_THROW(lexical_cast<char *>("Test"), bad_lexical_cast);
|
||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||
BOOST_CHECK_THROW(lexical_cast<wchar_t *>("Test"), bad_lexical_cast);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_conversion_from_wchar_t()
|
||||
{
|
||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||
@@ -436,17 +435,6 @@ void test_no_whitespace_stripping()
|
||||
BOOST_CHECK_THROW(lexical_cast<int>("123 "), bad_lexical_cast);
|
||||
}
|
||||
|
||||
void test_volatile_types_conversions()
|
||||
{
|
||||
volatile int i1 = 100000;
|
||||
BOOST_CHECK_EQUAL("100000", boost::lexical_cast<std::string>(i1));
|
||||
|
||||
volatile const int i2 = 100000;
|
||||
BOOST_CHECK_EQUAL("100000", boost::lexical_cast<std::string>(i2));
|
||||
|
||||
volatile const long int i3 = 1000000;
|
||||
BOOST_CHECK_EQUAL("1000000", boost::lexical_cast<std::string>(i3));
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
void test_traits()
|
||||
@@ -473,11 +461,6 @@ void test_wtraits()
|
||||
|
||||
void test_allocator()
|
||||
{
|
||||
// Following test cause compilation error on MSVC2012:
|
||||
// (Reason: cannot convert from 'std::_Wrap_alloc<_Alloc>' to 'const my_allocator<CharT>')
|
||||
//
|
||||
// MSVC developer is notified about this issue
|
||||
#if !defined(_MSC_VER) || (_MSC_VER < 1700)
|
||||
typedef std::basic_string< char
|
||||
, std::char_traits<char>
|
||||
, my_allocator<char>
|
||||
@@ -490,16 +473,10 @@ void test_allocator()
|
||||
BOOST_CHECK(boost::lexical_cast<my_string>(1) == "1");
|
||||
BOOST_CHECK(boost::lexical_cast<my_string>("s") == s);
|
||||
BOOST_CHECK(boost::lexical_cast<my_string>(std::string("s")) == s);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_wallocator()
|
||||
{
|
||||
// Following test cause compilation error on MSVC2012:
|
||||
// (Reason: cannot convert from 'std::_Wrap_alloc<_Alloc>' to 'const my_allocator<CharT>')
|
||||
//
|
||||
// MSVC developer is notified about this issue
|
||||
#if !defined(_MSC_VER) || (_MSC_VER < 1700)
|
||||
typedef std::basic_string< wchar_t
|
||||
, std::char_traits<wchar_t>
|
||||
, my_allocator<wchar_t>
|
||||
@@ -512,7 +489,6 @@ void test_wallocator()
|
||||
BOOST_CHECK(boost::lexical_cast<my_string>(1) == L"1");
|
||||
BOOST_CHECK(boost::lexical_cast<my_string>(L"s") == s);
|
||||
BOOST_CHECK(boost::lexical_cast<my_string>(std::wstring(L"s")) == s);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -582,7 +558,7 @@ void operators_overload_test()
|
||||
}
|
||||
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
void test_char16_conversions()
|
||||
{
|
||||
BOOST_CHECK(u"100" == lexical_cast<std::u16string>(u"100"));
|
||||
@@ -590,7 +566,7 @@ void test_char16_conversions()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
void test_char32_conversions()
|
||||
{
|
||||
BOOST_CHECK(U"100" == lexical_cast<std::u32string>(U"100"));
|
||||
@@ -598,25 +574,4 @@ void test_char32_conversions()
|
||||
}
|
||||
#endif
|
||||
|
||||
void test_getting_pointer_to_function()
|
||||
{
|
||||
// Just checking that &lexical_cast<To, From> is not ambiguous
|
||||
typedef char char_arr[4];
|
||||
typedef int(*f1)(const char_arr&);
|
||||
f1 p1 = &boost::lexical_cast<int, char_arr>;
|
||||
BOOST_CHECK(p1);
|
||||
|
||||
typedef int(*f2)(const std::string&);
|
||||
f2 p2 = &boost::lexical_cast<int, std::string>;
|
||||
BOOST_CHECK(p2);
|
||||
|
||||
typedef std::string(*f3)(const int&);
|
||||
f3 p3 = &boost::lexical_cast<std::string, int>;
|
||||
BOOST_CHECK(p3);
|
||||
|
||||
std::vector<int> values;
|
||||
std::vector<std::string> ret;
|
||||
std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast<std::string, int>);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ using namespace boost;
|
||||
using std::cout;
|
||||
|
||||
|
||||
int test_main( int , char * [] )
|
||||
int test_main( int argc, char * argv[] )
|
||||
{
|
||||
|
||||
# ifdef NDEBUG
|
||||
@@ -48,7 +48,7 @@ int test_main( int , char * [] )
|
||||
long large_negative_value = LONG_MIN;
|
||||
signed char c = 0;
|
||||
|
||||
c = static_cast<signed char>(large_value);
|
||||
c = large_value; // see if compiler generates warning
|
||||
|
||||
c = numeric_cast<signed char>( small_value );
|
||||
BOOST_CHECK( c == 1 );
|
||||
@@ -96,6 +96,5 @@ int test_main( int , char * [] )
|
||||
{ cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
|
||||
BOOST_CHECK ( caught_exception );
|
||||
|
||||
(void)ul; // Supressing GCC warning about set but unused wariable
|
||||
return 0 ;
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
// what: simple unit test framework
|
||||
// who: developed by Kevlin Henney
|
||||
// when: November 2000
|
||||
// where: tested with BCC 5.5, MSVC 6.0, and g++ 2.91
|
||||
//
|
||||
// ChangeLog:
|
||||
// 20 Jan 2001 - Fixed a warning for MSVC (Dave Abrahams)
|
||||
|
||||
#ifndef TEST_INCLUDED
|
||||
#define TEST_INCLUDED
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <strstream> // for out-of-the-box g++
|
||||
#include <string>
|
||||
|
||||
namespace test // test tuple comprises name and nullary function (object)
|
||||
{
|
||||
template<typename string_type, typename function_type>
|
||||
struct test
|
||||
{
|
||||
string_type name;
|
||||
function_type action;
|
||||
|
||||
static test make(string_type name, function_type action)
|
||||
{
|
||||
test result; // MSVC aggreggate initializer bugs
|
||||
result.name = name;
|
||||
result.action = action;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace test // failure exception used to indicate checked test failures
|
||||
{
|
||||
class failure : public std::exception
|
||||
{
|
||||
public: // struction (default cases are OK)
|
||||
|
||||
failure(const std::string & why)
|
||||
: reason(why)
|
||||
{
|
||||
}
|
||||
|
||||
// std::~string has no exception-specification (could throw anything),
|
||||
// but we need to be compatible with std::~exception's empty one
|
||||
// see std::15.4p13 and std::15.4p3
|
||||
~failure() throw()
|
||||
{
|
||||
}
|
||||
|
||||
public: // usage
|
||||
|
||||
virtual const char * what() const throw()
|
||||
{
|
||||
return reason.c_str();
|
||||
}
|
||||
|
||||
private: // representation
|
||||
|
||||
std::string reason;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
namespace test // not_implemented exception used to mark unimplemented tests
|
||||
{
|
||||
class not_implemented : public std::exception
|
||||
{
|
||||
public: // usage (default ctor and dtor are OK)
|
||||
|
||||
virtual const char * what() const throw()
|
||||
{
|
||||
return "not implemented";
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
namespace test // test utilities
|
||||
{
|
||||
inline void check(bool condition, const std::string & description)
|
||||
{
|
||||
if(!condition)
|
||||
{
|
||||
throw failure(description);
|
||||
}
|
||||
}
|
||||
|
||||
inline void check_true(bool value, const std::string & description)
|
||||
{
|
||||
check(value, "expected true: " + description);
|
||||
}
|
||||
|
||||
inline void check_false(bool value, const std::string & description)
|
||||
{
|
||||
check(!value, "expected false: " + description);
|
||||
}
|
||||
|
||||
template<typename lhs_type, typename rhs_type>
|
||||
void check_equal(
|
||||
const lhs_type & lhs, const rhs_type & rhs,
|
||||
const std::string & description)
|
||||
{
|
||||
check(lhs == rhs, "expected equal values: " + description);
|
||||
}
|
||||
|
||||
template<typename lhs_type, typename rhs_type>
|
||||
void check_unequal(
|
||||
const lhs_type & lhs, const rhs_type & rhs,
|
||||
const std::string & description)
|
||||
{
|
||||
check(lhs != rhs, "expected unequal values: " + description);
|
||||
}
|
||||
|
||||
inline void check_null(const void* ptr, const std::string & description)
|
||||
{
|
||||
check(!ptr, "expected null pointer: " + description);
|
||||
}
|
||||
|
||||
inline void check_non_null(const void* ptr, const std::string & description)
|
||||
{
|
||||
check(ptr != 0, "expected non-null pointer: " + description);
|
||||
}
|
||||
}
|
||||
|
||||
#define TEST_CHECK_THROW(expression, exception, description) \
|
||||
try \
|
||||
{ \
|
||||
expression; \
|
||||
throw ::test::failure(description); \
|
||||
} \
|
||||
catch(exception &) \
|
||||
{ \
|
||||
}
|
||||
|
||||
namespace test // memory tracking (enabled if test new and delete linked in)
|
||||
{
|
||||
class allocations
|
||||
{
|
||||
public: // singleton access
|
||||
|
||||
static allocations & instance()
|
||||
{
|
||||
static allocations singleton;
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public: // logging
|
||||
|
||||
void clear()
|
||||
{
|
||||
alloc_count = dealloc_count = 0;
|
||||
}
|
||||
|
||||
void allocation()
|
||||
{
|
||||
++alloc_count;
|
||||
}
|
||||
|
||||
void deallocation()
|
||||
{
|
||||
++dealloc_count;
|
||||
}
|
||||
|
||||
public: // reporting
|
||||
|
||||
unsigned long allocated() const
|
||||
{
|
||||
return alloc_count;
|
||||
}
|
||||
|
||||
unsigned long deallocated() const
|
||||
{
|
||||
return dealloc_count;
|
||||
}
|
||||
|
||||
bool balanced() const
|
||||
{
|
||||
return alloc_count == dealloc_count;
|
||||
}
|
||||
|
||||
private: // structors (default dtor is fine)
|
||||
|
||||
allocations()
|
||||
: alloc_count(0), dealloc_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
private: // prevention
|
||||
|
||||
allocations(const allocations &);
|
||||
allocations & operator=(const allocations &);
|
||||
|
||||
private: // state
|
||||
|
||||
unsigned long alloc_count, dealloc_count;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
namespace test // tester is the driver class for a sequence of tests
|
||||
{
|
||||
template<typename test_iterator>
|
||||
class tester
|
||||
{
|
||||
public: // structors (default destructor is OK)
|
||||
|
||||
tester(test_iterator first_test, test_iterator after_last_test)
|
||||
: begin(first_test), end(after_last_test)
|
||||
{
|
||||
}
|
||||
|
||||
public: // usage
|
||||
|
||||
bool operator()(); // returns true if all tests passed
|
||||
|
||||
private: // representation
|
||||
|
||||
test_iterator begin, end;
|
||||
|
||||
private: // prevention
|
||||
|
||||
tester(const tester &);
|
||||
tester &operator=(const tester &);
|
||||
|
||||
};
|
||||
|
||||
template<typename test_iterator>
|
||||
bool tester<test_iterator>::operator()()
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
unsigned long passed = 0, failed = 0, unimplemented = 0;
|
||||
|
||||
for(test_iterator current = begin; current != end; ++current)
|
||||
{
|
||||
cerr << "[" << current->name << "] " << flush;
|
||||
string result = "passed"; // optimistic
|
||||
|
||||
try
|
||||
{
|
||||
allocations::instance().clear();
|
||||
current->action();
|
||||
|
||||
if(!allocations::instance().balanced())
|
||||
{
|
||||
unsigned long allocated = allocations::instance().allocated();
|
||||
unsigned long deallocated = allocations::instance().deallocated();
|
||||
ostrstream report;
|
||||
report << "new/delete ("
|
||||
<< allocated << " allocated, "
|
||||
<< deallocated << " deallocated)"
|
||||
<< ends;
|
||||
const char * text = report.str();
|
||||
report.freeze(false);
|
||||
throw failure(text);
|
||||
}
|
||||
|
||||
++passed;
|
||||
}
|
||||
catch(const failure & caught)
|
||||
{
|
||||
(result = "failed: ") += caught.what();
|
||||
++failed;
|
||||
}
|
||||
catch(const not_implemented &)
|
||||
{
|
||||
result = "not implemented";
|
||||
++unimplemented;
|
||||
}
|
||||
catch(const exception & caught)
|
||||
{
|
||||
(result = "exception: ") += caught.what();
|
||||
++failed;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
result = "failed with unknown exception";
|
||||
++failed;
|
||||
}
|
||||
|
||||
cerr << result << endl;
|
||||
}
|
||||
|
||||
cerr << passed + failed << " tests: "
|
||||
<< passed << " passed, "
|
||||
<< failed << " failed";
|
||||
|
||||
if(unimplemented)
|
||||
{
|
||||
cerr << " (" << unimplemented << " not implemented)";
|
||||
}
|
||||
|
||||
cerr << endl;
|
||||
|
||||
return failed == 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Copyright Kevlin Henney, 2000. All rights reserved.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
+11
-31
@@ -1,5 +1,5 @@
|
||||
# Copyright (C) 2001-2003 Douglas Gregor
|
||||
# Copyright (C) 2011-2013 Antony Polukhin
|
||||
# Copyright (C) 2011-2012 Antony Polukhin
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -12,14 +12,7 @@ project
|
||||
: requirements
|
||||
<library>/boost/test//boost_unit_test_framework
|
||||
<link>static
|
||||
<toolset>gcc-4.7:<cxxflags>-ftrapv
|
||||
<toolset>gcc-4.6:<cxxflags>-ftrapv
|
||||
<toolset>clang:<cxxflags>-ftrapv
|
||||
# default to all warnings on:
|
||||
<warnings>all
|
||||
# set warnings as errors for those compilers we know we get warning free:
|
||||
<toolset>gcc:<cxxflags>-Wextra
|
||||
<toolset>gcc:<cxxflags>-Wno-uninitialized
|
||||
<toolset>gcc-4.8:<define>BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
|
||||
;
|
||||
|
||||
# Thanks to Steven Watanabe for helping with <nowchar> feature
|
||||
@@ -30,9 +23,9 @@ feature.compose <nowchar>on : <cxxflags>/Zc:wchar_t- ;
|
||||
test-suite conversion
|
||||
: [ run implicit_cast.cpp ]
|
||||
[ compile-fail implicit_cast_fail.cpp ]
|
||||
[ run cast_test.cpp ]
|
||||
[ run numeric_cast_test.cpp ]
|
||||
[ run lexical_cast_test.cpp ]
|
||||
[ run ../cast_test.cpp ]
|
||||
[ run ../numeric_cast_test.cpp ]
|
||||
[ run ../lexical_cast_test.cpp ]
|
||||
[ run lexical_cast_loopback_test.cpp ]
|
||||
[ run lexical_cast_abstract_test.cpp ]
|
||||
[ run lexical_cast_noncopyable_test.cpp ]
|
||||
@@ -40,34 +33,21 @@ test-suite conversion
|
||||
[ run lexical_cast_wchars_test.cpp ]
|
||||
[ run lexical_cast_float_types_test.cpp ]
|
||||
[ run lexical_cast_inf_nan_test.cpp ]
|
||||
[ run lexical_cast_containers_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>clang:<cxxflags>-Wno-long-long ]
|
||||
[ run lexical_cast_containers_test.cpp ]
|
||||
[ run lexical_cast_empty_input_test.cpp ]
|
||||
[ run lexical_cast_pointers_test.cpp ]
|
||||
[ 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_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
|
||||
<toolset>gcc-4.3:<cxxflags>-fno-exceptions
|
||||
<toolset>gcc-4.4:<cxxflags>-fno-exceptions
|
||||
<toolset>gcc-4.5:<cxxflags>-fno-exceptions
|
||||
<toolset>gcc-4.6:<cxxflags>-fno-exceptions
|
||||
<toolset>gcc-4.7:<cxxflags>-fno-exceptions
|
||||
<toolset>gcc-4.8:<cxxflags>-fno-exceptions
|
||||
<toolset>clang:<cxxflags>-fno-exceptions
|
||||
<toolset>gcc-4.3:<cflags>-fno-exceptions
|
||||
<toolset>gcc-4.4:<cflags>-fno-exceptions
|
||||
<toolset>gcc-4.5:<cflags>-fno-exceptions
|
||||
<toolset>gcc-4.6:<cflags>-fno-exceptions
|
||||
<toolset>gcc-4.7:<cflags>-fno-exceptions
|
||||
]
|
||||
[ run lexical_cast_iterator_range_test.cpp ]
|
||||
[ run lexical_cast_arrays_test.cpp ]
|
||||
[ run lexical_cast_integral_types_test.cpp ]
|
||||
[ run lexical_cast_stream_detection_test.cpp ]
|
||||
[ run lexical_cast_stream_traits_test.cpp ]
|
||||
[ compile-fail lexical_cast_to_pointer_test.cpp ]
|
||||
[ run lexical_cast_filesystem_test.cpp ../../filesystem/build//boost_filesystem/<link>static ]
|
||||
;
|
||||
|
||||
# Assuring that examples compile and run. Adding sources from `example` directory to the `conversion` test suite.
|
||||
for local p in [ glob ../example/*.cpp ]
|
||||
{
|
||||
conversion += [ run $(p) ] ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ struct foo
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
foo x = implicit_cast<foo>("foobar");
|
||||
(void)x; // warning suppression.
|
||||
BOOST_CHECK(false); // suppressing warning about 'boost::unit_test::{anonymous}::unit_test_log' defined but not used
|
||||
(void)x; // warning suppression.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,14 +22,6 @@ void testing_std_array_input_conversion();
|
||||
|
||||
using namespace boost;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
|
||||
#define BOOST_LC_RUNU16
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
|
||||
#define BOOST_LC_RUNU32
|
||||
#endif
|
||||
|
||||
boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
{
|
||||
unit_test::test_suite *suite =
|
||||
@@ -58,25 +50,25 @@ static void testing_template_array_output_on_spec_value(T val)
|
||||
|
||||
{
|
||||
arr_type res1 = lexical_cast<arr_type>(val);
|
||||
BOOST_CHECK_EQUAL(&res1[0], ethalon);
|
||||
BOOST_CHECK_EQUAL(res1.begin(), ethalon);
|
||||
const arr_type res2 = lexical_cast<arr_type>(val);
|
||||
BOOST_CHECK_EQUAL(&res2[0], ethalon);
|
||||
BOOST_CHECK_EQUAL(res2.begin(), ethalon);
|
||||
BOOST_CHECK_THROW(lexical_cast<short_arr_type>(val), boost::bad_lexical_cast);
|
||||
}
|
||||
|
||||
{
|
||||
uarr_type res1 = lexical_cast<uarr_type>(val);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(&res1[0]), ethalon);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(res1.begin()), ethalon);
|
||||
const uarr_type res2 = lexical_cast<uarr_type>(val);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(&res2[0]), ethalon);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(res2.begin()), ethalon);
|
||||
BOOST_CHECK_THROW(lexical_cast<ushort_arr_type>(val), boost::bad_lexical_cast);
|
||||
}
|
||||
|
||||
{
|
||||
sarr_type res1 = lexical_cast<sarr_type>(val);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(&res1[0]), ethalon);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(res1.begin()), ethalon);
|
||||
const sarr_type res2 = lexical_cast<sarr_type>(val);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(&res2[0]), ethalon);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(res2.begin()), ethalon);
|
||||
BOOST_CHECK_THROW(lexical_cast<sshort_arr_type>(val), boost::bad_lexical_cast);
|
||||
}
|
||||
|
||||
@@ -87,49 +79,49 @@ static void testing_template_array_output_on_spec_value(T val)
|
||||
|
||||
{
|
||||
warr_type res = lexical_cast<warr_type>(val);
|
||||
BOOST_CHECK(&res[0] == wethalon);
|
||||
BOOST_CHECK(res.begin() == wethalon);
|
||||
}
|
||||
|
||||
{
|
||||
const warr_type res = lexical_cast<warr_type>(val);
|
||||
BOOST_CHECK(&res[0] == wethalon);
|
||||
BOOST_CHECK(res.begin() == wethalon);
|
||||
}
|
||||
|
||||
BOOST_CHECK_THROW(lexical_cast<wshort_arr_type>(val), boost::bad_lexical_cast);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_LC_RUNU16
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
typedef ArrayT<char16_t, 300> u16arr_type;
|
||||
typedef ArrayT<char16_t, 3> u16short_arr_type;
|
||||
std::u16string u16ethalon(u"100");
|
||||
|
||||
{
|
||||
u16arr_type res = lexical_cast<u16arr_type>(val);
|
||||
BOOST_CHECK(&res[0] == u16ethalon);
|
||||
BOOST_CHECK(res.begin() == u16ethalon);
|
||||
}
|
||||
|
||||
{
|
||||
const u16arr_type res = lexical_cast<u16arr_type>(val);
|
||||
BOOST_CHECK(&res[0] == u16ethalon);
|
||||
BOOST_CHECK(res.begin() == u16ethalon);
|
||||
}
|
||||
|
||||
BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), boost::bad_lexical_cast);
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_LC_RUNU32
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
typedef ArrayT<char32_t, 300> u32arr_type;
|
||||
typedef ArrayT<char32_t, 3> u32short_arr_type;
|
||||
std::u32string u32ethalon(U"100");
|
||||
|
||||
{
|
||||
u32arr_type res = lexical_cast<u32arr_type>(val);
|
||||
BOOST_CHECK(&res[0] == u32ethalon);
|
||||
BOOST_CHECK(res.begin() == u32ethalon);
|
||||
}
|
||||
|
||||
{
|
||||
const u32arr_type res = lexical_cast<u32arr_type>(val);
|
||||
BOOST_CHECK(&res[0] == u32ethalon);
|
||||
BOOST_CHECK(res.begin() == u32ethalon);
|
||||
}
|
||||
|
||||
BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), boost::bad_lexical_cast);
|
||||
@@ -153,25 +145,25 @@ static void testing_template_array_output_on_char_value()
|
||||
|
||||
{
|
||||
arr_type res1 = lexical_cast<arr_type>(val);
|
||||
BOOST_CHECK_EQUAL(&res1[0], ethalon);
|
||||
BOOST_CHECK_EQUAL(res1.begin(), ethalon);
|
||||
const arr_type res2 = lexical_cast<arr_type>(val);
|
||||
BOOST_CHECK_EQUAL(&res2[0], ethalon);
|
||||
BOOST_CHECK_EQUAL(res2.begin(), ethalon);
|
||||
BOOST_CHECK_THROW(lexical_cast<short_arr_type>(val), boost::bad_lexical_cast);
|
||||
}
|
||||
|
||||
{
|
||||
uarr_type res1 = lexical_cast<uarr_type>(val);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(&res1[0]), ethalon);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(res1.begin()), ethalon);
|
||||
const uarr_type res2 = lexical_cast<uarr_type>(val);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(&res2[0]), ethalon);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(res2.begin()), ethalon);
|
||||
BOOST_CHECK_THROW(lexical_cast<ushort_arr_type>(val), boost::bad_lexical_cast);
|
||||
}
|
||||
|
||||
{
|
||||
sarr_type res1 = lexical_cast<sarr_type>(val);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(&res1[0]), ethalon);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(res1.begin()), ethalon);
|
||||
const sarr_type res2 = lexical_cast<sarr_type>(val);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(&res2[0]), ethalon);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(res2.begin()), ethalon);
|
||||
BOOST_CHECK_THROW(lexical_cast<sshort_arr_type>(val), boost::bad_lexical_cast);
|
||||
}
|
||||
|
||||
@@ -182,23 +174,23 @@ static void testing_template_array_output_on_char_value()
|
||||
|
||||
{
|
||||
warr_type res = lexical_cast<warr_type>(val);
|
||||
BOOST_CHECK(&res[0] == wethalon);
|
||||
BOOST_CHECK(res.begin() == wethalon);
|
||||
warr_type res3 = lexical_cast<warr_type>(wethalon);
|
||||
BOOST_CHECK(&res3[0] == wethalon);
|
||||
BOOST_CHECK(res3.begin() == wethalon);
|
||||
}
|
||||
|
||||
{
|
||||
const warr_type res = lexical_cast<warr_type>(val);
|
||||
BOOST_CHECK(&res[0] == wethalon);
|
||||
BOOST_CHECK(res.begin() == wethalon);
|
||||
const warr_type res3 = lexical_cast<warr_type>(wethalon);
|
||||
BOOST_CHECK(&res3[0] == wethalon);
|
||||
BOOST_CHECK(res3.begin() == wethalon);
|
||||
}
|
||||
|
||||
BOOST_CHECK_THROW(lexical_cast<wshort_arr_type>(val), boost::bad_lexical_cast);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_LC_RUNU16
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
typedef ArrayT<char16_t, 300> u16arr_type;
|
||||
typedef ArrayT<char16_t, 3> u16short_arr_type;
|
||||
std::u16string u16ethalon(u"100");
|
||||
@@ -206,27 +198,26 @@ static void testing_template_array_output_on_char_value()
|
||||
{
|
||||
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
|
||||
u16arr_type res = lexical_cast<u16arr_type>(val);
|
||||
BOOST_CHECK(&res[0] == u16ethalon);
|
||||
BOOST_CHECK(res.begin() == u16ethalon);
|
||||
#endif
|
||||
|
||||
u16arr_type res3 = lexical_cast<u16arr_type>(u16ethalon);
|
||||
BOOST_CHECK(&res3[0] == u16ethalon);
|
||||
BOOST_CHECK(res3.begin() == u16ethalon);
|
||||
}
|
||||
|
||||
{
|
||||
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
|
||||
const u16arr_type res = lexical_cast<u16arr_type>(val);
|
||||
BOOST_CHECK(&res[0] == u16ethalon);
|
||||
BOOST_CHECK(res.begin() == u16ethalon);
|
||||
#endif
|
||||
const u16arr_type res3 = lexical_cast<u16arr_type>(u16ethalon);
|
||||
BOOST_CHECK(&res3[0] == u16ethalon);
|
||||
BOOST_CHECK(res3.begin() == u16ethalon);
|
||||
}
|
||||
|
||||
// Some compillers may throw std::bad_alloc here
|
||||
BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), std::exception);
|
||||
BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), boost::bad_lexical_cast);
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_LC_RUNU32
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
typedef ArrayT<char32_t, 300> u32arr_type;
|
||||
typedef ArrayT<char32_t, 3> u32short_arr_type;
|
||||
std::u32string u32ethalon(U"100");
|
||||
@@ -234,23 +225,22 @@ static void testing_template_array_output_on_char_value()
|
||||
{
|
||||
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
|
||||
u32arr_type res = lexical_cast<u32arr_type>(val);
|
||||
BOOST_CHECK(&res[0] == u32ethalon);
|
||||
BOOST_CHECK(res.begin() == u32ethalon);
|
||||
#endif
|
||||
u32arr_type res3 = lexical_cast<u32arr_type>(u32ethalon);
|
||||
BOOST_CHECK(&res3[0] == u32ethalon);
|
||||
BOOST_CHECK(res3.begin() == u32ethalon);
|
||||
}
|
||||
|
||||
{
|
||||
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
|
||||
const u32arr_type res = lexical_cast<u32arr_type>(val);
|
||||
BOOST_CHECK(&res[0] == u32ethalon);
|
||||
BOOST_CHECK(res.begin() == u32ethalon);
|
||||
#endif
|
||||
const u32arr_type res3 = lexical_cast<u32arr_type>(u32ethalon);
|
||||
BOOST_CHECK(&res3[0] == u32ethalon);
|
||||
BOOST_CHECK(res3.begin() == u32ethalon);
|
||||
}
|
||||
|
||||
// Some compillers may throw std::bad_alloc here
|
||||
BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), std::exception);
|
||||
BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), boost::bad_lexical_cast);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -266,7 +256,7 @@ void testing_boost_array_output_conversion()
|
||||
|
||||
void testing_std_array_output_conversion()
|
||||
{
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
#if !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
|
||||
testing_template_array_output_on_char_value<std::array>();
|
||||
testing_template_array_output_on_spec_value<std::array>(100);
|
||||
testing_template_array_output_on_spec_value<std::array>(static_cast<short>(100));
|
||||
@@ -338,7 +328,7 @@ static void testing_generic_array_input_conversion()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_LC_RUNU16
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
{
|
||||
const ArrayT<const char16_t, 4> var_zero_terminated_const_var_const_char = {{ u'1', u'0', u'0', u'\0'}};
|
||||
BOOST_CHECK(lexical_cast<std::u16string>(var_zero_terminated_const_var_const_char) == u"100");
|
||||
@@ -349,7 +339,7 @@ static void testing_generic_array_input_conversion()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_LC_RUNU32
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
{
|
||||
const ArrayT<const char32_t, 4> var_zero_terminated_const_var_const_char = {{ U'1', U'0', U'0', U'\0'}};
|
||||
BOOST_CHECK(lexical_cast<std::u32string>(var_zero_terminated_const_var_const_char) == U"100");
|
||||
@@ -368,7 +358,7 @@ void testing_boost_array_input_conversion()
|
||||
|
||||
void testing_std_array_input_conversion()
|
||||
{
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
#if !defined(BOOST_NO_CXX11_HDR_ARRAY) && defined(BOOST_HAS_TR1_ARRAY)
|
||||
testing_generic_array_input_conversion<std::array>();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -71,12 +71,12 @@ void testing_boost_containers_string_widening()
|
||||
BOOST_CHECK(boost::lexical_cast<boost::container::wstring>(char_array) == wchar_array);
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
const char16_t char16_array[] = u"Test string";
|
||||
BOOST_CHECK(boost::lexical_cast<boost::container::basic_string<char16_t> >(char_array) == char16_array);
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
const char32_t char32_array[] = U"Test string";
|
||||
BOOST_CHECK(boost::lexical_cast<boost::container::basic_string<char32_t> >(char_array) == char32_array);
|
||||
#endif
|
||||
|
||||
Regular → Executable
+2
-4
@@ -32,9 +32,7 @@ void do_test_on_empty_input(T& v)
|
||||
BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
|
||||
#endif
|
||||
BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
@@ -86,12 +84,12 @@ void test_empty_string()
|
||||
#endif
|
||||
|
||||
// Currently, no compiler and STL library fully support char16_t and char32_t
|
||||
//#ifndef BOOST_NO_CXX11_CHAR16_T
|
||||
//#ifndef BOOST_NO_CHAR16_T
|
||||
// std::basic_string<char16_t> v16w;
|
||||
// do_test_on_empty_input(v16w);
|
||||
// BOOST_CHECK_THROW(lexical_cast<char16_t>(v16w), bad_lexical_cast);
|
||||
//#endif
|
||||
//#ifndef BOOST_NO_CXX11_CHAR32_T
|
||||
//#ifndef BOOST_NO_CHAR32_T
|
||||
// std::basic_string<char32_t> v32w;
|
||||
// do_test_on_empty_input(v32w);
|
||||
// BOOST_CHECK_THROW(lexical_cast<char32_t>(v32w), bad_lexical_cast);
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// Unit test for boost::lexical_cast.
|
||||
//
|
||||
// See http://www.boost.org for most recent version, including documentation.
|
||||
//
|
||||
// Copyright Antony Polukhin, 2013.
|
||||
//
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
//
|
||||
// Test lexical_cast usage with long filesystem::path. Bug 7704.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
void test_filesystem();
|
||||
|
||||
unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
{
|
||||
unit_test::test_suite *suite =
|
||||
BOOST_TEST_SUITE("lexical_cast unit test");
|
||||
suite->add(BOOST_TEST_CASE(&test_filesystem));
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
void test_filesystem()
|
||||
{
|
||||
boost::filesystem::path p;
|
||||
std::string s1 = "aaaaaaaaaaaaaaaaaaaaaaa";
|
||||
p = boost::lexical_cast<boost::filesystem::path>(s1);
|
||||
BOOST_CHECK(!p.empty());
|
||||
BOOST_CHECK_EQUAL(p, s1);
|
||||
p.clear();
|
||||
|
||||
const char ab[] = "aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
|
||||
p = boost::lexical_cast<boost::filesystem::path>(ab);
|
||||
BOOST_CHECK(!p.empty());
|
||||
BOOST_CHECK_EQUAL(p, ab);
|
||||
}
|
||||
|
||||
Regular → Executable
+10
-22
@@ -105,13 +105,13 @@ void test_conversion_from_to_float_for_locale()
|
||||
|
||||
|
||||
/*
|
||||
* Converts char* [and wchar_t*] to float number type and checks, that generated
|
||||
* number does not exceeds allowed epsilon.
|
||||
* Converts char* [and wchar_t] to float number type and checks, that generated
|
||||
* number is in interval [base_value-epsilon, base_value+epsilon].
|
||||
*/
|
||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||
#define CHECK_CLOSE_ABS_DIFF(VAL,PREFIX) \
|
||||
converted_val = lexical_cast<test_t>(#VAL); \
|
||||
BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits<test_t>::epsilon()), \
|
||||
BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits<test_t>::epsilon()), \
|
||||
(converted_val ? converted_val : std::numeric_limits<test_t>::epsilon()), \
|
||||
std::numeric_limits<test_t>::epsilon() \
|
||||
); \
|
||||
@@ -120,7 +120,7 @@ void test_conversion_from_to_float_for_locale()
|
||||
#else
|
||||
#define CHECK_CLOSE_ABS_DIFF(VAL,TYPE) \
|
||||
converted_val = lexical_cast<test_t>(#VAL); \
|
||||
BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits<test_t>::epsilon()), \
|
||||
BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits<test_t>::epsilon()), \
|
||||
(converted_val ? converted_val : std::numeric_limits<test_t>::epsilon()), \
|
||||
std::numeric_limits<test_t>::epsilon() \
|
||||
);
|
||||
@@ -264,11 +264,8 @@ void test_converion_to_float_types()
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("."), bad_lexical_cast);
|
||||
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("-B"), bad_lexical_cast);
|
||||
|
||||
// Following two tests are not valid for C++11 compilers
|
||||
//BOOST_CHECK_THROW(lexical_cast<test_t>("0xB"), bad_lexical_cast);
|
||||
//BOOST_CHECK_THROW(lexical_cast<test_t>("0x0"), bad_lexical_cast);
|
||||
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("0xB"), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("0x0"), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("--1.0"), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("1.0e--1"), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("1.0.0"), bad_lexical_cast);
|
||||
@@ -290,23 +287,19 @@ void test_float_typess_for_overflows()
|
||||
test_t minvalue = (std::numeric_limits<test_t>::min)();
|
||||
std::string s_min_value = lexical_cast<std::string>(minvalue);
|
||||
BOOST_CHECK_CLOSE_FRACTION(minvalue, lexical_cast<test_t>(minvalue), (std::numeric_limits<test_t>::epsilon()));
|
||||
BOOST_CHECK_CLOSE_FRACTION(minvalue, lexical_cast<test_t>(s_min_value), (std::numeric_limits<test_t>::epsilon() * 2));
|
||||
BOOST_CHECK_CLOSE_FRACTION(minvalue, lexical_cast<test_t>(s_min_value), (std::numeric_limits<test_t>::epsilon()));
|
||||
|
||||
test_t maxvalue = (std::numeric_limits<test_t>::max)();
|
||||
std::string s_max_value = lexical_cast<std::string>(maxvalue);
|
||||
BOOST_CHECK_CLOSE_FRACTION(maxvalue, lexical_cast<test_t>(maxvalue), (std::numeric_limits<test_t>::epsilon()));
|
||||
BOOST_CHECK_CLOSE_FRACTION(maxvalue, lexical_cast<test_t>(s_max_value), (std::numeric_limits<test_t>::epsilon()));
|
||||
|
||||
#ifndef _LIBCPP_VERSION
|
||||
// libc++ had a bug in implementation of stream conversions for values that must be represented as infinity.
|
||||
// http://llvm.org/bugs/show_bug.cgi?id=15723#c4
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>(s_max_value+"1"), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>(s_max_value+"9"), bad_lexical_cast);
|
||||
|
||||
// VC9 can fail the following tests on floats and doubles when using stingstream...
|
||||
// VC9 can fail the fllowing tests on floats and doubles when using stingstream...
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("1"+s_max_value), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<test_t>("9"+s_max_value), bad_lexical_cast);
|
||||
#endif
|
||||
|
||||
if ( is_same<test_t,float>::value )
|
||||
{
|
||||
@@ -333,14 +326,13 @@ void test_float_typess_for_overflows()
|
||||
|
||||
#undef CHECK_CLOSE_ABS_DIFF
|
||||
|
||||
// Epsilon is multiplied by 2 because of two lexical conversions
|
||||
#define TEST_TO_FROM_CAST_AROUND_TYPED(VAL,STRING_TYPE) \
|
||||
test_value = VAL + std::numeric_limits<test_t>::epsilon() * i ; \
|
||||
converted_val = lexical_cast<test_t>( lexical_cast<STRING_TYPE>(test_value) ); \
|
||||
BOOST_CHECK_CLOSE_FRACTION( \
|
||||
BOOST_CHECK_CLOSE_FRACTION( \
|
||||
test_value, \
|
||||
converted_val, \
|
||||
std::numeric_limits<test_t>::epsilon() * 2 \
|
||||
std::numeric_limits<test_t>::epsilon() \
|
||||
);
|
||||
|
||||
/*
|
||||
@@ -512,11 +504,7 @@ void test_conversion_from_to_double()
|
||||
}
|
||||
void test_conversion_from_to_long_double()
|
||||
{
|
||||
// We do not run tests on compilers with bugs
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_conversion_from_to_float<long double>();
|
||||
#endif
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Regular → Executable
-4
@@ -186,11 +186,7 @@ void test_inf_nan_double()
|
||||
|
||||
void test_inf_nan_long_double()
|
||||
{
|
||||
// We do not run tests on compilers with bugs
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_inf_nan_templated<long double >();
|
||||
#endif
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
|
||||
#include <boost/type_traits/integral_promotion.hpp>
|
||||
#include <boost/type_traits/make_unsigned.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@@ -57,8 +56,6 @@ int const lcast_integral_test_counter=500;
|
||||
|
||||
using namespace boost;
|
||||
|
||||
|
||||
|
||||
void test_conversion_from_to_short();
|
||||
void test_conversion_from_to_ushort();
|
||||
void test_conversion_from_to_int();
|
||||
@@ -71,11 +68,6 @@ void test_conversion_from_to_uintmax_t();
|
||||
void test_conversion_from_to_longlong();
|
||||
void test_conversion_from_to_ulonglong();
|
||||
#endif
|
||||
#ifdef BOOST_HAS_INT128
|
||||
void test_conversion_from_to_int128();
|
||||
void test_conversion_from_to_uint128();
|
||||
#endif
|
||||
void test_integral_conversions_on_min_max();
|
||||
|
||||
|
||||
unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
@@ -95,11 +87,6 @@ unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_longlong));
|
||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_ulonglong));
|
||||
#endif
|
||||
#ifdef BOOST_HAS_INT128
|
||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_int128));
|
||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_uint128));
|
||||
#endif
|
||||
suite->add(BOOST_TEST_CASE(&test_integral_conversions_on_min_max));
|
||||
|
||||
return suite;
|
||||
}
|
||||
@@ -243,7 +230,7 @@ void test_conversion_from_integral_to_string(CharT)
|
||||
|
||||
// Test values around 100, 1000, 10000, ...
|
||||
T ten_power = 100;
|
||||
for(int e = 2; e < limits::digits10; ++e, ten_power *= 10)
|
||||
for(int e = 2; e <= limits::digits10; ++e, ten_power *= 10)
|
||||
{
|
||||
// ten_power + 100 probably never overflows
|
||||
for(t = ten_power - 100; t != ten_power + 100; ++t)
|
||||
@@ -340,7 +327,7 @@ void test_conversion_from_string_to_integral(CharT)
|
||||
|
||||
// Test values around 100, 1000, 10000, ...
|
||||
T ten_power = 100;
|
||||
for(int e = 2; e < limits::digits10; ++e, ten_power *= 10)
|
||||
for(int e = 2; e <= limits::digits10; ++e, ten_power *= 10)
|
||||
{
|
||||
// ten_power + 100 probably never overflows
|
||||
for(t = ten_power - 100; t != ten_power + 100; ++t)
|
||||
@@ -367,36 +354,10 @@ void test_conversion_from_to_integral_for_locale()
|
||||
BOOST_CHECK( lexical_cast<T>("30000") == static_cast<T>(30000) );
|
||||
}
|
||||
|
||||
|
||||
test_conversion_from_integral_to_integral<T>();
|
||||
|
||||
// This is a part of test_conversion_from_integral_to_string<T>('0') method,
|
||||
// but with BOOST_CHECK_EQUAL instead of BOOST_CHECK. It is required to see
|
||||
// what is produced by the to_str<char>(t) method in situations when result
|
||||
// is different. BOOST_CHECK does not work with wchar_t.
|
||||
typedef std::numeric_limits<T> limits;
|
||||
T t = (limits::min)();
|
||||
BOOST_CHECK_EQUAL(lexical_cast<std::string>(t), to_str<char>(t));
|
||||
|
||||
test_conversion_from_integral_to_string<T>('0');
|
||||
test_conversion_from_string_to_integral<T>('0');
|
||||
#if !defined(BOOST_LCAST_NO_WCHAR_T)
|
||||
if (lexical_cast<std::wstring>(t) != to_str<wchar_t>(t)) {
|
||||
// Something went wrong, and now we are attempting to find and print the
|
||||
// difference.
|
||||
std::wstring wstr = to_str<wchar_t>(t);
|
||||
std::string lcast_str = lexical_cast<std::string>(t);
|
||||
std::string str;
|
||||
str.reserve(wstr.size());
|
||||
for (std::size_t i = 0; i < wstr.size(); ++i) {
|
||||
str.push_back(static_cast<char>(wstr[i]));
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL(lcast_str.length(), lexical_cast<std::wstring>(t).length());
|
||||
BOOST_CHECK_EQUAL(to_str<char>(t), str);
|
||||
BOOST_CHECK_EQUAL(lcast_str, str);
|
||||
}
|
||||
|
||||
test_conversion_from_integral_to_string<T>(L'0');
|
||||
test_conversion_from_string_to_integral<T>(L'0');
|
||||
#endif
|
||||
@@ -409,7 +370,7 @@ struct restore_oldloc
|
||||
};
|
||||
|
||||
template<class T>
|
||||
void test_conversion_from_to_integral_minimal()
|
||||
void test_conversion_from_to_integral()
|
||||
{
|
||||
char const zero = '0';
|
||||
signed char const szero = '0';
|
||||
@@ -425,12 +386,12 @@ void test_conversion_from_to_integral_minimal()
|
||||
test_conversion_from_integral_to_char<T>(wzero);
|
||||
test_conversion_from_char_to_integral<T>(wzero);
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
char16_t const u16zero = u'0';
|
||||
test_conversion_from_integral_to_char<T>(u16zero);
|
||||
test_conversion_from_char_to_integral<T>(u16zero);
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
char32_t const u32zero = u'0';
|
||||
test_conversion_from_integral_to_char<T>(u32zero);
|
||||
test_conversion_from_char_to_integral<T>(u32zero);
|
||||
@@ -466,8 +427,8 @@ void test_conversion_from_to_integral_minimal()
|
||||
// test_conversion_from_to_integral_for_locale
|
||||
|
||||
// Overflow test case from David W. Birdsall
|
||||
std::string must_owerflow_str = (sizeof(T) < 16 ? "160000000000000000000" : "1600000000000000000000000000000000000000");
|
||||
std::string must_owerflow_negative_str = (sizeof(T) < 16 ? "-160000000000000000000" : "-1600000000000000000000000000000000000000");
|
||||
std::string must_owerflow_str = "160000000000000000000";
|
||||
std::string must_owerflow_negative_str = "-160000000000000000000";
|
||||
for (int i = 0; i < 15; ++i) {
|
||||
BOOST_CHECK_THROW(lexical_cast<T>(must_owerflow_str), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<T>(must_owerflow_negative_str), bad_lexical_cast);
|
||||
@@ -475,12 +436,7 @@ void test_conversion_from_to_integral_minimal()
|
||||
must_owerflow_str += '0';
|
||||
must_owerflow_negative_str += '0';
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void test_conversion_from_to_integral()
|
||||
{
|
||||
test_conversion_from_to_integral_minimal<T>();
|
||||
typedef std::numpunct<char> numpunct;
|
||||
|
||||
restore_oldloc guard;
|
||||
@@ -579,75 +535,5 @@ void test_conversion_from_to_ulonglong()
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BOOST_HAS_INT128
|
||||
|
||||
template <bool Specialized, class T>
|
||||
struct test_if_specialized {
|
||||
static void test() {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct test_if_specialized<true, T> {
|
||||
static void test() {
|
||||
test_conversion_from_to_integral_minimal<T>();
|
||||
}
|
||||
};
|
||||
|
||||
void test_conversion_from_to_int128()
|
||||
{
|
||||
test_if_specialized<
|
||||
std::numeric_limits<boost::int128_type>::is_specialized,
|
||||
boost::int128_type
|
||||
>::test();
|
||||
}
|
||||
|
||||
void test_conversion_from_to_uint128()
|
||||
{
|
||||
test_if_specialized<
|
||||
std::numeric_limits<boost::int128_type>::is_specialized,
|
||||
boost::uint128_type
|
||||
>::test();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename SignedT>
|
||||
void test_integral_conversions_on_min_max_impl()
|
||||
{
|
||||
typedef SignedT signed_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::make_unsigned<signed_t>::type unsigned_t;
|
||||
|
||||
typedef std::numeric_limits<signed_t> s_limits;
|
||||
typedef std::numeric_limits<unsigned_t> uns_limits;
|
||||
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned_t>((uns_limits::max)()), (uns_limits::max)());
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned_t>((uns_limits::min)()), (uns_limits::min)());
|
||||
|
||||
BOOST_CHECK_EQUAL(lexical_cast<signed_t>((s_limits::max)()), (s_limits::max)());
|
||||
BOOST_CHECK_EQUAL(lexical_cast<signed_t>((uns_limits::min)()), static_cast<signed_t>((uns_limits::min)()));
|
||||
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned_t>((s_limits::max)()), static_cast<unsigned_t>((s_limits::max)()));
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned_t>((s_limits::min)()), static_cast<unsigned_t>((s_limits::min)()));
|
||||
}
|
||||
|
||||
void test_integral_conversions_on_min_max()
|
||||
{
|
||||
test_integral_conversions_on_min_max_impl<int>();
|
||||
test_integral_conversions_on_min_max_impl<short>();
|
||||
|
||||
#ifdef _MSC_VER
|
||||
test_integral_conversions_on_min_max_impl<long int>();
|
||||
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
test_integral_conversions_on_min_max_impl<boost::long_long_type>();
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
test_integral_conversions_on_min_max_impl<__int64>();
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_HAS_INT128
|
||||
test_integral_conversions_on_min_max_impl<boost::int128_type>();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,15 +27,6 @@ using namespace boost;
|
||||
#define BOOST_LCAST_NO_WCHAR_T
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
|
||||
#define BOOST_LC_RUNU16
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
|
||||
#define BOOST_LC_RUNU32
|
||||
#endif
|
||||
|
||||
struct class_with_user_defined_sream_operators {
|
||||
int i;
|
||||
|
||||
@@ -55,39 +46,24 @@ template <class RngT>
|
||||
void do_test_iterator_range_impl(const RngT& rng)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(lexical_cast<int>(rng), 1);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<int>(rng.begin(), rng.size()), 1);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(rng), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(rng.begin(), rng.size()), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<short>(rng), 1);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<short>(rng.begin(), rng.size()), 1);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned short>(rng), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned short>(rng.begin(), rng.size()), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<long int>(rng), 1);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<long int>(rng.begin(), rng.size()), 1);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned long int>(rng), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned long int>(rng.begin(), rng.size()), 1u);
|
||||
|
||||
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
|
||||
BOOST_CHECK_EQUAL(lexical_cast<float>(rng), 1.0f);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<float>(rng.begin(), rng.size()), 1.0f);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<double>(rng), 1.0);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<double>(rng.begin(), rng.size()), 1.0);
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
BOOST_CHECK_EQUAL(lexical_cast<long double>(rng), 1.0L);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<long double>(rng.begin(), rng.size()), 1.0L);
|
||||
#endif
|
||||
BOOST_CHECK_EQUAL(lexical_cast<class_with_user_defined_sream_operators>(rng), 1);
|
||||
#endif
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
BOOST_CHECK_EQUAL(lexical_cast<boost::ulong_long_type>(rng), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<boost::ulong_long_type>(rng.begin(), rng.size()), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<boost::long_long_type>(rng), 1);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<boost::long_long_type>(rng.begin(), rng.size()), 1);
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned __int64>(rng), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<unsigned __int64>(rng.begin(), rng.size()), 1u);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<__int64>(rng), 1);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<__int64>(rng.begin(), rng.size()), 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -130,16 +106,12 @@ void test_it_range_using_char(CharT* one, CharT* eleven)
|
||||
|
||||
BOOST_CHECK_EQUAL(lexical_cast<float>(rng1), 1.0f);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<double>(rng1), 1.0);
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
BOOST_CHECK_EQUAL(lexical_cast<long double>(rng1), 1.0L);
|
||||
#endif
|
||||
BOOST_CHECK_EQUAL(lexical_cast<class_with_user_defined_sream_operators>(rng1), 1);
|
||||
|
||||
BOOST_CHECK_EQUAL(lexical_cast<float>(crng2), 1.0f);
|
||||
BOOST_CHECK_EQUAL(lexical_cast<double>(crng2), 1.0);
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
BOOST_CHECK_EQUAL(lexical_cast<long double>(crng2), 1.0L);
|
||||
#endif
|
||||
BOOST_CHECK_EQUAL(lexical_cast<class_with_user_defined_sream_operators>(crng2), 1);
|
||||
|
||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||
@@ -149,7 +121,7 @@ void test_it_range_using_char(CharT* one, CharT* eleven)
|
||||
BOOST_CHECK(lexical_cast<std::wstring>(crng2) == L"1");
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_LC_RUNU16) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
typedef std::basic_string<char16_t> my_char16_string;
|
||||
BOOST_CHECK(lexical_cast<my_char16_string>(rng1) == u"1");
|
||||
BOOST_CHECK(lexical_cast<my_char16_string>(crng1) == u"1");
|
||||
@@ -157,7 +129,7 @@ void test_it_range_using_char(CharT* one, CharT* eleven)
|
||||
BOOST_CHECK(lexical_cast<my_char16_string>(crng2) == u"1");
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_LC_RUNU32) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
typedef std::basic_string<char32_t> my_char32_string;
|
||||
BOOST_CHECK(lexical_cast<my_char32_string>(rng1) == U"1");
|
||||
BOOST_CHECK(lexical_cast<my_char32_string>(crng1) == U"1");
|
||||
@@ -209,7 +181,7 @@ void test_wchar_iterator_ranges()
|
||||
|
||||
void test_char16_iterator_ranges()
|
||||
{
|
||||
#if defined(BOOST_LC_RUNU16)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
typedef char16_t test_char_type;
|
||||
test_char_type data1[] = u"1";
|
||||
test_char_type data2[] = u"11";
|
||||
@@ -221,7 +193,7 @@ void test_char16_iterator_ranges()
|
||||
|
||||
void test_char32_iterator_ranges()
|
||||
{
|
||||
#if defined(BOOST_LC_RUNU32)
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS)
|
||||
typedef char32_t test_char_type;
|
||||
test_char_type data1[] = U"1";
|
||||
test_char_type data2[] = U"11";
|
||||
|
||||
@@ -86,11 +86,7 @@ void test_round_conversion_double()
|
||||
|
||||
void test_round_conversion_long_double()
|
||||
{
|
||||
// We do not run tests on compilers with bugs
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_round_conversion<long double>();
|
||||
test_msvc_magic_values<long double>();
|
||||
#endif
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
|
||||
Regular → Executable
Regular → Executable
-2
@@ -37,9 +37,7 @@ void do_test_on_empty_input(T& v)
|
||||
BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
|
||||
#endif
|
||||
BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
|
||||
BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
|
||||
Regular → Executable
@@ -1,307 +0,0 @@
|
||||
// Unit test for boost::lexical_cast.
|
||||
//
|
||||
// See http://www.boost.org for most recent version, including documentation.
|
||||
//
|
||||
// Copyright Antony Polukhin, 2011-2012.
|
||||
//
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
///////////////////////// char streamable classes ///////////////////////////////////////////
|
||||
|
||||
struct streamable_easy { enum ENU {value = 0}; };
|
||||
std::ostream& operator << (std::ostream& ostr, const streamable_easy&) {
|
||||
return ostr << streamable_easy::value;
|
||||
}
|
||||
std::istream& operator >> (std::istream& istr, const streamable_easy&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, streamable_easy::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct streamable_medium { enum ENU {value = 1}; };
|
||||
template <class CharT>
|
||||
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_ostream<CharT>&>::type
|
||||
operator << (std::basic_ostream<CharT>& ostr, const streamable_medium&) {
|
||||
return ostr << streamable_medium::value;
|
||||
}
|
||||
template <class CharT>
|
||||
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_istream<CharT>&>::type
|
||||
operator >> (std::basic_istream<CharT>& istr, const streamable_medium&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, streamable_medium::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct streamable_hard { enum ENU {value = 2}; };
|
||||
template <class CharT, class TraitsT>
|
||||
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_ostream<CharT, TraitsT>&>::type
|
||||
operator << (std::basic_ostream<CharT, TraitsT>& ostr, const streamable_hard&) {
|
||||
return ostr << streamable_hard::value;
|
||||
}
|
||||
template <class CharT, class TraitsT>
|
||||
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_istream<CharT, TraitsT>&>::type
|
||||
operator >> (std::basic_istream<CharT, TraitsT>& istr, const streamable_hard&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, streamable_hard::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct streamable_hard2 { enum ENU {value = 3}; };
|
||||
template <class TraitsT>
|
||||
std::basic_ostream<char, TraitsT>& operator << (std::basic_ostream<char, TraitsT>& ostr, const streamable_hard2&) {
|
||||
return ostr << streamable_hard2::value;
|
||||
}
|
||||
template <class TraitsT>
|
||||
std::basic_istream<char, TraitsT>& operator >> (std::basic_istream<char, TraitsT>& istr, const streamable_hard2&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, streamable_hard2::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////// wchar_t streamable classes ///////////////////////////////////////////
|
||||
|
||||
struct wstreamable_easy { enum ENU {value = 4}; };
|
||||
std::wostream& operator << (std::wostream& ostr, const wstreamable_easy&) {
|
||||
return ostr << wstreamable_easy::value;
|
||||
}
|
||||
std::wistream& operator >> (std::wistream& istr, const wstreamable_easy&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, wstreamable_easy::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct wstreamable_medium { enum ENU {value = 5}; };
|
||||
template <class CharT>
|
||||
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_ostream<CharT>& >::type
|
||||
operator << (std::basic_ostream<CharT>& ostr, const wstreamable_medium&) {
|
||||
return ostr << wstreamable_medium::value;
|
||||
}
|
||||
template <class CharT>
|
||||
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_istream<CharT>& >::type
|
||||
operator >> (std::basic_istream<CharT>& istr, const wstreamable_medium&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, wstreamable_medium::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct wstreamable_hard { enum ENU {value = 6}; };
|
||||
template <class CharT, class TraitsT>
|
||||
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_ostream<CharT, TraitsT>&>::type
|
||||
operator << (std::basic_ostream<CharT, TraitsT>& ostr, const wstreamable_hard&) {
|
||||
return ostr << wstreamable_hard::value;
|
||||
}
|
||||
template <class CharT, class TraitsT>
|
||||
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_istream<CharT, TraitsT>&>::type
|
||||
operator >> (std::basic_istream<CharT, TraitsT>& istr, const wstreamable_hard&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, wstreamable_hard::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct wstreamable_hard2 { enum ENU {value = 7}; };
|
||||
template <class TraitsT>
|
||||
std::basic_ostream<wchar_t, TraitsT>& operator << (std::basic_ostream<wchar_t, TraitsT>& ostr, const wstreamable_hard2&) {
|
||||
return ostr << wstreamable_hard2::value;
|
||||
}
|
||||
template <class TraitsT>
|
||||
std::basic_istream<wchar_t, TraitsT>& operator >> (std::basic_istream<wchar_t, TraitsT>& istr, const wstreamable_hard2&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, wstreamable_hard2::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
///////////////////////// char and wchar_t streamable classes ///////////////////////////////////////////
|
||||
|
||||
|
||||
struct bistreamable_easy { enum ENU {value = 8}; };
|
||||
std::ostream& operator << (std::ostream& ostr, const bistreamable_easy&) {
|
||||
return ostr << bistreamable_easy::value;
|
||||
}
|
||||
std::istream& operator >> (std::istream& istr, const bistreamable_easy&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_easy::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
std::wostream& operator << (std::wostream& ostr, const bistreamable_easy&) {
|
||||
return ostr << bistreamable_easy::value + 100;
|
||||
}
|
||||
std::wistream& operator >> (std::wistream& istr, const bistreamable_easy&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_easy::value + 100);
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct bistreamable_medium { enum ENU {value = 9}; };
|
||||
template <class CharT>
|
||||
std::basic_ostream<CharT>& operator << (std::basic_ostream<CharT>& ostr, const bistreamable_medium&) {
|
||||
return ostr << bistreamable_medium::value + (sizeof(CharT) == 1 ? 0 : 100);
|
||||
}
|
||||
template <class CharT>
|
||||
std::basic_istream<CharT>& operator >> (std::basic_istream<CharT>& istr, const bistreamable_medium&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_medium::value + (sizeof(CharT) == 1 ? 0 : 100));
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct bistreamable_hard { enum ENU {value = 10}; };
|
||||
template <class CharT, class TraitsT>
|
||||
std::basic_ostream<CharT, TraitsT>& operator << (std::basic_ostream<CharT, TraitsT>& ostr, const bistreamable_hard&) {
|
||||
return ostr << bistreamable_hard::value + (sizeof(CharT) == 1 ? 0 : 100);
|
||||
}
|
||||
template <class CharT, class TraitsT>
|
||||
std::basic_istream<CharT, TraitsT>& operator >> (std::basic_istream<CharT, TraitsT>& istr, const bistreamable_hard&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_hard::value + (sizeof(CharT) == 1 ? 0 : 100));
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct bistreamable_hard2 { enum ENU {value = 11}; };
|
||||
template <class TraitsT>
|
||||
std::basic_ostream<char, TraitsT>& operator << (std::basic_ostream<char, TraitsT>& ostr, const bistreamable_hard2&) {
|
||||
return ostr << bistreamable_hard2::value;
|
||||
}
|
||||
template <class TraitsT>
|
||||
std::basic_istream<char, TraitsT>& operator >> (std::basic_istream<char, TraitsT>& istr, const bistreamable_hard2&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_hard2::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
template <class TraitsT>
|
||||
std::basic_ostream<wchar_t, TraitsT>& operator << (std::basic_ostream<wchar_t, TraitsT>& ostr, const bistreamable_hard2&) {
|
||||
return ostr << bistreamable_hard2::value + 100;
|
||||
}
|
||||
template <class TraitsT>
|
||||
std::basic_istream<wchar_t, TraitsT>& operator >> (std::basic_istream<wchar_t, TraitsT>& istr, const bistreamable_hard2&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_hard2::value + 100);
|
||||
return istr;
|
||||
}
|
||||
|
||||
|
||||
void test_ostream_character_detection();
|
||||
void test_istream_character_detection();
|
||||
void test_mixed_stream_character_detection();
|
||||
|
||||
boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
{
|
||||
boost::unit_test::test_suite *suite =
|
||||
BOOST_TEST_SUITE("lexical_cast stream character detection");
|
||||
suite->add(BOOST_TEST_CASE(&test_ostream_character_detection));
|
||||
suite->add(BOOST_TEST_CASE(&test_istream_character_detection));
|
||||
suite->add(BOOST_TEST_CASE(&test_mixed_stream_character_detection));
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void test_ostr_impl() {
|
||||
T streamable;
|
||||
BOOST_CHECK_EQUAL(T::value, boost::lexical_cast<int>(streamable));
|
||||
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(T::value), boost::lexical_cast<std::string>(streamable));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void test_wostr_impl() {
|
||||
T streamable;
|
||||
BOOST_CHECK_EQUAL(T::value, boost::lexical_cast<int>(streamable));
|
||||
// BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(T::value), boost::lexical_cast<std::string>(streamable)); // Shall not compile???
|
||||
BOOST_CHECK(boost::lexical_cast<std::wstring>(T::value) == boost::lexical_cast<std::wstring>(streamable));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void test_bistr_impl() {
|
||||
T streamable;
|
||||
|
||||
BOOST_CHECK_EQUAL(T::value, boost::lexical_cast<int>(streamable));
|
||||
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(T::value), boost::lexical_cast<std::string>(streamable));
|
||||
|
||||
BOOST_CHECK(boost::lexical_cast<std::wstring>(T::value + 100) == boost::lexical_cast<std::wstring>(streamable));
|
||||
}
|
||||
|
||||
void test_ostream_character_detection() {
|
||||
test_ostr_impl<streamable_easy>();
|
||||
test_ostr_impl<streamable_medium>();
|
||||
test_ostr_impl<streamable_hard>();
|
||||
test_ostr_impl<streamable_hard2>();
|
||||
|
||||
test_wostr_impl<wstreamable_easy>();
|
||||
test_wostr_impl<wstreamable_medium>();
|
||||
test_wostr_impl<wstreamable_hard>();
|
||||
test_wostr_impl<wstreamable_hard2>();
|
||||
|
||||
test_bistr_impl<bistreamable_easy>();
|
||||
test_bistr_impl<bistreamable_medium>();
|
||||
test_bistr_impl<bistreamable_hard>();
|
||||
test_bistr_impl<bistreamable_hard2>();
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
static void test_istr_impl() {
|
||||
boost::lexical_cast<T>(T::value);
|
||||
boost::lexical_cast<T>(boost::lexical_cast<std::string>(T::value));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void test_wistr_impl() {
|
||||
boost::lexical_cast<T>(T::value);
|
||||
//boost::lexical_cast<T>(boost::lexical_cast<std::string>(T::value)); // Shall not compile???
|
||||
boost::lexical_cast<T>(boost::lexical_cast<std::wstring>(T::value));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void test_bistr_instr_impl() {
|
||||
boost::lexical_cast<T>(T::value);
|
||||
boost::lexical_cast<T>(boost::lexical_cast<std::string>(T::value));
|
||||
boost::lexical_cast<T>(boost::lexical_cast<std::wstring>(T::value + 100));
|
||||
}
|
||||
|
||||
void test_istream_character_detection() {
|
||||
test_istr_impl<streamable_easy>();
|
||||
test_istr_impl<streamable_medium>();
|
||||
test_istr_impl<streamable_hard>();
|
||||
test_istr_impl<streamable_hard2>();
|
||||
|
||||
test_wistr_impl<wstreamable_easy>();
|
||||
test_wistr_impl<wstreamable_medium>();
|
||||
test_wistr_impl<wstreamable_hard>();
|
||||
test_wistr_impl<wstreamable_hard2>();
|
||||
|
||||
test_bistr_instr_impl<bistreamable_easy>();
|
||||
test_bistr_instr_impl<bistreamable_medium>();
|
||||
test_bistr_instr_impl<bistreamable_hard>();
|
||||
test_bistr_instr_impl<bistreamable_hard2>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct wistreamble_ostreamable { enum ENU {value = 200}; };
|
||||
std::ostream& operator << (std::ostream& ostr, const wistreamble_ostreamable&) {
|
||||
return ostr << wistreamble_ostreamable::value;
|
||||
}
|
||||
std::wistream& operator >> (std::wistream& istr, const wistreamble_ostreamable&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, wistreamble_ostreamable::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
struct istreamble_wostreamable { enum ENU {value = 201}; };
|
||||
std::wostream& operator << (std::wostream& ostr, const istreamble_wostreamable&) {
|
||||
return ostr << istreamble_wostreamable::value;
|
||||
}
|
||||
std::istream& operator >> (std::istream& istr, const istreamble_wostreamable&) {
|
||||
int i; istr >> i; BOOST_CHECK_EQUAL(i, istreamble_wostreamable::value);
|
||||
return istr;
|
||||
}
|
||||
|
||||
void test_mixed_stream_character_detection() {
|
||||
//boost::lexical_cast<std::wstring>(std::string("qwe")); // TODO: ALLOW IT AS EXTENSION!
|
||||
|
||||
boost::lexical_cast<wistreamble_ostreamable>(wistreamble_ostreamable::value);
|
||||
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(wistreamble_ostreamable()), wistreamble_ostreamable::value);
|
||||
|
||||
boost::lexical_cast<istreamble_wostreamable>(istreamble_wostreamable::value);
|
||||
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(istreamble_wostreamable()), istreamble_wostreamable::value);
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
// Unit test for boost::lexical_cast.
|
||||
//
|
||||
// See http://www.boost.org for most recent version, including documentation.
|
||||
//
|
||||
// Copyright Antony Polukhin, 2012.
|
||||
//
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
template <class T>
|
||||
static void test_optimized_types_to_string_const()
|
||||
{
|
||||
namespace de = boost::detail;
|
||||
typedef de::lexical_cast_stream_traits<T, std::string> trait_1;
|
||||
BOOST_CHECK(!trait_1::is_source_input_not_optimized_t::value);
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_1::src_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_1::target_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_1::char_type, char>::value));
|
||||
BOOST_CHECK(!trait_1::is_string_widening_required_t::value);
|
||||
BOOST_CHECK(!trait_1::is_source_input_not_optimized_t::value);
|
||||
|
||||
typedef de::lexical_cast_stream_traits<const T, std::string> trait_2;
|
||||
BOOST_CHECK(!trait_2::is_source_input_not_optimized_t::value);
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_2::src_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_2::target_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_2::char_type, char>::value));
|
||||
BOOST_CHECK(!trait_2::is_string_widening_required_t::value);
|
||||
BOOST_CHECK(!trait_2::is_source_input_not_optimized_t::value);
|
||||
|
||||
typedef de::lexical_cast_stream_traits<T, std::wstring> trait_3;
|
||||
BOOST_CHECK(!trait_3::is_source_input_not_optimized_t::value);
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_3::src_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_3::target_char_t, wchar_t>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_3::char_type, wchar_t>::value));
|
||||
|
||||
BOOST_CHECK((boost::detail::is_character<BOOST_DEDUCED_TYPENAME trait_3::no_cv_src>::value != trait_3::is_string_widening_required_t::value));
|
||||
|
||||
BOOST_CHECK(!trait_3::is_source_input_not_optimized_t::value);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
static void test_optimized_types_to_string()
|
||||
{
|
||||
test_optimized_types_to_string_const<T>();
|
||||
|
||||
namespace de = boost::detail;
|
||||
typedef de::lexical_cast_stream_traits<std::string, T> trait_4;
|
||||
BOOST_CHECK(!trait_4::is_source_input_not_optimized_t::value);
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_4::src_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_4::target_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_4::char_type, char>::value));
|
||||
BOOST_CHECK(!trait_4::is_string_widening_required_t::value);
|
||||
BOOST_CHECK(!trait_4::is_source_input_not_optimized_t::value);
|
||||
|
||||
typedef de::lexical_cast_stream_traits<const std::string, T> trait_5;
|
||||
BOOST_CHECK(!trait_5::is_source_input_not_optimized_t::value);
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_5::src_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_5::target_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_5::char_type, char>::value));
|
||||
BOOST_CHECK(!trait_5::is_string_widening_required_t::value);
|
||||
BOOST_CHECK(!trait_5::is_source_input_not_optimized_t::value);
|
||||
|
||||
typedef de::lexical_cast_stream_traits<const std::wstring, T> trait_6;
|
||||
BOOST_CHECK(!trait_6::is_source_input_not_optimized_t::value);
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_6::src_char_t, wchar_t>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_6::target_char_t, char>::value));
|
||||
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_6::char_type, wchar_t>::value));
|
||||
BOOST_CHECK(!trait_6::is_string_widening_required_t::value);
|
||||
}
|
||||
|
||||
void test_metafunctions()
|
||||
{
|
||||
test_optimized_types_to_string<bool>();
|
||||
test_optimized_types_to_string<char>();
|
||||
test_optimized_types_to_string<unsigned char>();
|
||||
test_optimized_types_to_string<signed char>();
|
||||
test_optimized_types_to_string<short>();
|
||||
test_optimized_types_to_string<unsigned short>();
|
||||
test_optimized_types_to_string<int>();
|
||||
test_optimized_types_to_string<unsigned int>();
|
||||
test_optimized_types_to_string<long>();
|
||||
test_optimized_types_to_string<unsigned long>();
|
||||
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
test_optimized_types_to_string<boost::ulong_long_type>();
|
||||
test_optimized_types_to_string<boost::long_long_type>();
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
test_optimized_types_to_string<unsigned __int64>();
|
||||
test_optimized_types_to_string<__int64>();
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_SWPRINTF) && !defined(__MINGW32__)
|
||||
test_optimized_types_to_string<float>();
|
||||
#endif
|
||||
|
||||
test_optimized_types_to_string<std::string>();
|
||||
test_optimized_types_to_string<char*>();
|
||||
//test_optimized_types_to_string<char[5]>();
|
||||
//test_optimized_types_to_string<char[1]>();
|
||||
test_optimized_types_to_string<unsigned char*>();
|
||||
//test_optimized_types_to_string<unsigned char[5]>();
|
||||
//test_optimized_types_to_string<unsigned char[1]>();
|
||||
test_optimized_types_to_string<signed char*>();
|
||||
//test_optimized_types_to_string<signed char[5]>();
|
||||
//test_optimized_types_to_string<signed char[1]>();
|
||||
test_optimized_types_to_string<boost::array<char, 1> >();
|
||||
test_optimized_types_to_string<boost::array<char, 5> >();
|
||||
test_optimized_types_to_string<boost::array<unsigned char, 1> >();
|
||||
test_optimized_types_to_string<boost::array<unsigned char, 5> >();
|
||||
test_optimized_types_to_string<boost::array<signed char, 1> >();
|
||||
test_optimized_types_to_string<boost::array<signed char, 5> >();
|
||||
test_optimized_types_to_string<boost::iterator_range<char*> >();
|
||||
test_optimized_types_to_string<boost::iterator_range<unsigned char*> >();
|
||||
test_optimized_types_to_string<boost::iterator_range<signed char*> >();
|
||||
|
||||
test_optimized_types_to_string_const<boost::array<const char, 1> >();
|
||||
test_optimized_types_to_string_const<boost::array<const char, 5> >();
|
||||
test_optimized_types_to_string_const<boost::array<const unsigned char, 1> >();
|
||||
test_optimized_types_to_string_const<boost::array<const unsigned char, 5> >();
|
||||
test_optimized_types_to_string_const<boost::array<const signed char, 1> >();
|
||||
test_optimized_types_to_string_const<boost::array<const signed char, 5> >();
|
||||
test_optimized_types_to_string_const<boost::iterator_range<const char*> >();
|
||||
test_optimized_types_to_string_const<boost::iterator_range<const unsigned char*> >();
|
||||
test_optimized_types_to_string_const<boost::iterator_range<const signed char*> >();
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||
test_optimized_types_to_string<std::array<char, 1> >();
|
||||
test_optimized_types_to_string<std::array<char, 5> >();
|
||||
test_optimized_types_to_string<std::array<unsigned char, 1> >();
|
||||
test_optimized_types_to_string<std::array<unsigned char, 5> >();
|
||||
test_optimized_types_to_string<std::array<signed char, 1> >();
|
||||
test_optimized_types_to_string<std::array<signed char, 5> >();
|
||||
|
||||
test_optimized_types_to_string_const<std::array<const char, 1> >();
|
||||
test_optimized_types_to_string_const<std::array<const char, 5> >();
|
||||
test_optimized_types_to_string_const<std::array<const unsigned char, 1> >();
|
||||
test_optimized_types_to_string_const<std::array<const unsigned char, 5> >();
|
||||
test_optimized_types_to_string_const<std::array<const signed char, 1> >();
|
||||
test_optimized_types_to_string_const<std::array<const signed char, 5> >();
|
||||
#endif
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
{
|
||||
boost::unit_test::test_suite *suite =
|
||||
BOOST_TEST_SUITE("lexical_cast traits tests");
|
||||
suite->add(BOOST_TEST_CASE(&test_metafunctions));
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// // Unit test for boost::lexical_cast.
|
||||
//
|
||||
// See http://www.boost.org for most recent version, including documentation.
|
||||
//
|
||||
// Copyright Antony Polukhin, 2013.
|
||||
//
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/type.hpp>
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
boost::lexical_cast<char*>("Hello");
|
||||
BOOST_CHECK(false); // suppressing warning about 'boost::unit_test::{anonymous}::unit_test_log' defined but not used
|
||||
return 0;
|
||||
}
|
||||
|
||||
Regular → Executable
Regular → Executable
@@ -34,7 +34,7 @@ void test_too_long_number(CharT zero)
|
||||
o << (limits::max)() << zero;
|
||||
s = o.str();
|
||||
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
|
||||
s[s.size()-1] += static_cast<CharT>(9); // '0' -> '9'
|
||||
s[s.size()-1] += 9; // '0' -> '9'
|
||||
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
|
||||
|
||||
if(limits::is_signed)
|
||||
@@ -43,7 +43,7 @@ void test_too_long_number(CharT zero)
|
||||
o << (limits::min)() << zero;
|
||||
s = o.str();
|
||||
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
|
||||
s[s.size()-1] += static_cast<CharT>(9); // '0' -> '9'
|
||||
s[s.size()-1] += 9; // '0' -> '9'
|
||||
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+2
-53
@@ -51,23 +51,6 @@ void test_char_types_conversions_wchar_t()
|
||||
{
|
||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||
test_impl(L"Test array of chars");
|
||||
wchar_t c = boost::detail::lcast_char_constants<wchar_t>::zero;
|
||||
BOOST_CHECK_EQUAL(L'0', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<wchar_t>::minus;
|
||||
BOOST_CHECK_EQUAL(L'-', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<wchar_t>::plus;
|
||||
BOOST_CHECK_EQUAL(L'+', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<wchar_t>::lowercase_e;
|
||||
BOOST_CHECK_EQUAL(L'e', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<wchar_t>::capital_e;
|
||||
BOOST_CHECK_EQUAL(L'E', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<wchar_t>::c_decimal_separator;
|
||||
BOOST_CHECK_EQUAL(L'.', c);
|
||||
#endif
|
||||
|
||||
BOOST_CHECK(true);
|
||||
@@ -75,25 +58,8 @@ void test_char_types_conversions_wchar_t()
|
||||
|
||||
void test_char_types_conversions_char16_t()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
#if !defined(BOOST_NO_CHAR16_T) && !defined(BOOST_NO_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
test_impl(u"Test array of chars");
|
||||
char16_t c = boost::detail::lcast_char_constants<char16_t>::zero;
|
||||
BOOST_CHECK_EQUAL(u'0', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char16_t>::minus;
|
||||
BOOST_CHECK_EQUAL(u'-', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char16_t>::plus;
|
||||
BOOST_CHECK_EQUAL(u'+', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char16_t>::lowercase_e;
|
||||
BOOST_CHECK_EQUAL(u'e', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char16_t>::capital_e;
|
||||
BOOST_CHECK_EQUAL(u'E', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char16_t>::c_decimal_separator;
|
||||
BOOST_CHECK_EQUAL(u'.', c);
|
||||
#endif
|
||||
|
||||
BOOST_CHECK(true);
|
||||
@@ -101,25 +67,8 @@ void test_char_types_conversions_char16_t()
|
||||
|
||||
void test_char_types_conversions_char32_t()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
#if !defined(BOOST_NO_CHAR32_T) && !defined(BOOST_NO_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
|
||||
test_impl(U"Test array of chars");
|
||||
char32_t c = boost::detail::lcast_char_constants<char32_t>::zero;
|
||||
BOOST_CHECK_EQUAL(U'0', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char32_t>::minus;
|
||||
BOOST_CHECK_EQUAL(U'-', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char32_t>::plus;
|
||||
BOOST_CHECK_EQUAL(U'+', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char32_t>::lowercase_e;
|
||||
BOOST_CHECK_EQUAL(U'e', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char32_t>::capital_e;
|
||||
BOOST_CHECK_EQUAL(U'E', c);
|
||||
|
||||
c = boost::detail::lcast_char_constants<char32_t>::c_decimal_separator;
|
||||
BOOST_CHECK_EQUAL(U'.', c);
|
||||
#endif
|
||||
|
||||
BOOST_CHECK(true);
|
||||
|
||||
Reference in New Issue
Block a user