Compare commits

..

251 Commits

Author SHA1 Message Date
Marshall Clow a0f276556a Release 1.55.0
[SVN r86621]
2013-11-11 19:45:21 +00:00
Antony Polukhin a98a74d3dd Merge lexical_casts documentation and tests to release branch (refs #9046)
[SVN r85901]
2013-09-25 13:27:07 +00:00
Antony Polukhin f2e0225b1b Fix generic_stringize example compilation on Darvin (refs #9046)
[SVN r85868]
2013-09-24 14:21:53 +00:00
Antony Polukhin 701963d3c4 lexical_cast.hpp improvements: fix bug with floats conversions and improve docs (refs #9046)
[SVN r85852]
2013-09-23 11:59:06 +00:00
Antony Polukhin ce7a54af7f Minor update of lexical cast before fixing mingw issues (refs #9046)
[SVN r85830]
2013-09-22 16:06:45 +00:00
Antony Polukhin c2c4b884fe Make a separate folder for lexical_casts examples, use those examples in documenation and assure that they successfully build and run (refs #9046)
[SVN r85828]
2013-09-22 12:23:26 +00:00
Antony Polukhin 6f656adea3 Do not treat long long warnings as errors in lexical_cast + containers tests (fixes #9061)
[SVN r85684]
2013-09-15 19:33:17 +00:00
Antony Polukhin c359ed53b2 Fix unused parameter warning (fix #9106)
[SVN r85683]
2013-09-15 19:28:36 +00:00
Antony Polukhin 47041de63a lexical_cast.hpp improvements: interpreter was split to input and output streams to reduce size of binaries and improve compilation times, fixed typo from previous commit (refs #9046)
[SVN r85528]
2013-08-30 14:37:32 +00:00
Antony Polukhin c58a55a512 lexical_cast.hpp improvements: more comments, BOOST_NOEXCEPT and const; parser_buf moved to boost/detail/basic_pointerbuf.hpp, better formatting and simplified type traits (refs #9046)
[SVN r85523]
2013-08-30 08:59:59 +00:00
Antony Polukhin dd165b4b0f lexical_cast.hpp improvements: no more const_casts, much shorter and better template specializations, some code formatting fixes (refs #9046)
[SVN r85513]
2013-08-29 15:35:02 +00:00
Antony Polukhin b5552e351c lexical_cast.hpp improvements: better overflow detections for float conversions, more const modifiers (refs #9046)
[SVN r85512]
2013-08-29 11:41:28 +00:00
Antony Polukhin 297b115e6c lcast_put_unsigned in lexical_cast.hpp header is refactored, duplicate code removed (refs #9046)
[SVN r85499]
2013-08-28 12:55:09 +00:00
Antony Polukhin a2299ec1f9 Fix bug introduced by previous commits during conversion of wide character to wide character. Remove duplicate code and add more comments for lcast_ret_unsigned method. Optimize and simplify overflow detection (refs #9046)
[SVN r85486]
2013-08-27 14:23:19 +00:00
Antony Polukhin bf551ad8c9 Delay character trait extraction (refs #9046)
[SVN r85483]
2013-08-27 07:51:27 +00:00
Antony Polukhin fac805ddf6 Improved some of the metaprogramming methods (refs #9046)
[SVN r85482]
2013-08-27 07:07:15 +00:00
Antony Polukhin 3ce36a2848 Get rid of some macro, improve type traits, fix svn properties, do not supress warnings (refs #9046)
[SVN r85475]
2013-08-26 11:18:42 +00:00
Antony Polukhin 4ba64ea889 Merge from trunk:
* Do not treat critcal errors as bad_lexical_cast exceptions, but if exceptions are on, throw correct exception instead (refs #8966)

[SVN r85331]
2013-08-13 13:08:37 +00:00
Antony Polukhin d723c18fff Update explicit failures markup and lexical_cast_float_types_test.cpp: do not run some checks when libc++ is used, but do expect other checks to pass well.
[SVN r85322]
2013-08-12 16:06:59 +00:00
Antony Polukhin 6bd8edfa02 Do not treat critcal errors as bad_lexical_cast exceptions, but if exceptions are on throw correct exception instead (refs #8966)
[SVN r85232]
2013-08-07 11:08:01 +00:00
Antony Polukhin 7e484c17f6 Merge lexical_cast and some conversion docs and test from trunk:
* fixed int128 and uint128 conversions (fixes #8790)
* fixed warnings from Boost Inspection Report

[SVN r85160]
2013-07-25 16:29:11 +00:00
Antony Polukhin 5f44bdcae8 Fix warnings in lexical_cast found by Boost Inspection program (copyrights restored according to svn history, license text replaced with license name and link to it)
[SVN r85149]
2013-07-24 08:46:08 +00:00
Antony Polukhin a65fcf571f Get rid of BOOST_LCAST_HAS_INT128 macro and use BOOST_HAS_INT128 instead (refs #8790)
[SVN r85073]
2013-07-18 09:13:41 +00:00
Antony Polukhin 13d98f02d0 Fixed testing of 128bit integer types and added staic assert that cheks for std::numeric_limits specializations, if they are required for conversion (refs #8790)
[SVN r85072]
2013-07-18 08:45:09 +00:00
Antony Polukhin 91aa2ce64d Report more warnings while testing boost::lexical_cast. Some warnings suppressed
[SVN r85007]
2013-07-12 11:33:15 +00:00
Antony Polukhin f7bd5e24c2 Fix macro for int128 detection (refs #8790)
[SVN r84965]
2013-07-07 09:51:58 +00:00
Antony Polukhin 3af0af9405 Merge from trunk:
* Fix for GCC-4.8 warning (fixes #8547)
* Disable tests, invalid for C11 (clang specific)

[SVN r84183]
2013-05-07 19:24:47 +00:00
Antony Polukhin c3c44c208a Fix for GCC-4.8 warning (refs #8547)
[SVN r84136]
2013-05-04 12:48:26 +00:00
Antony Polukhin 93a01eba32 Comment out two lexical_cast tests, not actual for C++11
[SVN r83894]
2013-04-14 07:53:45 +00:00
Antony Polukhin b97f2542ec Mrege from trunk:
* Disable UTF16 and UTF32 tests for libc++ (fixes #8369)

[SVN r83764]
2013-04-04 15:47:02 +00:00
Antony Polukhin 12fd711cc8 Disable UTF16 and UTF32 tests for libc++ (refs #8369)
[SVN r83717]
2013-04-02 19:56:49 +00:00
Antony Polukhin 32d70a0764 Merge from trunk:
* Fix stream related issues with libc++ and clang (fixes #7704, fixes #8267)
* Change runtime assert to compile time when converting to pointer (fixes #8267)

[SVN r83689]
2013-04-01 20:40:43 +00:00
Antony Polukhin 1a0ffcadbf Add tests for filesystem::path conversion (refs #7704)
[SVN r83644]
2013-03-30 07:41:23 +00:00
Antony Polukhin ab0727fdac Fix streams and buffers usage (refs #8267 and refs #7704). Now conversions the use STL streams shall work faster
[SVN r83642]
2013-03-30 07:20:22 +00:00
Antony Polukhin 633b852b81 Update code that uses string buffers (refs #8267).
Treat cast to pointer as compile time error (refs #8334).
Update documentation

[SVN r83601]
2013-03-27 17:00:46 +00:00
Antony Polukhin 9fc1a66d27 Reimplement STL string buffer unlocker (refs #8267 and refs #7704)
[SVN r83543]
2013-03-24 15:26:45 +00:00
Antony Polukhin a4bd056b8e Merge from trunk:
* Fixed incorrect usage of Boost.Math when it does not support long double (fixes #8162)
* Fixed ambiguity of boost::lexical_cast functions (fixes #7421)

[SVN r83542]
2013-03-24 14:37:56 +00:00
Antony Polukhin 61938bc8d3 Fix ambiguity while using lexical_cast with std::transform or other functions that may take a pointer to lexical_cast (refs #7421)
[SVN r83457]
2013-03-16 09:24:08 +00:00
Antony Polukhin 694f7b5033 Do not use long double type in lexical_cast for internal variables if Boost.Math has no functions for long double (refs #8162)
Do not test lexical_cast on long doubles, if Boost.Math does not support long double

[SVN r83129]
2013-02-24 13:34:57 +00:00
Antony Polukhin 335c868e9b Merge from trunk:
* Silence some buggy VS warnings (fixes #7949)
* Fix -Wconversion warnings (fixes #2558)
* Added support for int128 conversions (fixes #7909)

[SVN r83114]
2013-02-24 08:31:17 +00:00
Antony Polukhin a15dbed640 Silence some buggy VS warnings (refs #7949)
[SVN r82807]
2013-02-10 13:59:45 +00:00
Antony Polukhin 5c8c897d30 Fixed as many -Wconversion warnings in lexical cast and tests as possible (refs #2558)
[SVN r82695]
2013-02-03 09:20:28 +00:00
Antony Polukhin 3e4a1669f1 More tests (refs #7814)
[SVN r82694]
2013-02-03 07:38:56 +00:00
Antony Polukhin cb9de2c55f Update performance results for VC in docs.
Looks like bug #6523 now is fixed (fixes #6523)

[SVN r82685]
2013-02-02 07:44:09 +00:00
Antony Polukhin 89556c8a0f Documentation update (refs #7909)
[SVN r82561]
2013-01-20 12:20:43 +00:00
Antony Polukhin 47bef9517f Attempt to add support for lexical conversions of int128 types (refs #7909)
[SVN r82560]
2013-01-20 12:13:31 +00:00
Antony Polukhin 63b680c082 More strict tests, less workarounds, bugfixes (refs #7814)
[SVN r82227]
2012-12-27 20:17:09 +00:00
Antony Polukhin 565e2882d3 Add missing signature to doc (refs #7831)
[SVN r82220]
2012-12-27 18:47:15 +00:00
Antony Polukhin 24bc6ca6f2 Fix bug in array conversion test (refs #7799)
[SVN r82187]
2012-12-23 15:16:01 +00:00
Antony Polukhin 4ad6f1bd4b FIx bug in conversion of some std::array implementations (refs #7799)
[SVN r82172]
2012-12-22 18:42:04 +00:00
Antony Polukhin 5a6309db7a Fix incorrect macro usage (refs #7799)
[SVN r82017]
2012-12-16 09:01:18 +00:00
Antony Polukhin 2333ee53f8 Minor fix in lexical_cast_stream_traits_test.cpp
[SVN r81745]
2012-12-06 17:20:28 +00:00
Marshall Clow e15f179bfc Removed usage of deprecated macros
[SVN r81559]
2012-11-26 17:27:53 +00:00
Marshall Clow 82969ebb20 Remove usage of deprecated macros
[SVN r81551]
2012-11-26 14:14:10 +00:00
Antony Polukhin 17f4b6fd4c Comment out some minor unrequired tests
[SVN r81486]
2012-11-22 16:33:54 +00:00
Antony Polukhin 2ea7487806 Move all the stream specific metafunctions to lexical_cast_stream_traits<Source, Target>
Test stream traits for correctness and correct optimization detection

[SVN r81354]
2012-11-15 07:26:23 +00:00
Antony Polukhin cd5a55aab5 Documentation update for lexical_cast (refs #6786)
[SVN r81353]
2012-11-15 06:45:23 +00:00
Antony Polukhin f682bff3a7 Simplify test_getting_pointer_to_function to don't deal with compilers bugs and just test that getting pointer to lexical_cast<T1, T2> is not ambiguous
[SVN r81294]
2012-11-11 08:59:36 +00:00
Antony Polukhin 1c37887f2b Stream type detection metafunctions were rewritten so that now they can detect stream type for user defined types (refs #6786)
Removed unrequired `::` 

[SVN r81278]
2012-11-10 07:42:04 +00:00
Antony Polukhin 5c3159cd1c Attempt to workaround VACPP, CRAY and ancient GCC bugs in lexical_cast tests
[SVN r81162]
2012-11-03 16:20:43 +00:00
Antony Polukhin c484325310 Fix FAQ section of lexical_cast documentation (refs #7582)
[SVN r81069]
2012-10-27 16:30:41 +00:00
Antony Polukhin 42e7585dd4 Tiny documentation update (refs #7421)
[SVN r80739]
2012-09-28 18:31:53 +00:00
Antony Polukhin 7b6c4eed7d Remove bad test (refs #7421)
[SVN r80731]
2012-09-28 04:55:37 +00:00
Antony Polukhin 824fbd9b06 Do not overload lexical_cast<To, From>(const From&), instead add lexical_cast<To>(character_type,size_type) templates (refs #7421). Added tests for getting &boost::lexical_cast<To,from> functions pointers
[SVN r80715]
2012-09-26 19:57:31 +00:00
Antony Polukhin 77eff6b47d Workaround MSVC2012 error in lexical_cast_test.cpp
[SVN r80584]
2012-09-18 20:11:05 +00:00
Antony Polukhin 8705038cd2 Workaround MSVC2012 error in lexical_cast_test.cpp
[SVN r80503]
2012-09-12 03:58:26 +00:00
Antony Polukhin bb224866a7 Fix float types tests, make them less strict (so that MSVC2012 could pass it)
[SVN r80438]
2012-09-08 01:44:18 +00:00
Antony Polukhin c43b86d7f1 Replace .c_str() with .data() in documentation (refs #6663)
[SVN r80377]
2012-09-03 17:23:16 +00:00
Antony Polukhin c290a26625 Added missing const modifier
[SVN r80374]
2012-09-03 17:06:40 +00:00
Antony Polukhin d08477900d Added lexical_cast(const CharType* chars, std::size_t count) function overload (refs #6430 and refs #6663)
Fixed GCC warning in numeric_cast_test.cpp

[SVN r80291]
2012-08-28 20:31:16 +00:00
Antony Polukhin 63acf4f174 Fix compilation of lexical cast with MSVC 2003 (refs #7255)
[SVN r80210]
2012-08-25 19:07:46 +00:00
Antony Polukhin ce95319f03 Multiple small changes:
1) #warning replaced with #error (refs 7228)
2) Pavel Korzh added to thanks list (refs 7157)
3) BOOST_NOEXCEPT modifiers added where possible
4) better support for c++11 Unicode characters
5) fixed compilation with MSVC+STLPort
6) more agressive usage of Traits template parameter

[SVN r80105]
2012-08-21 04:44:00 +00:00
Antony Polukhin d6a72e9ea5 Fix bug with volatile types (refs #7157)
[SVN r79797]
2012-07-29 18:54:24 +00:00
Antony Polukhin 3c94791b1e Workaround VC warning (refs #7116)
[SVN r79565]
2012-07-16 17:17:00 +00:00
Antony Polukhin e81d4dfdbb Fix typo in documentation (fixes #7129)
[SVN r79479]
2012-07-13 19:20:05 +00:00
Antony Polukhin fe79553bf8 Fix tab in documentation (refs #7065)
[SVN r79363]
2012-07-08 17:59:50 +00:00
Antony Polukhin 093e298c9d Updated documentaion and performance test (now we have info about conversion speed to and from array<>, refs #7065)
[SVN r79297]
2012-07-05 19:27:35 +00:00
Antony Polukhin d2361fe05a Updated documentaion, fixed bug and refactored tests (refs #7065)
[SVN r79266]
2012-07-04 18:50:56 +00:00
Antony Polukhin b037563bf9 Documentation update: documented optimizations for boost and std arrays (refs #7065)
[SVN r79249]
2012-07-03 17:32:29 +00:00
Antony Polukhin 88244b57d4 Split lexical_cast_test.cpp into two tests and reduce iterations count for integral types tests (now we must not exceed tests timeouts)
[SVN r79246]
2012-07-03 17:10:02 +00:00
Antony Polukhin e3cd0ca7fa Optimizations for boost and std array (refs #7065)
[SVN r79230]
2012-07-02 18:30:21 +00:00
Antony Polukhin c6318e3819 Do not force PGI compiler to use fallback version of lexical_cast (PGI fails tests even in fallback version)
Trialing whitespaces removed

[SVN r78521]
2012-05-20 16:25:21 +00:00
Antony Polukhin e691b15b77 Force PGI and SunCC compillers to use fallback version of lexical_cast
[SVN r78485]
2012-05-15 18:51:35 +00:00
Antony Polukhin bb46dbc46c Fixes #6852 for wide characters (ISO C++ does not support the ‘%lg’ gnu_printf format fixed)
[SVN r78408]
2012-05-10 17:39:46 +00:00
Antony Polukhin d30dd9e3c8 Fixes #6852 (ISO C++ does not support the ‘%lg’ gnu_printf format fixed)
[SVN r78308]
2012-05-02 19:00:37 +00:00
Antony Polukhin 15ab0d6385 Fixes #6812 (now converting "." to float type throws bad_lexical_cast)
[SVN r78111]
2012-04-21 11:08:03 +00:00
Antony Polukhin d963842d70 Typo fix in documentation. New line added to the end of lexical_cast.hpp file
[SVN r78051]
2012-04-17 18:00:30 +00:00
Antony Polukhin 9ff79f4df9 Update documentation ( more info about stream character type detection + warn about new unicode types support; refs #6786, refs #6663)
[SVN r78044]
2012-04-17 16:27:50 +00:00
Antony Polukhin 746d466e38 Comment out bad advise in documentation ( refs #6786, refs #6663)
[SVN r78015]
2012-04-16 17:13:11 +00:00
Antony Polukhin 674e71fb7d Fix compile time error in lexical_cast, when new unicode characters are being converted (Refs #6504 )
[SVN r77936]
2012-04-12 17:15:22 +00:00
Antony Polukhin 35d592fc21 Fix iterator_range test for compilers with new unicode characters but without new unicode locales support
[SVN r77921]
2012-04-11 18:34:10 +00:00
Antony Polukhin 7881eb5666 Remove incorrect test
[SVN r77854]
2012-04-09 18:07:51 +00:00
Antony Polukhin 8562b480f8 * fixes #6504 (characters widening fixed)
* much more tests
* better support for unicode characters and template classes that are instantinated with unicode character types
* meta code refactored (it is now shorter and clearer)

[SVN r77824]
2012-04-07 19:44:07 +00:00
Antony Polukhin 6ff6958204 Removed incorrect test
[SVN r77807]
2012-04-07 08:05:16 +00:00
Antony Polukhin 2af8c47558 Fix inspection warning (tab removed)
[SVN r77773]
2012-04-05 03:59:02 +00:00
Antony Polukhin deef894ae2 Lexical_cast test's Jamfile has been rewritten (boost license is now explicitly defined, disabled build of typedefed_wchar_runtime for unsupported targets, nicer and more compact jamfile instructions)
[SVN r77772]
2012-04-05 03:53:58 +00:00
Antony Polukhin 4a617adce1 More workarounds for fixed #6670 (disable more char16_t and char32_t tests for some compilers)
[SVN r77745]
2012-04-03 18:00:30 +00:00
Antony Polukhin 969a913153 More workarounds for fixed #6670 (disable basic char16_t and char32_t tests for some compilers, disable optimizations for them)
[SVN r77721]
2012-04-02 16:58:32 +00:00
Antony Polukhin 41a673db61 Fixes #6717 (now also setting precision for float types conversion when using iostreams)
[SVN r77716]
2012-04-02 15:33:46 +00:00
Antony Polukhin acb746274f Fixes #6670 (now using BOOST_NO_UNICODE_LITERALS macro)
[SVN r77691]
2012-04-01 19:08:46 +00:00
Antony Polukhin dfb518997f Fixes #6717 (now lexical_cast won`t try to support non confirming swprintf)
[SVN r77639]
2012-03-30 03:55:26 +00:00
Antony Polukhin 4265f454e1 Small documentation updates for #6663
[SVN r77537]
2012-03-25 05:31:43 +00:00
Antony Polukhin 76b9f29c12 Fixes #6663 (much more optimizations for iterator_range, updated documentation and performance test results)
[SVN r77517]
2012-03-24 19:35:19 +00:00
Antony Polukhin 676bde6e1f More strict tests for disabled exceptions (for fixed #5800)
[SVN r77236]
2012-03-05 18:44:31 +00:00
Antony Polukhin 7e7f494dd1 Attempt to supress warning described in #6645 (implicit conversion shortens 64-bit value into a 32-bit value)
[SVN r77221]
2012-03-04 17:59:03 +00:00
Antony Polukhin 83639bd9ae Fixes #6571 (documentation update, added 'why lexical_cast does not understand "-1.#IND"' question and answer to it)
[SVN r77118]
2012-02-26 09:19:55 +00:00
Antony Polukhin 0dded6d3a7 Update for fixed #6441 (unable to compile lexical_cast with BOOST_NO_STD_LOCALE defined)
Now test must compile under VC, removed some warnings.

[SVN r77117]
2012-02-25 17:32:26 +00:00
Antony Polukhin 25d880f5eb Updates #5800 (partially fix lexical cast compilation with disabled exceptions)
[SVN r77116]
2012-02-25 16:58:46 +00:00
Antony Polukhin b71fb9aada Fixes #6441 (compilation error with BOOST_NO_STD_LOCALE defined)
[SVN r77077]
2012-02-20 16:20:09 +00:00
Antony Polukhin d9baa71302 Updated INF/NAN support for char16_t and char32_t
[SVN r77058]
2012-02-17 18:51:05 +00:00
Antony Polukhin 80e858b182 More tests for fixed #5689 (issue mentiond in 5th comment)
[SVN r77040]
2012-02-16 17:57:52 +00:00
Antony Polukhin 646b958a92 FIx #5689 (issue from 5th comment)
[SVN r77039]
2012-02-16 17:56:27 +00:00
Antony Polukhin 04f441e989 Commited sources of performance testing program and Jamfile.v2 to build and run it
[SVN r76936]
2012-02-07 17:20:03 +00:00
Antony Polukhin 7a48fea517 Disabling some optimisations for sun cc
Bug described in #6462

[SVN r76824]
2012-02-01 17:08:10 +00:00
Antony Polukhin c9863cd254 FIxes #6453 (compile error due to deduce_char_traits ambiguity)
[SVN r76818]
2012-02-01 04:25:21 +00:00
Antony Polukhin 132663404b Added tests for ticket #6453
[SVN r76817]
2012-02-01 04:22:21 +00:00
Antony Polukhin a0cbfa8af6 New test case from ticket #5793
[SVN r76809]
2012-01-31 16:05:22 +00:00
Antony Polukhin efe20fcf76 Tiny change to test case from #6452
[SVN r76708]
2012-01-26 17:51:17 +00:00
Antony Polukhin 84d9706182 Update tests with example from #6452
[SVN r76707]
2012-01-26 17:47:56 +00:00
Antony Polukhin 5ed7bfd280 Attempt to fix #6251
[SVN r76599]
2012-01-20 19:33:04 +00:00
Antony Polukhin 7bdc45327a Tiny documentation update
[SVN r76356]
2012-01-08 09:21:00 +00:00
Antony Polukhin 9a6d983ee5 Fixes #6193
[SVN r76318]
2012-01-05 12:09:15 +00:00
Antony Polukhin d754143308 Fixes #6132
Fixes #6182

[SVN r76305]
2012-01-04 16:06:37 +00:00
Antony Polukhin 085bd6f93c Fixes #6290
Tiny documentation update
Updated char16_t and char32_t support (still some work required)
lexical_cast_empty_input_test.cpp refactored 

[SVN r76154]
2011-12-25 18:55:33 +00:00
Antony Polukhin 5d288580ee Fixes #6298
Fixes #6264

[SVN r76096]
2011-12-21 17:03:52 +00:00
Antony Polukhin 8627f8bb8a Fixes #6186 (treat conversions to/from single wchar_t character as conversions to/from unsigned short. Test added, documentation updated)
[SVN r75937]
2011-12-14 16:36:34 +00:00
Antony Polukhin f32fb4b5e5 Fixes #6186 test failures
[SVN r75921]
2011-12-12 18:09:53 +00:00
Antony Polukhin a9697b88fd Fixes #6186 (lexical_cast compliation error fixed, when wchar_t is a typedef for unsigned short. Test added)
[SVN r75864]
2011-12-08 15:29:44 +00:00
Antony Polukhin 2312691bde Fixes #6127 (wchar_t usage outside of #ifndef BOOST_LCAST_NO_WCHAR_T )
[SVN r75813]
2011-12-05 16:29:45 +00:00
Antony Polukhin 7dd63d08d6 Fixes #6159 (compilation on platforms without cwchar)
[SVN r75812]
2011-12-05 16:17:09 +00:00
Antony Polukhin 4ddb0bfb95 Fix for error noticed by Olaf van der Spek (ticket #6083)
Added test case for that error

[SVN r75283]
2011-11-03 04:33:58 +00:00
Antony Polukhin c07cbcee5c Performance optimizations and testsfor conversions to/from boost::container::basic_string
[SVN r74940]
2011-10-13 18:36:39 +00:00
Gennadiy Rozental 8c7c7b9237 eliminated unit_test_framework and BOOST_MESSAGE
[SVN r74727]
2011-10-05 09:42:21 +00:00
Gennadiy Rozental 3d60698843 eliminated unit_test_framework
[SVN r74720]
2011-10-05 09:15:12 +00:00
Antony Polukhin d2ae7fdbd7 char16_t and char32_t conversions now work on gcc for C locale
Optimizations for C locale
Performance section of documentation updated

[SVN r74432]
2011-09-17 09:09:27 +00:00
Antony Polukhin 2acef7aa44 Basic support for char16_t and char32_t
[SVN r74243]
2011-09-05 19:00:29 +00:00
Antony Polukhin 2f5d0c847b Fixes #5783
Fixes ambiguities with operators >> and <<. Adds tests for such cases.

[SVN r73818]
2011-08-16 17:09:25 +00:00
Antony Polukhin eb66b40e67 FIxes #5631
Workaround for nvcc bug

[SVN r73707]
2011-08-12 17:35:56 +00:00
Antony Polukhin 5ebb13bbad Very small update for FAQ section of documentation
[SVN r73706]
2011-08-12 17:08:17 +00:00
Antony Polukhin 4a4150d0be Fixes #5746
Updates FAQ section of documentation

[SVN r73705]
2011-08-12 17:04:31 +00:00
Antony Polukhin 9955dcce51 Fixes #5732.
* suppress compilation warnings, if the compiler requires a return, even when it can never be reached

[SVN r73640]
2011-08-10 18:58:06 +00:00
Antony Polukhin e8108e5066 Fixes #5732.
* some fixes for WinCE
* updated explicit failures markup

[SVN r73601]
2011-08-07 17:38:33 +00:00
Antony Polukhin a9778ad460 Fixes #5732.
* at least compiles on pgi

[SVN r73446]
2011-07-30 16:47:30 +00:00
Antony Polukhin aba423d425 Fixes #5732.
* one more try to fix compilation errors on pgi compiler 

[SVN r73435]
2011-07-29 19:33:18 +00:00
Antony Polukhin 30e4efd062 Fixes #5732.
* one more try to fix compilation errors on pgi compiler 

[SVN r73401]
2011-07-27 15:56:49 +00:00
Antony Polukhin 19f316f768 Fixes #5732.
* fixes compilation errors pgi compiler 
* fixes some bugs for MinGW compiler

[SVN r73384]
2011-07-26 18:51:39 +00:00
Antony Polukhin 9ac4e2bef1 Fixes #5732.
* fixes compilation errors for nonconst char arrays

[SVN r73357]
2011-07-25 15:13:36 +00:00
Antony Polukhin 2b76f558c1 #5732. Adds workaround for MinGW bugs
[SVN r73347]
2011-07-25 05:02:07 +00:00
Antony Polukhin 0ee6400d5e Fixes #5732.
* fixes some warnings and bugs for VC

[SVN r73328]
2011-07-24 10:56:54 +00:00
Antony Polukhin fd264b0583 Fixes #5732.
* fixes performance regression, that was added by previous commit
* fixes float types preformance regression for old compilers

[SVN r73323]
2011-07-24 09:42:06 +00:00
Antony Polukhin 8a756eae7b Fixes #5732.
* reduces templates count
 * leaves only one lexical converting class (at least for modern compilers)
 * fixes small TODOs and XXXs from source code
 * makes lexical_stream_limited_src more readable
 * updates status/explicit-failures-markup.xml
 * makes lexical_cast_inf_nan_test.cpp pass on Itanium pltform
 * makes lexical_cast able to convert signed and unsigned chars to wchar_t
 and updates lexical_cast_wchars_test

[SVN r73313]
2011-07-23 15:55:54 +00:00
Antony Polukhin c1c8485cb4 Fixes #5723. Links in documentation are now implemented via [@boost: ]
[SVN r73277]
2011-07-21 15:35:11 +00:00
Antony Polukhin c372f482a2 Fixes #5723. Fixes broken link
[SVN r73269]
2011-07-21 08:20:35 +00:00
Daniel James fa7f4ba7a7 Link up the new lexical cast documentation.
[SVN r73267]
2011-07-21 07:35:29 +00:00
Antony Polukhin 272e92ba7f Fixes #5723. Updates lexical_cast maintainer info
[SVN r73256]
2011-07-20 11:50:46 +00:00
Antony Polukhin c6c501c769 Fixes #5689. Added code to work -NaN on any platform. Removed some warnings
[SVN r73155]
2011-07-16 21:02:32 +00:00
Antony Polukhin de3df54f80 Fixes #5689. Added code to work with Inf and NaN on any platform
[SVN r73118]
2011-07-15 11:20:11 +00:00
Antony Polukhin 27a7fac22e Updates #5660.
Removed duplicate tests.
Unified behaviour for float conversions on different compillers

[SVN r72972]
2011-07-08 17:23:31 +00:00
Antony Polukhin fff0066392 Fixes #5676.
Tests for float types are now more accurate

[SVN r72955]
2011-07-07 16:04:32 +00:00
Antony Polukhin 0e2235dc75 Fixes #5675. Adds tests on #5675.
Updates #5660. Updates performance section of documentation

[SVN r72954]
2011-07-07 11:31:25 +00:00
Antony Polukhin 6a8c22d5c3 Partial fix for #5660. Better performance and less memory usage for conversions to float type (and to double type, if sizeof(double) < sizeof(long double)). New test suits. Documentation update.
[SVN r72925]
2011-07-06 15:43:04 +00:00
Antony Polukhin cd0167d6b8 Fixes #5585 and adds test on it
[SVN r72315]
2011-05-31 20:46:37 +00:00
Antony Polukhin ccaa3059e8 Improved english and documentation design for #5576.
[SVN r72225]
2011-05-27 18:32:57 +00:00
Antony Polukhin b0b1ce9453 Fixes #5576, adds performance section to the lexical_cast documentation, fixes misprint in tests/
[SVN r72224]
2011-05-27 18:19:38 +00:00
Antony Polukhin 98d24e04f4 Fixes #5564. Adds tests on #5564 and more tests on #5557
[SVN r72203]
2011-05-27 04:22:18 +00:00
Antony Polukhin 920e36f6ba Fixes #5557. Adds tests on #5557
[SVN r72071]
2011-05-22 11:35:00 +00:00
Antony Polukhin dc9b364d6f Fixes #5417. Much better performance on casts to integral types.
Adds more tests for overflow detection.
Workaround for bugs of vc8 (lexical_cast_vc8_bug_test.cpp now passes)
Fixes some inspection errors.

[SVN r72056]
2011-05-20 17:11:53 +00:00
Antony Polukhin 95360b5df6 Fixes #5417. Fixes #4397
More tests (for conversions to float types, for conversions of negative values to unsigned integers)

[SVN r71958]
2011-05-15 15:31:01 +00:00
Antony Polukhin 266ebbcb88 Added documentation on the feature, described in ticket. Fixed 5494
[SVN r71922]
2011-05-13 17:31:16 +00:00
Antony Polukhin e41ef929d2 FIx #5536
[SVN r71901]
2011-05-12 17:21:07 +00:00
Alexander Nasonov c28efea0b3 Fix an access to grouping[grouping.size()].
AFAIK, this is valid for const strings but STLport (when _STLP_DEBUG
is defined) doesn't like it.
The problem reported by Bogdan Dragu.


[SVN r65279]
2010-09-05 00:02:25 +00:00
Steven Watanabe 00b609b498 Supress MSVC /Wp64 warnings. Fixes #4184
[SVN r62806]
2010-06-11 16:12:39 +00:00
Alexander Nasonov 2cfa78ab40 Apply the patch from #4119. Fixes #4119.
[SVN r62529]
2010-06-07 22:58:42 +00:00
Alexander Nasonov 5c1dc5388c Use BOOST_LCAST_THROW_BAD_CAST consistently.
[SVN r59664]
2010-02-13 01:24:34 +00:00
John Maddock fce9ad4e1b Misc small fixes to suppress warnings.
Code should now be clean with msvc /W4 and gcc /Wall /Wextra -pedantic with the exception of one deliberate warning in one test.

[SVN r57510]
2009-11-09 12:27:54 +00:00
Troy D. Straszheim febafb7cb8 rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
Alexander Nasonov f5d825e77f Decrease indent of #if and #endif lines and test string<->integral conversons when BOOST_NO_INTRINSIC_WCHAR_T is defined.
[SVN r56232]
2009-09-15 23:56:39 +00:00
Alexander Nasonov 79a141ce9d Add new test libs/conversion/test/lexical_cast_vc8_bug_test.cpp.
[SVN r56229]
2009-09-15 23:38:21 +00:00
Alexander Nasonov 78adbeaab1 DISABLE_WIDE_CHAR_SUPPORT -> BOOST_LCAST_NO_WCHAR_T.
[SVN r56228]
2009-09-15 22:55:02 +00:00
Alexander Nasonov 0aaa89042a Add a test for uintmax_t.
[SVN r56171]
2009-09-13 14:58:34 +00:00
Alexander Nasonov b37f56f478 Fix #2295 (Inconsistent behavior when using 64 bit integer types).
[SVN r56170]
2009-09-13 14:48:27 +00:00
Alexander Nasonov c22d671409 Fix #1847 (Can't compile without <locale> header, boost::lexical_cast problem).
[SVN r56160]
2009-09-12 22:22:28 +00:00
Alexander Nasonov 8582e25571 Fix #1791 (fix warning on MSVC warning level 4) and undo r34801 (some "rewording" to avoid spurious level 4 warnings with VC7.1 and VC8).
[SVN r56158]
2009-09-12 21:47:27 +00:00
Troy D. Straszheim a77fc4c0bb Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
Gennadiy Rozental 7b37688ca8 avoid C style casts
[SVN r53670]
2009-06-06 09:41:03 +00:00
Gennadiy Rozental fa4a95c1dd avoid C style casts
[SVN r53668]
2009-06-06 09:38:47 +00:00
Alexander Nasonov 5fa1edeee0 Fixes #1220: lexical_cast requires RTTI
[SVN r50123]
2008-12-04 22:59:27 +00:00
Michael A. Jackson b72cb10ae6 Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
Michael A. Jackson 4217a354f5 Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
Alexander Nasonov 6c5fd3e86d Fix #2184 (Macro without BOOST_ prefix)
[SVN r49262]
2008-10-10 23:16:10 +00:00
Alexander Nasonov 2296357eaf Fix #2299 (Patch to fix warnings in lexical_cast)
[SVN r49261]
2008-10-10 22:56:08 +00:00
Nicola Musatti 33981b9400 Patch from Ticket #2370
[SVN r49154]
2008-10-06 20:22:10 +00:00
Daniel James 2708853971 Clean up some link errors.
[SVN r48987]
2008-09-28 12:21:39 +00:00
Daniel James ae273a3e7b Fix link to numeric conversion library.
[SVN r48003]
2008-08-06 15:28:17 +00:00
Peter Dimov 0d258ff7b1 Largely pointless Borland 5.5.1 changes. :-)
[SVN r45627]
2008-05-21 21:13:22 +00:00
Alexander Nasonov ae5cbbbec8 Fixes #1847 Can't compile without <locale> header, boost::lexical_cast problem
[SVN r45201]
2008-05-07 19:43:55 +00:00
Alexander Nasonov e1dbc6ef04 Use make_unsigned and get rid of gcc warnings when -DBOOST_LEXICAL_CAST_ASSUME_C_LOCALE
[SVN r44474]
2008-04-16 21:13:25 +00:00
Daniel James 0ad888867f Link to people pages on the website, as they've been removed from the download.
[SVN r43209]
2008-02-10 14:56:22 +00:00
Beman Dawes 408cbf0dcb Correct misspelling of library name
[SVN r42069]
2007-12-15 14:26:16 +00:00
Alexander Nasonov 808f210c0d Link to html version of [Tuning] and BOOST_LEXICAL_CAST_ASSUME_C_LOCALE synopsis
[SVN r41703]
2007-12-04 21:49:51 +00:00
Alexander Nasonov 69cf3b2766 Remove redundant BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION.
[SVN r41406]
2007-11-26 21:29:04 +00:00
Joaquín M López Muñoz ec8665d114 added missing traits template arg to a lexical_stream instantiation
[SVN r41394]
2007-11-26 11:52:03 +00:00
Alexander Nasonov 05036d3ae1 Support for string with non-default char_traits and allocator.
[SVN r41387]
2007-11-25 23:08:50 +00:00
Alexander Nasonov 159b045ad7 Pass unsigned type to lcast_put_unsigned.
[SVN r41385]
2007-11-25 22:28:16 +00:00
Alexander Nasonov 2cc7aedd28 minor changes
[SVN r41331]
2007-11-24 15:22:52 +00:00
Eric Niebler 340f9b9e45 fix warning in gcc-4.3
[SVN r41258]
2007-11-20 16:52:43 +00:00
Beman Dawes 726f188aa4 // Add or correct comment identifying Boost library this header is associated with.
[SVN r41173]
2007-11-17 20:13:16 +00:00
Alexander Nasonov e70cf014ad #839 fixed: local variable shadow patch
[SVN r40816]
2007-11-05 22:22:48 +00:00
Joaquín M López Muñoz 0d6a924f94 applied workaround for MSVC++ 6.5/7.0 problem with static constants inside templates, see http://lists.boost.org/Archives/boost/2007/10/128392.php
[SVN r40146]
2007-10-18 06:57:25 +00:00
Vladimir Prus b9a7ee6deb Remove V1 Jamfiles
[SVN r38516]
2007-08-08 19:02:26 +00:00
Alexander Nasonov 9c1f3650f2 Added BOOST_LEXICAL_CAST_ASSUME_C_LOCALE.
[SVN r37950]
2007-06-08 19:59:40 +00:00
Alexander Nasonov da5151abf6 added: FAQ and References section, updated: Changes
[SVN r37725]
2007-05-20 16:25:34 +00:00
Alexander Nasonov f986e8e588 Get rid of Tru64 cxx warnings
[SVN r37116]
2007-02-28 21:44:10 +00:00
Hartmut Kaiser 959b7ab0b4 Fixed a warning, when lexical cast is used to convert a boost::ulong_long_type to a string.
[SVN r37082]
2007-02-26 17:27:26 +00:00
Alexander Nasonov 42cb6d66cf lexical_cast_noncopyable_test.cpp
[SVN r36763]
2007-01-20 13:17:35 +00:00
Alexander Nasonov 209644c177 Better fix for SF:1358600
[SVN r36762]
2007-01-20 13:16:40 +00:00
Alexander Nasonov cf477316ed Documentation update for [ 1358600 ] lexical_cast & pure virtual functions & VC 8 STL
[SVN r36740]
2007-01-16 22:22:19 +00:00
Alexander Nasonov 986ec16ecc Fix [ 1358600 ] lexical_cast & pure virtual functions & VC 8 STL
[SVN r36739]
2007-01-16 21:53:27 +00:00
Alexander Nasonov 2c41ed0473 Fix for [ 1358600 ] lexical_cast & pure virtual functions & VC 8 STL
[SVN r36738]
2007-01-16 21:03:47 +00:00
Alexander Nasonov fcc28133c5 Presumably fix Boost.Test failures on Sun CC 5.3 (reported by Gennadiy Rozental)
[SVN r36464]
2006-12-20 08:01:48 +00:00
Vladimir Prus de6746d67a Allow building of shared versions of some Boost.Test libraries.
Adjust tests to use always use static linking to Boost.Test, since
linking to the shared version requires test changes.

Patch from Juergen Hunold.


[SVN r35989]
2006-11-10 19:09:56 +00:00
Alexander Nasonov 67968d9b33 Separate test for round-tripping of floating point types.
[SVN r35771]
2006-10-28 19:33:32 +00:00
Alexander Nasonov c004fb5fc6 Fix the test built with <native-wchar_t>off on vc-7_1 and vc-8_0
[SVN r35760]
2006-10-28 14:37:37 +00:00
Alexander Nasonov ef439017ca Fixed: std::basic_streambuf<char, std::char_traits<char> > is an inaccessible base of boost::detail::lexical_streambuf<char>
[SVN r35759]
2006-10-28 10:22:30 +00:00
Alexander Nasonov fb63ebd4cd The test passed on VC6
[SVN r35755]
2006-10-27 21:28:33 +00:00
Alexander Nasonov 0f46451c1d One more VC6 workaround.
[SVN r35747]
2006-10-25 21:08:50 +00:00
Alexander Nasonov 663635d124 Optimization for floating types (1.25 faster on gcc / FreeBSD 6.2). VC6 test is still broken.
[SVN r35739]
2006-10-25 06:43:44 +00:00
Alexander Nasonov 4d69e9f2af VC6 workaround
[SVN r35738]
2006-10-25 06:41:21 +00:00
Alexander Nasonov d23f722228 Corrected a typo in comments.
[SVN r35611]
2006-10-14 17:58:33 +00:00
Alexander Nasonov e9767dc4e8 workarounds for test_round_conversion_long_double
[SVN r35606]
2006-10-14 10:09:49 +00:00
Alexander Nasonov 2b069eb3a3 test_round_conversion_long_double added to testsuite despite that it fails on FreeBSD and OpenBSD
[SVN r35600]
2006-10-13 22:27:53 +00:00
Alexander Nasonov 36db66bd12 Use metafunction (at compile-time), if possible; use run-time function only for broken libraries.
[SVN r35596]
2006-10-13 20:43:14 +00:00
Alexander Nasonov 4b1ca7bdf6 round conversion of floating point types: T -> std::string -> T
[SVN r35595]
2006-10-13 19:40:03 +00:00
Alexander Nasonov 0a605d1bb3 Use qualified name to fix graph tests
[SVN r35592]
2006-10-13 17:34:56 +00:00
Dave Abrahams 04de824ead vc6 workaround: help the compiler to distinguish overloads
[SVN r35566]
2006-10-12 06:39:14 +00:00
Alexander Nasonov 115ad05af5 Set precision correctly for builtin and UDT floating types.
[SVN r35562]
2006-10-11 19:43:54 +00:00
Alexander Nasonov ee7ea0011c Calculate/set stream precision for lexical_cast. May be useful for other libraries as well.
[SVN r35561]
2006-10-11 19:19:07 +00:00
Alexander Nasonov a2c7ddf5d9 no more gcc warnings
[SVN r35560]
2006-10-11 19:13:30 +00:00
Alexander Nasonov a7436ebacb setbuf renamed to lcast_setbuf to get rid of virtual function override warning
[SVN r34984]
2006-08-28 17:00:44 +00:00
Alexander Nasonov e797b09590 tabs replaced with 4 spaces
[SVN r34965]
2006-08-26 17:22:33 +00:00
Alexander Nasonov 2fca4d02a1 Optimization for many combinations of types
[SVN r34950]
2006-08-25 20:34:57 +00:00
Alexander Nasonov c17002aa73 get rid of lexical_cast.hpp impl details in the test
[SVN r34932]
2006-08-23 19:47:56 +00:00
Alexander Nasonov ae431bacf8 Better coverage
[SVN r34925]
2006-08-22 20:40:31 +00:00
Gennaro Prota 425e7cb367 removed BOOST_IMPLICIT_CAST; it was committed by mistake, has no unit tests, and is not released by the author under the Boost Software License
[SVN r34857]
2006-08-09 20:18:06 +00:00
Alexander Nasonov 453555619e New test cases for forthcoming fast lexical_cast
[SVN r34847]
2006-08-07 20:36:23 +00:00
Gennaro Prota 0743b5982c added slash to boost url
fixed silly error in #if/#endif logic of the previous edit
improved comment about code never reached
removed "All rights reserved"


[SVN r34822]
2006-08-06 12:31:44 +00:00
Gennaro Prota 795b7e1809 there seems to be no reasonable form which avoids warnings with all compilers; so let's use a clear style and filter explicitly the VC warning
[SVN r34820]
2006-08-05 22:45:53 +00:00
Gennaro Prota c5bc634015 some "rewording" to avoid spurious level 4 warnings with VC7.1 and VC8
[SVN r34801]
2006-08-01 22:37:38 +00:00
Gennaro Prota e6c83d0665 with apologies to Terje, changed 'ø' in 'o', to stick to the basic source
character set (non-basic chars should be handled in phase 1, but some users report compile failures due to them)


[SVN r34800]
2006-08-01 20:36:14 +00:00
Gennaro Prota aac8fcb4b6 boost guidelines (mainly from inspect tool: tabs, license reference text, etc.)
[SVN r34752]
2006-07-27 10:27:37 +00:00
Alexander Nasonov d436099477 Code size optimization
[SVN r33694]
2006-04-13 20:52:28 +00:00
21 changed files with 844 additions and 216 deletions
+12 -6
View File
@@ -10,6 +10,13 @@
<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">
@@ -131,10 +138,9 @@ void f( Fruit * fruit ) {
-->June 23, 2005<!--webbot bot="Timestamp" endspan i-checksum="30348"
--></p>
<p>&copy; 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>
<p class="copyright">&copy; 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>
</body>
</html>
</html>
+151 -96
View File
@@ -3,7 +3,7 @@
[version 1.0]
[copyright 2000-2005 Kevlin Henney]
[copyright 2006-2010 Alexander Nasonov]
[copyright 2011-2012 Antony Polukhin]
[copyright 2011-2013 Antony Polukhin]
[category String and text processing]
[category Miscellaneous]
[license
@@ -38,54 +38,22 @@ 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;
std::vector<short> args;
[import ../example/args_to_numbers.cpp]
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 &);
[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]
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);
``
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);
}
``
[endsect]
[section Synopsis]
@@ -156,56 +124,6 @@ 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`?
@@ -276,6 +194,17 @@ limitation of compiler options that you use.
[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.
@@ -880,6 +809,132 @@ 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]
+35
View File
@@ -0,0 +1,35 @@
// 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]
+61
View File
@@ -0,0 +1,61 @@
// 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]
+52
View File
@@ -0,0 +1,52 @@
// 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;
}
+39
View File
@@ -0,0 +1,39 @@
// 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]
+248 -68
View File
@@ -19,7 +19,7 @@
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
// Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2012
// when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2013
#include <boost/config.hpp>
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
@@ -168,6 +168,7 @@ namespace boost
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/range/iterator_range_core.hpp>
#include <boost/container/container_fwd.hpp>
#include <boost/integer.hpp>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
@@ -310,6 +311,11 @@ namespace boost {
> {};
#endif
#ifdef BOOST_HAS_INT128
template <> struct stream_char_common< boost::int128_type >: public boost::mpl::identity< char > {};
template <> struct stream_char_common< boost::uint128_type >: public boost::mpl::identity< char > {};
#endif
#if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T)
template <>
struct stream_char_common< wchar_t >
@@ -602,6 +608,10 @@ namespace boost {
BOOST_LCAST_DEF(unsigned __int64)
BOOST_LCAST_DEF( __int64)
#endif
#ifdef BOOST_HAS_INT128
BOOST_LCAST_DEF(boost::int128_type)
BOOST_LCAST_DEF(boost::uint128_type)
#endif
#undef BOOST_LCAST_DEF
@@ -824,7 +834,7 @@ namespace boost {
if(group < grouping_size)
{
char const grp_size = grouping[group];
last_grp_size = grp_size <= 0 ? CHAR_MAX : grp_size;
last_grp_size = grp_size <= 0 ? static_cast<char>(CHAR_MAX) : grp_size;
}
left = last_grp_size;
@@ -864,15 +874,23 @@ namespace boost {
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(!std::numeric_limits<T>::is_signed);
// GCC when used with flag -std=c++0x may not have std::numeric_limits
// specializations for __int128 and unsigned __int128 types.
// Try compilation with -std=gnu++0x or -std=gnu++11.
//
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40856
BOOST_STATIC_ASSERT_MSG(std::numeric_limits<T>::is_specialized,
"std::numeric_limits are not specialized for integral type passed to boost::lexical_cast"
);
#endif
typedef typename Traits::int_type int_type;
CharT const czero = lcast_char_constants<CharT>::zero;
--end;
value = 0;
if (begin > end || *end < czero || *end >= czero + 10)
return false;
value = *end - czero;
value = static_cast<T>(*end - czero);
--end;
T multiplier = 1;
bool multiplier_overflowed = false;
@@ -892,17 +910,17 @@ namespace boost {
{
unsigned char current_grouping = 0;
CharT const thousands_sep = np.thousands_sep();
char remained = grouping[current_grouping] - 1;
char remained = static_cast<char>(grouping[current_grouping] - 1);
bool shall_we_return = true;
for(;end>=begin; --end)
{
if (remained) {
T const multiplier_10 = multiplier * 10;
T const multiplier_10 = static_cast<T>(multiplier * 10);
if (multiplier_10 / 10 != multiplier) multiplier_overflowed = true;
T const dig_value = *end - czero;
T const new_sub_value = multiplier_10 * dig_value;
T const dig_value = static_cast<T>(*end - czero);
T const new_sub_value = static_cast<T>(multiplier_10 * dig_value);
if (*end < czero || *end >= czero + 10
/* detecting overflow */
@@ -912,8 +930,8 @@ namespace boost {
)
return false;
value += new_sub_value;
multiplier *= 10;
value = static_cast<T>(value + new_sub_value);
multiplier = static_cast<T>(multiplier * 10);
--remained;
} else {
if ( !Traits::eq(*end, thousands_sep) ) //|| begin == end ) return false;
@@ -946,11 +964,11 @@ namespace boost {
{
while ( begin <= end )
{
T const multiplier_10 = multiplier * 10;
T const multiplier_10 = static_cast<T>(multiplier * 10);
if (multiplier_10 / 10 != multiplier) multiplier_overflowed = true;
T const dig_value = *end - czero;
T const new_sub_value = multiplier_10 * dig_value;
T const dig_value = static_cast<T>(*end - czero);
T const new_sub_value = static_cast<T>(multiplier_10 * dig_value);
if (*end < czero || *end >= czero + 10
/* detecting overflow */
@@ -960,8 +978,8 @@ namespace boost {
)
return false;
value += new_sub_value;
multiplier *= 10;
value = static_cast<T>(value + new_sub_value);
multiplier = static_cast<T>(multiplier * 10);
--end;
}
}
@@ -1142,6 +1160,12 @@ namespace boost {
namespace detail // lcast_ret_float
{
// Silence buggy MS warnings like C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data
#if defined(_MSC_VER) && (_MSC_VER == 1400)
# pragma warning(push)
# pragma warning(disable:4244)
#endif
template <class T>
struct mantissa_holder_type
{
@@ -1152,15 +1176,19 @@ namespace boost {
struct mantissa_holder_type<float>
{
typedef unsigned int type;
typedef double wide_result_t;
};
template <>
struct mantissa_holder_type<double>
{
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
typedef long double wide_result_t;
#if defined(BOOST_HAS_LONG_LONG)
typedef boost::ulong_long_type type;
#elif defined(BOOST_HAS_MS_INT64)
typedef unsigned __int64 type;
#endif
#endif
};
@@ -1178,7 +1206,7 @@ namespace boost {
: np.grouping()
);
std::string::size_type const grouping_size = grouping.size();
CharT const thousands_sep = grouping_size ? np.thousands_sep() : 0;
CharT const thousands_sep = static_cast<CharT>(grouping_size ? np.thousands_sep() : 0);
CharT const decimal_point = np.decimal_point();
bool found_grouping = false;
std::string::size_type last_grouping_pos = grouping_size - 1;
@@ -1198,6 +1226,7 @@ namespace boost {
typedef typename Traits::int_type int_type;
typedef BOOST_DEDUCED_TYPENAME mantissa_holder_type<T>::type mantissa_type;
typedef BOOST_DEDUCED_TYPENAME mantissa_holder_type<T>::wide_result_t wide_result_t;
int_type const zero = Traits::to_int_type(czero);
if (begin == end) return false;
@@ -1376,32 +1405,110 @@ namespace boost {
/* We need a more accurate algorithm... We can not use current algorithm
* with long doubles (and with doubles if sizeof(double)==sizeof(long double)).
*/
long double result = std::pow(10.0L, pow_of_10) * mantissa;
const wide_result_t result = std::pow(static_cast<wide_result_t>(10.0), pow_of_10) * mantissa;
value = static_cast<T>( has_minus ? (boost::math::changesign)(result) : result);
if ( (boost::math::isinf)(value) || (boost::math::isnan)(value) ) return false;
return true;
}
// Unsilence buggy MS warnings like C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data
#if defined(_MSC_VER) && (_MSC_VER == 1400)
# pragma warning(pop)
#endif
}
namespace detail // stl_buf_unlocker
namespace detail // parser_buf
{
template< class BufferType, class CharT >
class stl_buf_unlocker: public BufferType{
//
// class parser_buf:
// acts as a stream buffer which wraps around a pair of pointers
//
// This class is copied (and slightly changed) from
// boost/regex/v4/cpp_regex_traits.hpp
// Thanks John Maddock for it! (previous version had some
// problems with libc++ and some other STL implementations)
template <class BufferType, class charT>
class parser_buf : public BufferType {
typedef BufferType base_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:
typedef BufferType base_class;
parser_buf() : base_type() { setbuf(0, 0); }
const charT* getnext() { return this->gptr(); }
#ifndef BOOST_NO_USING_TEMPLATE
using base_class::pptr;
using base_class::pbase;
using base_class::setg;
using base_class::setp;
using base_type::pptr;
using base_type::pbase;
#else
CharT* pptr() const { return base_class::pptr(); }
CharT* pbase() const { return base_class::pbase(); }
void setg(CharT* gbeg, CharT* gnext, CharT* gend){ return base_class::setg(gbeg, gnext, gend); }
void setp(CharT* pbeg, CharT* pend) { return setp(pbeg, pend); }
charT* pptr() const { return base_type::pptr(); }
charT* pbase() const { return base_type::pbase(); }
#endif
base_type* setbuf(char_type* s, streamsize n) {
this->setg(s, s, s + n);
return this;
}
pos_type 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));
}
pos_type 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
}
private:
parser_buf& operator=(const parser_buf&);
parser_buf(const parser_buf&);
};
}
@@ -1422,13 +1529,12 @@ namespace boost {
#if defined(BOOST_NO_STRINGSTREAM)
typedef std::ostrstream out_stream_t;
typedef stl_buf_unlocker<std::strstreambuf, char> unlocked_but_t;
#elif defined(BOOST_NO_STD_LOCALE)
typedef std::ostringstream out_stream_t;
typedef stl_buf_unlocker<std::stringbuf, char> unlocked_but_t;
typedef parser_buf<std::streambuf, char> buffer_t;
#else
typedef std::basic_ostringstream<CharT, Traits> out_stream_t;
typedef stl_buf_unlocker<std::basic_stringbuf<CharT, Traits>, CharT> unlocked_but_t;
typedef std::basic_ostringstream<CharT, Traits> out_stream_t;
typedef parser_buf<std::basic_streambuf<CharT, Traits>, CharT> buffer_t;
#endif
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
RequiresStringbuffer,
@@ -1442,7 +1548,7 @@ namespace boost {
deduced_out_stream_t out_stream;
public:
lexical_stream_limited_src(CharT* sta, CharT* fin)
lexical_stream_limited_src(CharT* sta, CharT* fin) BOOST_NOEXCEPT
: start(sta)
, finish(fin)
{}
@@ -1510,12 +1616,23 @@ namespace boost {
// does not support such conversions. Try updating it.
BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
#endif
#ifndef BOOST_NO_EXCEPTIONS
out_stream.exceptions(std::ios::badbit);
try {
#endif
bool const result = !(out_stream << input).fail();
const unlocked_but_t* const p
= static_cast<unlocked_but_t*>(out_stream.rdbuf()) ;
const buffer_t* const p = static_cast<buffer_t*>(
static_cast<std::basic_streambuf<CharT, Traits>*>(out_stream.rdbuf())
);
start = p->pbase();
finish = p->pptr();
return result;
#ifndef BOOST_NO_EXCEPTIONS
} catch (const ::std::ios_base::failure& /*f*/) {
return false;
}
#endif
}
template <class T>
@@ -1723,6 +1840,12 @@ namespace boost {
bool operator<<(unsigned __int64 n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
bool operator<<( __int64 n) { return shl_signed(n); }
#endif
#ifdef BOOST_HAS_INT128
bool operator<<(const boost::uint128_type& n) { start = lcast_put_unsigned<Traits>(n, finish); return true; }
bool operator<<(const boost::int128_type& n) { return shl_signed(n); }
#endif
bool operator<<(float val) { return shl_real_type(val, start, finish); }
bool operator<<(double val) { return shl_real_type(val, start, finish); }
bool operator<<(long double val) {
@@ -1858,35 +1981,38 @@ namespace boost {
template<typename InputStreamable>
bool shr_using_base_class(InputStreamable& output)
{
#if (defined _MSC_VER)
# pragma warning( push )
// conditional expression is constant
# pragma warning( disable : 4127 )
#endif
if(is_pointer<InputStreamable>::value)
return false;
BOOST_STATIC_ASSERT_MSG(
(!boost::is_pointer<InputStreamable>::value),
"boost::lexical_cast can not convert to pointers"
);
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
// If you have compilation error at this point, than your STL library
// unsupports such conversions. Try updating it.
BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
BOOST_STATIC_ASSERT_MSG((boost::is_same<char, CharT>::value),
"boost::lexical_cast can not convert, because your STL library does not "
"support such conversions. Try updating it."
);
#endif
#if defined(BOOST_NO_STRINGSTREAM)
std::istrstream stream(start, finish - start);
#elif defined(BOOST_NO_STD_LOCALE)
std::istringstream stream;
#else
std::basic_istringstream<CharT, Traits> stream;
#endif
static_cast<unlocked_but_t*>(stream.rdbuf())
->setg(start, start, finish);
buffer_t buf;
buf.setbuf(start, finish - start);
#if defined(BOOST_NO_STD_LOCALE)
std::istream stream(&buf);
#else
std::basic_istream<CharT, Traits> stream(&buf);
#endif // BOOST_NO_STD_LOCALE
#endif // BOOST_NO_STRINGSTREAM
#ifndef BOOST_NO_EXCEPTIONS
stream.exceptions(std::ios::badbit);
try {
#endif
stream.unsetf(std::ios::skipws);
lcast_set_precision(stream, static_cast<InputStreamable*>(0));
#if (defined _MSC_VER)
# pragma warning( pop )
#endif
return stream >> output &&
stream.get() ==
#if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING)
@@ -1898,6 +2024,12 @@ namespace boost {
#else
Traits::eof();
#endif
#ifndef BOOST_NO_EXCEPTIONS
} catch (const ::std::ios_base::failure& /*f*/) {
return false;
}
#endif
}
template<class T>
@@ -1916,7 +2048,7 @@ namespace boost {
}
/************************************ OPERATORS >> ( ... ) ********************************/
public:
public:
bool operator>>(unsigned short& output) { return shr_unsigned(output); }
bool operator>>(unsigned int& output) { return shr_unsigned(output); }
bool operator>>(unsigned long int& output) { return shr_unsigned(output); }
@@ -1930,6 +2062,12 @@ namespace boost {
bool operator>>(unsigned __int64& output) { return shr_unsigned(output); }
bool operator>>(__int64& output) { return shr_signed(output); }
#endif
#ifdef BOOST_HAS_INT128
bool operator>>(boost::uint128_type& output) { return shr_unsigned(output); }
bool operator>>(boost::int128_type& output) { return shr_signed(output); }
#endif
bool operator>>(char& output) { return shr_xchar(output); }
bool operator>>(unsigned char& output) { return shr_xchar(output); }
bool operator>>(signed char& output) { return shr_xchar(output); }
@@ -2085,10 +2223,10 @@ namespace boost {
* double, because it will give a big precision loss.
* */
boost::mpl::if_c<
#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)
#if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
boost::type_traits::ice_eq< sizeof(double), sizeof(long double) >::value,
#else
0
1,
#endif
int,
char
@@ -2324,7 +2462,7 @@ namespace boost {
> converter_t;
return (
arg < 0 ? 0u - converter_t::convert(0u - arg) : converter_t::convert(arg)
arg < 0 ? static_cast<Target>(0u - converter_t::convert(0u - arg)) : converter_t::convert(arg)
);
}
};
@@ -2405,17 +2543,59 @@ namespace boost {
return caster_type::lexical_cast_impl(arg);
}
template <typename Target, typename CharType>
inline Target lexical_cast(const CharType* chars, std::size_t count)
{
BOOST_STATIC_ASSERT_MSG(boost::detail::is_char_or_wchar<CharType>::value,
"CharType must be a character or wide character type");
return boost::lexical_cast<Target>(
boost::iterator_range<const CharType*>(chars, chars + count)
template <typename Target>
inline Target lexical_cast(const char* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char*>(chars, chars + count)
);
}
template <typename Target>
inline Target lexical_cast(const unsigned char* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const unsigned char*>(chars, chars + count)
);
}
template <typename Target>
inline Target lexical_cast(const signed char* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const signed char*>(chars, chars + count)
);
}
#ifndef BOOST_LCAST_NO_WCHAR_T
template <typename Target>
inline Target lexical_cast(const wchar_t* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const wchar_t*>(chars, chars + count)
);
}
#endif
#ifndef BOOST_NO_CXX11_CHAR16_T
template <typename Target>
inline Target lexical_cast(const char16_t* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char16_t*>(chars, chars + count)
);
}
#endif
#ifndef BOOST_NO_CXX11_CHAR32_T
template <typename Target>
inline Target lexical_cast(const char32_t* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char32_t*>(chars, chars + count)
);
}
#endif
} // namespace boost
#else // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
@@ -2555,7 +2735,7 @@ namespace boost {
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2012.
// Copyright Antony Polukhin, 2011-2013.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
+13 -2
View File
@@ -6,6 +6,13 @@
<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">
@@ -32,7 +39,11 @@ 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>
+5 -10
View File
@@ -36,6 +36,7 @@
#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)) \
@@ -66,7 +67,6 @@ 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();
@@ -99,7 +99,6 @@ 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
@@ -311,14 +310,6 @@ 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
@@ -622,6 +613,10 @@ void test_getting_pointer_to_function()
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>);
}
+1 -1
View File
@@ -48,7 +48,7 @@ int test_main( int , char * [] )
long large_negative_value = LONG_MIN;
signed char c = 0;
c = large_value; // see if compiler generates warning
c = static_cast<signed char>(large_value);
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
+16 -2
View File
@@ -1,5 +1,5 @@
# Copyright (C) 2001-2003 Douglas Gregor
# Copyright (C) 2011-2012 Antony Polukhin
# Copyright (C) 2011-2013 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)
@@ -15,6 +15,11 @@ project
<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
;
# Thanks to Steven Watanabe for helping with <nowchar> feature
@@ -35,7 +40,7 @@ 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 ]
[ run lexical_cast_containers_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>clang:<cxxflags>-Wno-long-long ]
[ run lexical_cast_empty_input_test.cpp ]
[ run lexical_cast_pointers_test.cpp ]
[ compile lexical_cast_typedefed_wchar_test.cpp : <toolset>msvc:<nowchar>on ]
@@ -55,5 +60,14 @@ test-suite conversion
[ 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) ] ;
}
+3 -1
View File
@@ -19,6 +19,8 @@ struct foo
int test_main(int, char*[])
{
foo x = implicit_cast<foo>("foobar");
(void)x; // warning suppression.
(void)x; // warning suppression.
BOOST_CHECK(false); // suppressing warning about 'boost::unit_test::{anonymous}::unit_test_log' defined but not used
return 0;
}
+18 -8
View File
@@ -22,6 +22,14 @@ 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 =
@@ -91,7 +99,7 @@ static void testing_template_array_output_on_spec_value(T val)
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
#ifdef BOOST_LC_RUNU16
typedef ArrayT<char16_t, 300> u16arr_type;
typedef ArrayT<char16_t, 3> u16short_arr_type;
std::u16string u16ethalon(u"100");
@@ -109,7 +117,7 @@ static void testing_template_array_output_on_spec_value(T val)
BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), boost::bad_lexical_cast);
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
#ifdef BOOST_LC_RUNU32
typedef ArrayT<char32_t, 300> u32arr_type;
typedef ArrayT<char32_t, 3> u32short_arr_type;
std::u32string u32ethalon(U"100");
@@ -190,7 +198,7 @@ static void testing_template_array_output_on_char_value()
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
#ifdef BOOST_LC_RUNU16
typedef ArrayT<char16_t, 300> u16arr_type;
typedef ArrayT<char16_t, 3> u16short_arr_type;
std::u16string u16ethalon(u"100");
@@ -214,10 +222,11 @@ static void testing_template_array_output_on_char_value()
BOOST_CHECK(&res3[0] == u16ethalon);
}
BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), boost::bad_lexical_cast);
// Some compillers may throw std::bad_alloc here
BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), std::exception);
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
#ifdef BOOST_LC_RUNU32
typedef ArrayT<char32_t, 300> u32arr_type;
typedef ArrayT<char32_t, 3> u32short_arr_type;
std::u32string u32ethalon(U"100");
@@ -240,7 +249,8 @@ static void testing_template_array_output_on_char_value()
BOOST_CHECK(&res3[0] == u32ethalon);
}
BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), boost::bad_lexical_cast);
// Some compillers may throw std::bad_alloc here
BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), std::exception);
#endif
}
@@ -328,7 +338,7 @@ static void testing_generic_array_input_conversion()
}
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
#ifdef BOOST_LC_RUNU16
{
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");
@@ -339,7 +349,7 @@ static void testing_generic_array_input_conversion()
}
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
#ifdef BOOST_LC_RUNU32
{
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");
+2
View File
@@ -32,7 +32,9 @@ 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)
+46
View File
@@ -0,0 +1,46 @@
// 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);
}
+10 -3
View File
@@ -264,8 +264,11 @@ 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);
BOOST_CHECK_THROW(lexical_cast<test_t>("0xB"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("0x0"), 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>("--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);
@@ -294,12 +297,16 @@ void test_float_typess_for_overflows()
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 fllowing tests on floats and doubles when using stingstream...
// VC9 can fail the following 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 )
{
+86 -13
View File
@@ -34,6 +34,7 @@
#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>
@@ -56,6 +57,8 @@ 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();
@@ -68,6 +71,10 @@ 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();
@@ -87,6 +94,10 @@ unit_test::test_suite *init_unit_test_suite(int, char *[])
#ifdef LCAST_TEST_LONGLONG
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));
@@ -372,7 +383,7 @@ struct restore_oldloc
};
template<class T>
void test_conversion_from_to_integral()
void test_conversion_from_to_integral_minimal()
{
char const zero = '0';
signed char const szero = '0';
@@ -388,12 +399,12 @@ void test_conversion_from_to_integral()
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)
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
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)
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
char32_t const u32zero = u'0';
test_conversion_from_integral_to_char<T>(u32zero);
test_conversion_from_char_to_integral<T>(u32zero);
@@ -429,8 +440,8 @@ void test_conversion_from_to_integral()
// test_conversion_from_to_integral_for_locale
// Overflow test case from David W. Birdsall
std::string must_owerflow_str = "160000000000000000000";
std::string must_owerflow_negative_str = "-160000000000000000000";
std::string must_owerflow_str = (sizeof(T) < 16 ? "160000000000000000000" : "1600000000000000000000000000000000000000");
std::string must_owerflow_negative_str = (sizeof(T) < 16 ? "-160000000000000000000" : "-1600000000000000000000000000000000000000");
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);
@@ -438,7 +449,12 @@ void test_conversion_from_to_integral()
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;
@@ -536,19 +552,76 @@ 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()
{
typedef std::numeric_limits<int> int_limits;
typedef std::numeric_limits<unsigned int> uint_limits;
test_integral_conversions_on_min_max_impl<int>();
test_integral_conversions_on_min_max_impl<short>();
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>((uint_limits::max)()), (uint_limits::max)());
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>((uint_limits::min)()), (uint_limits::min)());
#ifdef _MSC_VER
test_integral_conversions_on_min_max_impl<long int>();
BOOST_CHECK_EQUAL(lexical_cast<int>((int_limits::max)()), (int_limits::max)());
BOOST_CHECK_EQUAL(lexical_cast<int>((uint_limits::min)()), static_cast<int>((uint_limits::min)()));
#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
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>((int_limits::max)()), static_cast<unsigned int>((int_limits::max)()));
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>((int_limits::min)()), static_cast<unsigned int>((int_limits::min)()));
}
+19 -4
View File
@@ -27,6 +27,15 @@ 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;
@@ -63,8 +72,10 @@ void do_test_iterator_range_impl(const RngT& rng)
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)
@@ -119,12 +130,16 @@ 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
@@ -134,7 +149,7 @@ void test_it_range_using_char(CharT* one, CharT* eleven)
BOOST_CHECK(lexical_cast<std::wstring>(crng2) == L"1");
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
#if defined(BOOST_LC_RUNU16) && 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");
@@ -142,7 +157,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_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
#if defined(BOOST_LC_RUNU32) && 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");
@@ -194,7 +209,7 @@ void test_wchar_iterator_ranges()
void test_char16_iterator_ranges()
{
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
#if defined(BOOST_LC_RUNU16)
typedef char16_t test_char_type;
test_char_type data1[] = u"1";
test_char_type data2[] = u"11";
@@ -206,7 +221,7 @@ void test_char16_iterator_ranges()
void test_char32_iterator_ranges()
{
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
#if defined(BOOST_LC_RUNU32)
typedef char32_t test_char_type;
test_char_type data1[] = U"1";
test_char_type data2[] = U"11";
+2
View File
@@ -37,7 +37,9 @@ 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)
+23
View File
@@ -0,0 +1,23 @@
// // 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;
}
+2 -2
View File
@@ -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] += 9; // '0' -> '9'
s[s.size()-1] += static_cast<CharT>(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] += 9; // '0' -> '9'
s[s.size()-1] += static_cast<CharT>(9); // '0' -> '9'
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
}
}