Compare commits

..

159 Commits

Author SHA1 Message Date
Antony Polukhin 827dd94c68 Update copyright years 2026-01-02 13:40:23 +03:00
dependabot[bot] 782e083f61 Bump actions/checkout from 2 to 6 (#32)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-26 22:04:25 +03:00
Antony Polukhin 1e6424563d Add dependabot 2025-12-24 20:19:01 +03:00
Antony Polukhin 6632ca9309 Run all the tests in CMake, add CMake runs into CI. Drop dependency on Boost.SmartPtr as it is not used by the library for some time (#31) 2025-10-07 20:26:12 +03:00
Antony Polukhin b74a4c34cb Allow using polymorphic_downcast and polymorphic_cast in constexpr (#30) 2025-06-27 20:42:54 +03:00
Antony Polukhin 452adac97f CI fixes 2025-06-27 17:33:16 +03:00
Antony Polukhin 5f82d5aa7d Update regression test links in Readme and fix typos 2025-06-19 09:27:35 +03:00
Antony Polukhin 9d64c899df Update copyright years 2025-01-05 19:37:56 +03:00
Antony Polukhin 35a71f0701 Prefer "using" over "typedef" 2024-12-17 16:37:40 +03:00
René Ferdinand Rivera Morell 8a860e05d0 Add support for modular build structure. (#29)
This is part of the effort to make the Boost libraries "modular" for build and consumption. See https://lists.boost.org/Archives/boost/2024/01/255704.php and https://github.com/grafikrobot/boost-b2-modular/blob/b2-modular/README.adoc for more information.

This PR depends on the following other PRs being merged to both develop and master branches of the respective repos:

- https://github.com/boostorg/boost/pull/854

This PR will be changed to ready for review, i.e. not draft, when the above are merged. Do not merge this one until that time.
2024-08-24 12:37:14 +03:00
Danil Sidoruk 9f285ef0c4 Remove mentions of lexical_cast in docs (#28)
lexical_cast isn't a part of Boost.Conversion, it's part of Boost.Lexical_Cast
2024-01-21 14:13:03 +03:00
Antony Polukhin 5f36c2c710 Update tests requirements 2024-01-21 14:08:52 +03:00
Antony Polukhin 41e62ed851 Update copyright years 2024-01-07 13:20:12 +03:00
Antony Polukhin 5cf5f78376 Restore Boost::smart_ptr dependency in CMakeLists 2023-08-27 13:28:45 +03:00
Antony Polukhin 5a3587c988 simplify code 2023-08-26 21:45:41 +03:00
Antony Polukhin f7f3c9b5ce Merge branch 'drop-cpp03' into develop 2023-08-25 15:00:40 +03:00
Antony Polukhin 668030fcd6 Remove hard error about C++11 requirement and update CI 2023-08-25 14:59:53 +03:00
Mohammad Nejati 0d60a3f7ce Use relative URL for redirect in index.html (#26) 2023-08-12 10:53:42 +03:00
Antony Polukhin 0ff5adc258 Merge pull request #27 from boostorg/drop-cpp03
Drop c++03 support
2023-08-12 10:45:01 +03:00
Antony Polukhin 2598281d10 drop c++03 support 2023-08-10 18:52:03 +03:00
Antony Polukhin a1104f580c update CI setup 2023-05-21 09:42:12 +03:00
Antony Polukhin 9a03296816 add C++03 deprecation warnings 2023-05-14 19:49:21 +03:00
Antony Polukhin 7ba0984b34 Update copyright years 2023-01-19 10:01:52 +03:00
Antony Polukhin 4ae8b4d495 update copyright years 2022-01-30 12:52:42 +03:00
Antony Polukhin 71b6a864a4 do not use depth 1 for checkouts in CI 2021-09-20 21:46:36 +03:00
Antony Polukhin b2a49138cf Fix appveyor CI checks for MSVC 2021-09-11 12:29:42 +03:00
Antony Polukhin 00f06d3549 Update appveyor CI badge link 2021-09-11 12:08:35 +03:00
Antony Polukhin 968dfd47f1 remove clang-9 from test matrix 2021-09-10 20:39:56 +03:00
Antony Polukhin f0fe02f7d6 use builtin rules for toolsets 2021-09-10 20:32:09 +03:00
Antony Polukhin 19b5a1cf29 remove ubuntu-16.04 matrix entries in CI 2021-09-10 20:25:17 +03:00
Peter Dimov 1a2e4fd8ef Update CMakeLists.txt 2021-06-10 01:17:02 +03:00
Antony Polukhin 8d1721f312 use HTTPS links in Readme 2021-04-27 10:07:49 +03:00
Antony Polukhin c6ab56e983 memory sanitizer is triggered by libstdc++, so disable it 2021-04-25 21:17:35 +03:00
Antony Polukhin 1c62347706 use more sanitizers 2021-04-25 20:32:49 +03:00
Antony Polukhin 56becb8fee update of the Github Actions to the latest version 2021-04-24 19:13:17 +03:00
Antony Polukhin 67ae26b0f0 update Readme links [skip ci] 2021-04-22 11:25:59 +03:00
Antony Polukhin d4e593120d update CI: depinst.py the Boost.Filesystem before copying the library content 2021-04-21 21:06:41 +03:00
Antony Polukhin 76ed70b0b1 update CI: overwrite the target dir 2021-04-21 20:59:46 +03:00
Antony Polukhin 4b7d551907 remove drone CI in favour of default github actions from CppAlliance 2021-04-21 20:53:38 +03:00
Antony Polukhin 9e3216d22f make boost::implicit_cast constexpr (fixes #25) 2021-04-21 20:51:14 +03:00
Antony Polukhin 4e557d31d1 fix broken links (fixes #23) 2021-04-21 20:50:26 +03:00
Antony Polukhin 46695ffb86 update CI: use workflow from boost.Any 2021-04-21 20:47:14 +03:00
Antony Polukhin c1c098fac1 update CI (5): update readme links 2021-04-18 21:20:23 +03:00
Antony Polukhin b171fe1ff6 update CI (4): more fixes for coverage 2021-04-18 20:14:15 +03:00
Antony Polukhin a178d1a691 update CI (3): fixes for coverage 2021-04-18 20:05:00 +03:00
Antony Polukhin 5176e189b8 update CI (2): inspect tool options 2021-04-18 19:50:46 +03:00
Antony Polukhin 49e6421271 update CI (1): simplify and decompose ci.yaml 2021-04-18 19:42:45 +03:00
Antony Polukhin a0bfc39077 Merge pull request #24 from sdarwin/githubactions
GitHub Actions config
2021-04-18 14:11:15 +03:00
sdarwin 2bf2bba4be Add GitHub Actions config [ci skip] 2021-03-04 18:22:48 +00:00
Antony Polukhin f882ab890d Merge pull request #21 from sdarwin/drone
Drone config
2021-01-27 10:28:28 +03:00
sdarwin e0bb75e096 add drone config [ci skip] 2021-01-26 15:29:35 +00:00
Antony Polukhin 80b9240f2e Merge pull request #20 from eldiener/develop
[skip ci] Add "cxxstd" json field
2021-01-20 10:34:58 +03:00
Edward Diener df86cb59c4 [skip ci] Add "cxxstd" json field. The "cxxstd" json field is being added to each Boost library's meta json information for libraries in order to specify the minumum C++ standard compilation level. The value of this field matches one of the values for 'cxxstd' in Boost.Build. The purpose of doing this is to provide information for the Boost website documentation for each library which will specify the minimum C++ standard compilation that an end-user must employ in order to use the particular library. This will aid end-users who want to know if they can successfully use a Boost library based on their C++ compiler's compilation level, without having to search the library's documentation to find this out. 2021-01-19 12:48:45 -05:00
Antony Polukhin 4fec53f3db update copyright years 2021-01-03 13:57:41 +03:00
Antony Polukhin db398fc1c8 Merge pull request #19 from sdarwin/lcov
update lcov in .travis.yml
2021-01-02 17:06:49 +03:00
sdarwin 1576ff7be6 update lcov in .travis.yml 2020-12-24 15:50:18 +00:00
Antony Polukhin 9540be42b4 CI fixes (3) 2020-07-06 10:34:54 +03:00
Antony Polukhin 7624b70a6d index.html update 2020-07-06 10:15:07 +03:00
Antony Polukhin 78fc22c66a CI fixes (2) 2020-07-06 10:13:52 +03:00
Antony Polukhin f1d5059c75 fix broken link 2020-07-05 23:24:00 +03:00
Antony Polukhin f2e83915c3 CI fixes (1) 2020-07-05 19:30:18 +03:00
Antony Polukhin e0a40b7067 CI fixes 2020-07-05 19:27:05 +03:00
Antony Polukhin 1dd1c98b79 Merge pull request #18 from Mike-Devel/patch-1
[CMake] Add boost core to dependency list
2020-05-02 07:51:37 +03:00
Mike-Devel a1788bc31b [CMake] Add boost core to dependency list
Used in  boost/polymorphic_cast.hpp
2020-04-29 11:52:40 +02:00
Antony Polukhin 58c33270a2 Use boost::addressof and update docs 2020-01-25 10:59:32 +03:00
Julien DELACROIX e130cd860c boost::polymorphic_downcast only supports raw pointer cast, which is a gap compared to static_cast.
To make it clear:
       Base* base = new Base();

       static_cast<Derived*>(base)                 ===> OK
       static_cast<Derived&>(*base)                ===> OK

       boost::polymorphic_downcast<Derived*>(base)  ===> OK
       boost::polymorphic_downcast<Derived&>(*base) ===> IMPOSSIBLE

    boost::polymorphic_downcast being a kind of "debug-safe version" of
    static_cast, it should provide the same capabilities.

    This patch extend boost::polymorphic_downcast to support references just
    like static_cast does.
    This is achieved by introducing a partial specialization for references.
    Unit tests have been updated accordingly.
2019-12-09 08:51:10 +01:00
Antony Polukhin 9d4a518e74 CI fix (2) 2019-06-29 11:28:49 +03:00
Antony Polukhin 1525157560 CI fix 2019-06-29 11:06:42 +03:00
Antony Polukhin 3421136ef0 test on clang-7 instead of clang-5.0 2019-06-29 10:59:47 +03:00
Antony Polukhin 441d4e4e1b Update appveyor.yml 2019-04-24 22:10:38 +03:00
Antony Polukhin b3f8e9f014 Merge pull request #16 from Mike-Devel/min_cmake
[CMake] Add minimal cmake support
2019-03-03 21:54:59 +03:00
Mike-Devel 24f2769eb7 [CMake] Use PascalCase in project name 2019-03-03 10:11:11 +01:00
Mike Dev 6806d99529 [CMake] Add minimal cmake support
- CMake file only supports add_subdirectory workflow.
- Provides target Boost::conversion, but doesn't support
  installation or running unit tests.
2019-03-03 09:38:35 +01:00
Antony Polukhin e38c0753ef update copyright years 2019-01-30 23:13:06 +03:00
Antony Polukhin 6b3395e57d Merge pull request #15 from apolukhin/feature/ci-update
CI update: Test on Cygwin, Clang and many other platforms
2018-12-15 00:40:42 +03:00
Antony Polukhin 83e57ed513 Do not run CI tests without RTTI 2018-12-14 12:28:02 +03:00
Antony Polukhin 56393150bb update ci 2018-12-14 11:53:39 +03:00
Antony Polukhin e8d104f34d Merge pull request #14 from gsauthof/verbatim
Add some missing verbatim markers
2018-10-16 22:31:35 +03:00
Georg Sauthoff a770ff87d7 Add some missing verbatim markers
i.e. completed one unbalanced and the rest for some non-verbatim
identifiers.
2018-10-16 21:22:10 +02:00
Antony Polukhin 29997a9fe1 Fix warning
`warning: catching polymorphic type ???class std::bad_cast??? by value`
2018-10-03 20:33:30 +03:00
Antony Polukhin 2a0a2a59f5 Fixed formatting in README and updated the AppveyorCI script 2017-05-20 10:42:53 +03:00
Antony Polukhin 51d544e6b8 Merge pull request #13 from boostorg/danieljames-patch-3
Change the path of the quickbook documentation
2017-03-26 13:09:03 +03:00
Daniel James ee92f4f98b Change the path of the quickbook documentation
The html path is determined by the quickbook id.
2017-03-25 21:50:29 +00:00
Antony Polukhin d46e12c921 Attempt to fix the docs build and redirects 2017-03-25 22:44:56 +03:00
Antony Polukhin 2648b144be Merge pull request #11 from boostorg/danieljames-patch-1
Try to fix the documentation build
2017-03-25 09:31:51 +03:00
Daniel James 32130aa427 Try to fix the documentation build
I think boostdoc is depending on the wrong target. Not sure if this will work, but worth a go?
2017-03-24 09:23:59 +00:00
Antony Polukhin c704762482 Run MinGW tests too (thanks to Pavel Filinov for showing that appveyor apability) 2017-02-23 21:21:50 +03:00
Rene Rivera ae1f2a5cd1 Fix doc build.
The doc building alias reference did not get updated for changed target. This puts in the correct name.
2016-12-27 13:24:04 -06:00
Antony Polukhin 993685b7d0 Merge pull request #10 from very-cool-name/quickbook_doc
Moved documentation from html to Boost Quickbook.
2016-12-26 23:30:40 +04:00
Mike Maximoff eafe2d352e Fixed title to Conversion. 2016-12-25 23:00:40 +03:00
Mike Maximoff 3b9769567e Fixed aliases and copyrights. Created new index.html with redirect only. 2016-12-24 23:13:01 +03:00
Mike Maximoff 610f9fe674 Moved documentation from html to Boost Quickbook. 2016-12-21 23:16:10 +03:00
Antony Polukhin cbe18465d7 Merge pull request #9 from very-cool-name/gcc6_fix
boost::assertion_failed trapped assertions, and subsequent bad casts …
2016-12-17 12:45:02 +04:00
Mike Maximoff 181eb0e6fc boost::assertion_failed trapped assertions, and subsequent bad casts were executed anyway. Now it throws exceptions for assert-like behavior. 2016-12-16 10:46:37 +03:00
Antony Polukhin 46694fb293 Update CI script version 2016-12-04 02:38:30 +03:00
Antony Polukhin 4d814efd3f Update CI scripts, add appveyor CI 2016-12-04 02:35:42 +03:00
Antony Polukhin da8b2fe695 Fix file permissions 2015-12-30 00:08:28 +03:00
Antony Polukhin a7b9f42b9a Use lightweight_test.hpp instead of asserts in tests 2015-12-30 00:07:48 +03:00
Antony Polukhin b6e9403ef0 Fixed warnings in tests 2015-12-14 19:14:28 +03:00
Antony Polukhin 58e8e78899 Run TravisCI tests using valgrind 2015-10-17 17:05:23 +03:00
Antony Polukhin 8f4b6ec985 Fixed issue from track Ticket #11209: conversion - cast_test leaks memory 2015-09-25 19:58:48 +03:00
Antony Polukhin a6100358f4 Add missing include 2015-03-24 22:24:08 +03:00
Antony Polukhin 8f1126f6b2 Merge branch 'alexhenrie-master' into develop 2015-02-03 20:11:03 +03:00
Antony Polukhin b2019fa2df Added a README.md and improved some docs. Added TravicCI integration 2015-02-03 13:28:04 +03:00
Antony Polukhin dc25edb4dd Fixed type deduction on old compilers 2015-02-03 13:00:37 +03:00
Alex Henrie 43ee183296 Correct spelling of "suppress" 2015-01-30 15:22:27 -07:00
Antony Polukhin 84ab59227d Merge pull request #7 from Boris-Rasin/synopsis
fix synopsis for polymorphic_pointer_cast
2014-11-18 19:58:36 +03:00
Boris Rasin 0dc31621c8 fix synopsis for polymorphic_pointer_cast 2014-11-18 14:31:22 +02:00
Antony Polukhin 00b6a53f7e Add polymorphic_pointer_cast 2014-11-10 15:02:20 +04:00
Antony Polukhin 6199649ae2 Move polymorphic_pointer_downcast to a separate header, use pragma once and boost::throw_exception 2014-11-10 14:24:39 +04:00
Antony Polukhin a8253878c8 Merge pull request #6 from Boris-Rasin/polymorphic_pointer_downcast
Add polymorphic_pointer_downcast function template (pull request #2)

Looks really good.
I'll move your implementation into a separate polymorphic_pointer_cast.hpp header to avoid Typeof dependencies for users that do not use `polymorphic_pointer_downcast`
2014-11-10 12:15:34 +03:00
Boris Rasin 582fc91adb add more tests and documentation example for polymorphic_pointer_downcast 2014-11-09 15:37:56 +02:00
Boris Rasin 6a224fa5e9 =add polymorphic_pointer_downcast function template 2014-11-09 00:02:44 +02:00
Antony Polukhin 5d66fea7d5 Merge branch 'master' into develop 2014-08-11 13:19:35 +04:00
Antony Polukhin 4e9021cac5 Merge branch 'develop' 2014-06-16 09:19:29 +04:00
Antony Polukhin ff7ea09a73 remove numeric_cast_test that is a copy of numeric/conversion/test/numeric_cast_test.cpp 2014-06-11 16:23:51 +04:00
Antony Polukhin 6943537150 Drop dependency to the boost_unit_test_framework library in tests 2014-06-11 16:16:40 +04:00
Antony Polukhin cf31a2ec00 Merge pull request #4 from boostorg/pull-request/cast-prune-dependencies
Prune conversion dependencies
2014-06-11 16:03:39 +04:00
Peter Dimov 800c10a4eb Remove use of mpl::identity from implicit_cast.hpp. 2014-06-11 14:45:37 +03:00
Peter Dimov df57f25807 Remove unnecessary includes from cast_test.cpp. 2014-06-11 14:41:55 +03:00
Peter Dimov f0caf56d0b Remove unnecessary includes from implicit_cast_fail.cpp. 2014-06-11 14:40:50 +03:00
Peter Dimov 24d6ac1e87 Remove unnecessary includes from polymorphic_cast.hpp. 2014-06-11 14:38:48 +03:00
Peter Dimov 8a03282736 Add additional tests. 2014-06-11 14:35:27 +03:00
Antony Polukhin 40c42eb740 cast.hpp was moved to the numeric_cast library 2014-06-11 11:44:02 +04:00
Antony Polukhin 36945c35bd Merge branch 'develop' 2014-06-10 13:37:08 +04:00
Antony Polukhin a0922ab598 Remove lexical_cast, add polymorphic_cast.hpp, minor fixes 2014-06-09 12:36:42 +04:00
Antony Polukhin 77a4a55af4 Merge pull request #3 from danieljames/metadata
Add metadata
2014-06-09 11:50:37 +04:00
Antony Polukhin 5c3878f015 Merge pull request #2 from danieljames/link-fix
Fix link to test.
2014-06-09 11:50:19 +04:00
Daniel James 5e93f4086c Remove mention of lexical casts. 2014-06-08 23:42:45 +01:00
Daniel James e2a68fdec1 Add metadata from website 2014-06-08 23:42:19 +01:00
Daniel James ee91295ac4 Fix link to test. 2014-06-08 15:01:02 +01:00
Antony Polukhin e3e4d3836a Merge branch 'develop' 2014-03-14 23:47:58 +04:00
Antony Polukhin d1a51b897d Fix conversions to bool with leading zeros (refs #9659) 2014-03-05 14:48:21 +04:00
Antony Polukhin 9e6aa219d3 Merge branch 'develop' 2014-03-04 16:37:10 +04:00
Antony Polukhin 1e65265b8f Minor fixes in tests 2014-02-11 12:13:17 +04:00
Antony Polukhin 90b4286753 Because of the errors in MSVC with fowarding and static_casting arrays it was decided to drop minor optimization and do not perfect forward source types in try_lexical_convert 2014-02-06 11:22:40 +04:00
Antony Polukhin 5a757dcece Docs updated and minor fixes for MSVC2013 2014-02-04 13:13:33 +04:00
Antony Polukhin 36bc5aea44 Attempt to fix access violation during forwarding of arrays on MSVC 2014-02-03 16:22:27 +04:00
Antony Polukhin ac7da550b4 Attempt to revert incorrectly merged branches 2014-01-19 11:53:50 +04:00
Antony Polukhin e8954f3868 Added docs for try_lexical_convert 2014-01-04 20:26:19 +04:00
Antony Polukhin 1707131ac3 Added some tests for try_lexical_convert and fixed some issues. 2014-01-01 21:47:09 +04:00
Antony Polukhin 2f2c1a3443 Create first merge point for Git 2013-12-30 18:03:42 +04:00
Antony Polukhin 91b77e7373 Do forward input streamable parameter during lexical input streaming. 2013-12-16 19:05:43 +04:00
Antony Polukhin e3dec04dd5 Applied improvements from [boost] [conversion] try_lexical_cast discussion: function is called try_lexical_convert and now uses perfect forwardings when possible. 2013-12-16 18:47:41 +04:00
Antony Polukhin b40bc02f94 try_lexical_cast is now implemented in optimal way 2013-12-13 13:52:18 +04:00
Antony Polukhin 07082420b3 Sketch implementaion of try_lexical_cast 2013-12-12 18:41:51 +04:00
Antony Polukhin 57e4e87e3b Put tests to test folder, remove unrequired files, fix permissions 2013-12-09 11:27:27 +04:00
Antony Polukhin e913b7cb1c Fix some of the implicit conversion warnings (refs #8991)
[SVN r86750]
2013-11-18 11:06:06 +00:00
Antony Polukhin c0c02e560e Attempt to catch libc++ bug with a modified tests
[SVN r86747]
2013-11-18 08:17:33 +00:00
Antony Polukhin bbd746d2ac Slightly modify one of the lexical_cast tests to see what is produced by the to_str method with libc++.
[SVN r86721]
2013-11-16 16:25:26 +00:00
Antony Polukhin bf75439403 Merged a big bunch of internal code changes from trunk for lexical_cast:
dropped support of antique compilers, code changed to produce a smaller binaries and simplify compiler's work, simplified and shortened the code, common with other libraries code moved to 'detail/basic_pointerbuf.hpp' (fixes #9046, fixes #9070, fixes #9271)

[SVN r86654]
2013-11-12 17:15:12 +00:00
Antony Polukhin edde5f442e Another attempt to suppress MSVC warnings (refs #9271)
[SVN r86388]
2013-10-22 09:07:02 +00:00
Antony Polukhin d78d334dbb Add missing #pragma wraning(push) (refs #9271)
[SVN r86378]
2013-10-21 09:21:35 +00:00
Antony Polukhin 39d1abe754 Suppress some of the Level 4 MSVC warnings in the basic_pointerbuf.hpp (refs #9271)
[SVN r86377]
2013-10-21 06:46:01 +00:00
Antony Polukhin 524232ebab Supressing MSVC2013 warnings and ensuring that lexical cast io classes are not copied (refs #9271)
[SVN r86374]
2013-10-20 17:57:15 +00:00
Stephen Kelly 472ebeff30 Simplify multi-component ifdefs containing BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
[SVN r86248]
2013-10-11 23:20:59 +00:00
Stephen Kelly 13f14db751 lexical_cast: Remove obsolete GCC version check.
[SVN r86113]
2013-10-01 08:47:00 +00:00
Stephen Kelly 8a49514506 cast: Remove obsolete MSVC version check.
[SVN r86026]
2013-09-30 00:18:40 +00:00
Stephen Kelly c8bd860de6 Remove obsolete MSVC check from pragma guard
git grep -h -B1 "^#\s*pragma once" | grep -v pragma | sort | uniq

is now clean.

[SVN r85952]
2013-09-26 13:02:51 +00:00
55 changed files with 1260 additions and 9399 deletions
+11
View File
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
+182
View File
@@ -0,0 +1,182 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- feature/**
env:
UBSAN_OPTIONS: print_stacktrace=1
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-14 # Do not remove! It is the only toolset that tests CMake tests down below
cxxstd: "03,11,14,17,20"
os: ubuntu-24.04
- toolset: gcc-12
cxxstd: "03,11,14,17,2a"
os: ubuntu-22.04
cxxflags: "cxxflags=--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined"
linkflags: "linkflags=--coverage -lasan -lubsan"
gcov_tool: "gcov-12"
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,2a"
os: ubuntu-22.04
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v6
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 10 https://github.com/boostorg/boost.git boost-root
cd boost-root
git submodule update --init --depth 10 --jobs 2 tools/boostdep tools/inspect libs/filesystem
python tools/boostdep/depinst/depinst.py --git_args "--depth 10 --jobs 3" filesystem
rm -rf libs/$LIBRARY/*
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--depth 10 --jobs 3" $LIBRARY
./bootstrap.sh
./b2 -j4 variant=debug tools/inspect
- name: Run CMake tests
if: ${{matrix.toolset == 'gcc-14'}}
run: |
cd ../boost-root/
mkdir __build
cd __build
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=conversion -DCMAKE_CXX_COMPILER=g++-14 -DCMAKE_C_COMPILER=gcc-14 ..
cmake --build . --target tests
ctest --output-on-failure --no-tests=error
cd ..
rm -rf __build
- name: Run tests
run: |
cd ../boost-root
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} variant=debug,release "${{matrix.cxxflags}}" "${{matrix.linkflags}}" "${{matrix.launcher}}"
dist/bin/inspect libs/$LIBRARY
- name: Prepare coverage data
if: matrix.gcov_tool
run: |
mkdir -p $GITHUB_WORKSPACE/coveralls
echo -e "#!/bin/bash\nexec ${{matrix.gcov_tool}} \"\$@\"" > $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh
chmod +x $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh
wget https://github.com/linux-test-project/lcov/archive/v1.16.zip
unzip v1.16.zip
LCOV="`pwd`/lcov-1.16/bin/lcov --gcov-tool $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh"
echo "$LCOV --directory ../boost-root/bin.v2/libs/$LIBRARY/ --base-directory `pwd`/libs/$LIBRARY/test --capture --output-file $GITHUB_WORKSPACE/coveralls/coverage.info"
$LCOV --directory ../boost-root/bin.v2/libs/$LIBRARY/ --base-directory ../boost-root/ --capture --output-file $GITHUB_WORKSPACE/coveralls/coverage.info
$LCOV --remove $GITHUB_WORKSPACE/coveralls/coverage.info "/usr*" "*/$LIBRARY/test/*" ${{matrix.ignore_coverage}} "*/$LIBRARY/tests/*" "*/$LIBRARY/examples/*" "*/$LIBRARY/example/*" -o $GITHUB_WORKSPACE/coveralls/coverage.info
cd ../boost-root
OTHER_LIBS=`grep "submodule .*" .gitmodules | sed 's/\[submodule\ "\(.*\)"\]/"\*\/boost\/\1\.hpp" "\*\/boost\/\1\/\*"/g'| sed "/\"\*\/boost\/$LIBRARY\/\*\"/d" | sed ':a;N;$!ba;s/\n/ /g'`
echo $OTHER_LIBS
eval "$LCOV --remove $GITHUB_WORKSPACE/coveralls/coverage.info $OTHER_LIBS -o $GITHUB_WORKSPACE/coveralls/coverage.info"
- name: Coveralls
uses: coverallsapp/github-action@master
if: matrix.gcov_tool
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coveralls/coverage.info
parallel: true
windows:
strategy:
fail-fast: false
matrix:
include:
- toolset: msvc-14.3
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2025
- toolset: gcc
cxxstd: "03,11,14,17,2a"
addrmd: 64
os: windows-2025
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v6
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 10 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--jobs 3" %LIBRARY%
cmd /c bootstrap
- name: Run CMake tests
if: ${{matrix.toolset == 'msvc-14.3'}}
shell: cmd
run: |
choco install --no-progress ninja
call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64
cd ../boost-root/
mkdir __build
cd __build
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=conversion ..
cmake --build . --target tests --config Debug
ctest --output-on-failure --no-tests=error -C Debug
cd ..
rm -rf __build
- name: Run tests
shell: cmd
run: |
cd ../boost-root
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release
finish:
needs: posix
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
+22
View File
@@ -0,0 +1,22 @@
# Copyright 2019 Mike Dev
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required( VERSION 3.5...4.20 )
project( boost_conversion VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX )
add_library( boost_conversion INTERFACE )
add_library( Boost::conversion ALIAS boost_conversion )
target_include_directories( boost_conversion INTERFACE include )
target_link_libraries( boost_conversion
INTERFACE
Boost::assert
Boost::config
Boost::throw_exception
)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
+15
View File
@@ -0,0 +1,15 @@
# [Boost.Conversion](https://boost.org/libs/conversion)
Boost.Conversion is one of the [Boost C++ Libraries](https://github.com/boostorg). This library improves program safety and clarity by performing otherwise messy conversions.
### Test results
@ | Build | Tests coverage | More info
----------------|-------------- | -------------- |-----------
Develop branch: | [![CI](https://github.com/boostorg/conversion/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/conversion/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/1cky1hrunfa46bdx/branch/develop?svg=true)](https://ci.appveyor.com/project/apolukhin/conversion/branch/develop) | [![Coverage Status](https://coveralls.io/repos/github/boostorg/conversion/badge.svg?branch=develop)](https://coveralls.io/github/boostorg/conversion?branch=develop) | [details...](https://regression.boost.io/develop/developer/conversion.html)
Master branch: | [![CI](https://github.com/boostorg/conversion/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/conversion/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/1cky1hrunfa46bdx/branch/master?svg=true)](https://ci.appveyor.com/project/apolukhin/conversion/branch/master) | [![Coverage Status](https://coveralls.io/repos/github/boostorg/conversion/badge.svg?branch=master)](https://coveralls.io/github/boostorg/conversion?branch=master) | [details...](https://regression.boost.io/master/developer/conversion.html)
[Latest developer documentation](https://www.boost.org/doc/libs/develop/doc/html/conversion.html)
### License
Distributed under the [Boost Software License, Version 1.0](https://boost.org/LICENSE_1_0.txt).
+25
View File
@@ -0,0 +1,25 @@
# Copyright René Ferdinand Rivera Morell 2023-2024
# 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)
require-b2 5.2 ;
constant boost_dependencies :
/boost/assert//boost_assert
/boost/config//boost_config
/boost/throw_exception//boost_throw_exception ;
project /boost/conversion
: common-requirements
<include>include
;
explicit
[ alias boost_conversion : : : : <library>$(boost_dependencies) ]
[ alias all : boost_conversion test ]
;
call-if : boost-library conversion
;
-146
View File
@@ -1,146 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"Microsoft FrontPage 5.0">
<meta http-equiv="Content-Type" content=
"text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<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">
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align=
"middle" width="277" height="86">Header <a href=
"../../boost/cast.hpp">boost/cast.hpp</a></h1>
<h2><a name="Cast Functions">Cast Functions</a></h2>
<p>The header <a href="../../boost/cast.hpp">boost/cast.hpp</a> provides <code>
<a href="#Polymorphic_cast">polymorphic_cast</a> and</code> <a href=
"#Polymorphic_cast"><code>polymorphic_downcast</code></a> function templates designed to
complement the C++ built-in casts.</p>
<p>The program <a href="cast_test.cpp">cast_test.cpp</a> can be used to
verify these function templates work as expected.</p>
<h3><a name="Polymorphic_cast">Polymorphic casts</a></h3>
<p>Pointers to polymorphic objects (objects of classes which define at
least one virtual function) are sometimes downcast or crosscast.
Downcasting means casting from a base class to a derived class.
Crosscasting means casting across an inheritance hierarchy diagram, such
as from one base to the other in a <code>Y</code> diagram hierarchy.</p>
<p>Such casts can be done with old-style casts, but this approach is
never to be recommended. Old-style casts are sorely lacking in type
safety, suffer poor readability, and are difficult to locate with search
tools.</p>
<p>The C++ built-in <code>static_cast</code> can be used for efficiently
downcasting pointers to polymorphic objects, but provides no error
detection for the case where the pointer being cast actually points to
the wrong derived class. The <code>polymorphic_downcast</code> template retains
the efficiency of <code>static_cast</code> for non-debug compilations, but for
debug compilations adds safety via an assert() that a <code>dynamic_cast</code>
succeeds.</p>
<p>The C++ built-in <code>dynamic_cast</code> can be used for downcasts and
crosscasts of pointers to polymorphic objects, but error notification in
the form of a returned value of 0 is inconvenient to test, or worse yet,
easy to forget to test. The throwing form of <code>dynamic_cast</code>, which
works on references, can be used on pointers through the ugly expression
&amp;<code>dynamic_cast&lt;T&amp;&gt;(*p)</code>, which causes undefined
behavior if <code>p</code> is <code>0</code>. The <code>polymorphic_cast</code>
template performs a <code>dynamic_cast</code> on a pointer, and throws an
exception if the <code>dynamic_cast</code> returns 0.</p>
<p>A <code>polymorphic_downcast</code> should be used for
downcasts that you are certain should succeed. Error checking is
only performed in translation units where <code>NDEBUG</code> is
not defined, via
<pre> assert( dynamic_cast&lt;Derived&gt;(x) == x )
</pre> where <code>x</code> is the source pointer. This approach
ensures that not only is a non-zero pointer returned, but also
that it is correct in the presence of multiple inheritance.
Attempts to crosscast using <code>polymorphic_downcast</code> will
fail to compile.
<b>Warning:</b> Because <code>polymorphic_downcast</code> uses assert(), it
violates the One Definition Rule (ODR) if NDEBUG is inconsistently
defined across translation units. [See ISO Std 3.2]
</p><p>
For crosscasts, or when the success of a cast can only be known at
runtime, or when efficiency is not important,
<code>polymorphic_cast</code> is preferred. </p>
<p>The C++ built-in <code>dynamic_cast</code> must be used to cast references
rather than pointers. It is also the only cast that can be used to check
whether a given interface is supported; in that case a return of 0 isn't
an error condition.</p>
<h3>polymorphic_cast and polymorphic_downcast synopsis</h3>
<blockquote>
<pre>namespace boost {
template &lt;class Derived, class Base&gt;
inline Derived polymorphic_cast(Base* x);
// Throws: std::bad_cast if ( dynamic_cast&lt;Derived&gt;(x) == 0 )
// Returns: dynamic_cast&lt;Derived&gt;(x)
template &lt;class Derived, class Base&gt;
inline Derived polymorphic_downcast(Base* x);
// Effects: assert( dynamic_cast&lt;Derived&gt;(x) == x );
// Returns: static_cast&lt;Derived&gt;(x)
}
</pre>
</blockquote>
<h3>polymorphic_downcast example</h3>
<blockquote>
<pre>#include &lt;boost/cast.hpp&gt;
...
class Fruit { public: virtual ~Fruit(){}; ... };
class Banana : public Fruit { ... };
...
void f( Fruit * fruit ) {
// ... logic which leads us to believe it is a Banana
Banana * banana = boost::polymorphic_downcast&lt;Banana*&gt;(fruit);
...
</pre>
</blockquote>
<h3>History</h3>
<p><code>polymorphic_cast</code> was suggested by Bjarne Stroustrup in "The C++
Programming Language".<br>
<code>polymorphic_downcast</code> was contributed by <a href=
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>.<code><br>
An old
numeric_cast</code> that was contributed by <a href=
"http://www.boost.org/people/kevlin_henney.htm">Kevlin Henney</a> is now superseeded by the <a href="../numeric/conversion/doc/html/index.html">Boost Numeric Conversion Library</a></p>
<hr>
<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">&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>
+30 -8
View File
@@ -1,16 +1,38 @@
# Copyright Antony Polukhin 2011. Use, modification, and distribution are
# subject to 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)
# Copyright (c) 2016 Mikhail Maximov <vigorous.activity -at- gmail.com>
# 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)
project doc/conversion ;
using quickbook ;
import boostbook : boostbook ;
import boostbook ;
xml lexical_cast : lexical_cast.qbk ;
xml conversion : conversion.qbk ;
boostbook standalone
:
lexical_cast
conversion
:
<xsl:param>boost.root=../../../..
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
;
# File name of HTML output:
<xsl:param>root.filename=conversion
# How far down we chunk nested sections, basically all of them:
<xsl:param>chunk.section.depth=0
# Don't put the first section on the same page as the TOC:
<xsl:param>chunk.first.sections=0
# How far down sections get TOC's
<xsl:param>toc.section.depth=2
# Max depth in each TOC:
<xsl:param>toc.max.depth=2
# How far down we go with TOC's
<xsl:param>generate.section.toc.level=0
<xsl:param>generate.manifest=0
;
###############################################################################
alias boostdoc : conversion ;
explicit boostdoc ;
alias boostrelease ;
explicit boostrelease ;
+215
View File
@@ -0,0 +1,215 @@
[/
Copyright 2016 Mikhail Maximov.
Copyright Antony Polukhin, 2020-2026.
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>)
]
[article The Conversion Library
[quickbook 1.6]
[compatibility-mode 1.5]
[id conversion]
[version 1.7]
[authors [Stroustrup, Bjarne], [Abrahams, Dave], [Rasin, Boris], [Polukhin, Antony]]
[copyright 2001 Beman Dawes, 2014-2026 Antony Polukhin]
[license
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])
]
[source-mode c++]
]
[/ QuickBook Document version 1.5 ]
[/ Dec, 2016 ]
[section Description]
The Conversion Library improves program safety and clarity by performing
otherwise messy conversions. It includes cast-style function templates designed
to complement the C++ Standard's built-in casts.
To reduce coupling, the Boost Conversion Library is supplied by several headers:
# The [@boost:boost/polymorphic_cast.hpp boost/polymorphic_cast.hpp] header
provides [link polymorphic_cast `polymorphic_cast<>`] and
[link polymorphic_downcast `polymorphic_downcast<>`]
to perform safe casting between polymorphic types.
# The [@boost:boost/polymorphic_pointer_cast.hpp boost/polymorphic_pointer_cast.hpp] header
provides [link polymorphic_pointer_cast `polymorphic_pointer_cast<>`] and
[link polymorphic_pointer_cast `polymorphic_pointer_downcast<>`]
# The [@boost:boost/implicit_cast.hpp boost/implicit_cast.hpp] header provides `implicit_cast<>`
to perform implicit casts only (no down-cast, no void*->T*, no U->T if T has only explicit constructors for U).
[endsect]
[section Polymorphic casts]
Pointers to polymorphic objects (objects of classes which define at
least one virtual function) are sometimes downcast or crosscast.
Downcasting means casting from a base class to a derived class.
Crosscasting means casting across an inheritance hierarchy diagram, such
as from one base to the other in a [^Y] diagram hierarchy.
Such casts can be done with old-style casts, but this approach is
never to be recommended. Old-style casts are sorely lacking in type
safety, suffer poor readability, and are difficult to locate with search
tools.
[#polymorphic_downcast]
[section polymorphic_downcast]
The C++ built-in `static_cast` can be used for efficiently
downcasting pointers to polymorphic objects, but provides no error
detection for the case where the pointer being cast actually points to
the wrong derived class. The `polymorphic_downcast` template retains
the efficiency of `static_cast` for non-debug compilations, but for
debug compilations adds safety via an `assert()` that a `dynamic_cast`
succeeds.
A `polymorphic_downcast` should be used for
downcasts that you are certain should succeed. Error checking is
only performed in translation units where `NDEBUG` is
not defined, via
```
assert( dynamic_cast<Derived>(x) == x )
```
where `x` is the source pointer. This approach
ensures that not only is a non-zero pointer returned, but also
that it is correct in the presence of multiple inheritance.
Attempts to crosscast using `polymorphic_downcast` will
fail to compile.
[warning Because `polymorphic_downcast` uses `assert()`, it
violates the One Definition Rule (ODR) if `NDEBUG` is inconsistently
defined across translation units. See ISO Std 3.2]
[h4 Example:]
```
#include <boost/polymorphic_cast.hpp>
...
class Fruit { public: virtual ~Fruit(){}; ... };
class Banana : public Fruit { ... };
...
void f( Fruit * fruit ) {
// ... logic which leads us to believe it is a Banana
Banana * banana = boost::polymorphic_downcast<Banana*>(fruit);
...
}
```
[endsect]
[#polymorphic_cast]
[section polymorphic_cast]
The C++ built-in `dynamic_cast` can be used for downcasts and
crosscasts of pointers to polymorphic objects, but error notification in
the form of a returned value of 0 is inconvenient to test, or worse yet,
easy to forget to test. The throwing form of `dynamic_cast`, which
works on references, can be used on pointers through the ugly expression
`&dynamic_cast<T&>(*p)`, which causes undefined
behavior if `p` is `0`. The `polymorphic_cast`
template performs a `dynamic_cast` on a pointer, and throws an
exception if the `dynamic_cast` returns 0.
For crosscasts, or when the success of a cast can only be known at runtime,
or when efficiency is not important, `polymorphic_cast` is preferred.
The C++ built-in `dynamic_cast` must be used to cast references rather than pointers.
It is also the only cast that can be used to check whether a given interface is supported; in that case a return of 0 isn't an error condition.
[endsect]
[#polymorphic_pointer_cast]
[section polymorphic_pointer_cast]
While `polymorphic_downcast` and `polymorphic_cast` work with built-in pointer types only,
`polymorphic_pointer_downcast` and `polymorphic_pointer_cast` are more generic versions
with support for any pointer type for which the following expressions would be valid:
For `polymorphic_pointer_downcast`:
```
static_pointer_cast<Derived>(p);
dynamic_pointer_cast<Derived>(p);
```
For `polymorphic_pointer_cast`:
```
dynamic_pointer_cast<Derived>(p);
!p; // conversion to bool with negation
```
This includes C++ built-in pointers, `std::shared_ptr`,
`boost::shared_ptr`, `boost::intrusive_ptr`, etc.
[h4 Example:]
```
#include <boost/polymorphic_pointer_cast.hpp>
class Fruit { public: virtual ~Fruit(){} };
class Banana : public Fruit {};
// Use one of these:
using FruitPtr = Fruit*;
using FruitPtr = std::shared_ptr<Fruit>;
using FruitPtr = boost::shared_ptr<Fruit>;
using FruitPtr = boost::intrusive_ptr<Fruit>;
void f(FruitPtr fruit) {
// ... logic which leads us to believe it is a banana
auto banana = boost::polymorphic_pointer_downcast<Banana>(fruit);
...
}
```
[endsect]
[endsect]
[section Synopsis]
```
namespace boost {
// Throws: std::bad_cast if ( dynamic_cast<Derived>(x) == 0 )
// Returns: dynamic_cast<Derived>(x)
template <class Derived, class Base>
constexpr Derived polymorphic_cast(Base* x);
// Effects: assert( dynamic_cast<Derived>(x) == x );
// Returns: static_cast<Derived>(x)
template <class Derived, class Base>
constexpr Derived polymorphic_downcast(Base* x);
// Effects: assert( dynamic_cast<Derived>(&x) == &x );
// Returns: static_cast<Derived>(x)
template <class Derived, class Base>
constexpr Derived polymorphic_downcast(Base& x);
// Throws: std::bad_cast if ( dynamic_pointer_cast<Derived>(x) == 0 )
// Returns: dynamic_pointer_cast<Derived>(x)
template <class Derived, class Base>
inline auto polymorphic_pointer_cast(Base x);
// Effects: assert( dynamic_pointer_cast<Derived>(x) == x );
// Returns: static_pointer_cast<Derived>(x)
template <class Derived, class Base>
inline auto polymorphic_pointer_downcast(Base x);
}
```
[endsect]
[section History]
`polymorphic_cast` was suggested by Bjarne Stroustrup in "The C++ Programming Language".
`polymorphic_downcast` was contributed by [@http://www.boost.org/people/dave_abrahams.htm Dave Abrahams].
`polymorphic_pointer_downcast` was contributed by [@http://www.boost.org/people/boris_rasin.htm Boris Rasin]
and `polymorphic_pointer_cast` by Antony Polukhin.
`polymorphic_downcast` overload for references was contributed by Julien Delacroix.
An old `numeric_cast` that was contributed by [@http://www.boost.org/people/kevlin_henney.htm Kevlin Henney]
is now superseded by the [@boost:numeric_conversion/doc/html/html/boost_numericconversion/improved_numeric_cast__.html Boost Numeric Conversion Library]
[endsect]
-941
View File
@@ -1,941 +0,0 @@
[library Boost.Lexical_Cast
[quickbook 1.5]
[version 1.0]
[copyright 2000-2005 Kevlin Henney]
[copyright 2006-2010 Alexander Nasonov]
[copyright 2011-2013 Antony Polukhin]
[category String and text processing]
[category Miscellaneous]
[license
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])
]
]
[def __numericcast__ [@boost:libs/numeric/conversion/doc/html/boost_numericconversion/improved_numeric_cast__.html `boost::numeric_cast`]]
[def __proposallong__ [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1973.html Lexical Conversion Library Proposal for TR2, N1973 by Kevlin Henney and Beman Dawes]]
[def __proposalshort__ [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1973.html Lexical Conversion Library Proposal for TR2, N1973]]
[section Motivation]
Sometimes a value must be converted to a literal text form, such as an [c++] `int` represented as a `std::string`, or vice-versa, when a `std::string` is interpreted as an `int`. Such examples are common when converting between data types internal to a program and representation external to a program, such as windows and configuration files.
The standard C and C++ libraries offer a number of facilities for performing such conversions. However, they vary with their ease of use, extensibility, and safety.
For instance, there are a number of limitations with the family of standard C functions typified by `atoi`:
* Conversion is supported in one direction only: from text to internal data type. Converting the other way using the C library requires either the inconvenience and compromised safety of the `sprintf` function, or the loss of portability associated with non-standard functions such as `itoa`.
* The range of types supported is only a subset of the built-in numeric types, namely `int`, `long`, and `double`.
* The range of types cannot be extended in a uniform manner. For instance, conversion from string representation to complex or rational.
The standard C functions typified by `strtol` have the same basic limitations, but offer finer control over the conversion process. However, for the common case such control is often either not required or not used. The `scanf` family of functions offer even greater control, but also lack safety and ease of use.
The standard C++ library offers `stringstream` for the kind of in-core formatting being discussed. It offers a great deal of control over the formatting and conversion of I/O to and from arbitrary types through text. However, for simple conversions direct use of `stringstream` can be either clumsy (with the introduction of extra local variables and the loss of infix-expression convenience) or obscure (where `stringstream` objects are created as temporary objects in an expression). Facets provide a comprehensive concept and facility for controlling textual representation, but their perceived complexity and high entry level requires an extreme degree of involvement for simple conversions, and excludes all but a few programmers.
The `lexical_cast` function template offers a convenient and consistent form for supporting common conversions to and from arbitrary types when they are represented as text. The simplification it offers is in expression-level convenience for such conversions. For more involved conversions, such as where precision or formatting need tighter control than is offered by the default behavior of `lexical_cast`, the conventional `std::stringstream` approach is recommended. Where the conversions are numeric to numeric, __numericcast__ may offer more reasonable behavior than `lexical_cast`.
For a good discussion of the options and issues involved in string-based formatting, including comparison of `stringstream`, `lexical_cast`, and others, see Herb Sutter's article, [@http://www.gotw.ca/publications/mill19.htm The String Formatters of Manor Farm]. Also, take a look at the [link boost_lexical_cast.performance Performance] section.
[endsect]
[section Examples]
[import ../example/args_to_numbers.cpp]
[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]
[endsect]
[section Synopsis]
Library features defined in [@boost:boost/lexical_cast.hpp boost/lexical_cast.hpp]:
``
namespace boost
{
class bad_lexical_cast;
template<typename Target, typename Source>
Target lexical_cast(const Source& arg);
template <typename Target>
Target lexical_cast(const AnyCharacterType* chars, std::size_t count);
}
``
[section lexical_cast]
``
template<typename Target, typename Source>
Target lexical_cast(const Source& arg);
``
Returns the result of streaming arg into a standard library string-based stream and then out as a Target object. Where Target is either `std::string` or `std::wstring`, stream extraction takes the whole content of the string, including spaces, rather than relying on the default `operator>>` behavior. If the conversion is unsuccessful, a `bad_lexical_cast` exception is thrown.
``
template <typename Target>
Target lexical_cast(const AnyCharacterType* chars, std::size_t count);
``
Takes an array of `count` characters as input parameter and streams them out as a Target object. If the conversion is unsuccessful, a `bad_lexical_cast` exception is thrown. This call may be useful for processing nonzero terminated array of characters or processing just some part of character array.
The requirements on the argument and result types for both functions are:
* Source is OutputStreamable, meaning that an `operator<<` is defined that takes a `std::ostream` or `std::wostream` object on the left hand side and an instance of the argument type on the right.
* Target is InputStreamable, meaning that an `operator>>` is defined that takes a `std::istream` or `std::wistream` object on the left hand side and an instance of the result type on the right.
* Target is CopyConstructible [20.1.3].
* Target is DefaultConstructible, meaning that it is possible to default-initialize an object of that type [8.5, 20.1.4].
The character type of the underlying stream is assumed to be `char` unless either the `Source` or the `Target` requires wide-character streaming, in which case the underlying stream uses `wchar_t`. Following types also can use `char16_t` or `char32_t` for wide-character streaming:
* Single character: `char16_t`, `char32_t`
* Arrays of characters: `char16_t *`, `char32_t *`, `const char16_t *`, `const char32_t *`
* Strings: `std::basic_string`, `boost::containers::basic_string`
* `boost::iterator_range<WideCharPtr>`, where `WideCharPtr` is a pointer to wide-character or pointer to const wide-character
* `boost::array<CharT, N>` and `std::array<CharT, N>`, `boost::array<const CharT, N>` and `std::array<const CharT, N>`
[important Many compilers and runtime libraries fail to make conversions using new Unicode characters. Make sure that the following code compiles and outputs nonzero values, before using new types:
``
std::cout
<< boost::lexical_cast<std::u32string>(1.0).size()
<< " "
<< boost::lexical_cast<std::u16string>(1.0).size();
``
]
Where a higher degree of control is required over conversions, `std::stringstream` and `std::wstringstream` offer a more appropriate path. Where non-stream-based conversions are required, `lexical_cast` is the wrong tool for the job and is not special-cased for such scenarios.
[endsect]
[section bad_lexical_cast]
``
class bad_lexical_cast : public std::bad_cast
{
public:
... // same member function interface as std::exception
};
``
Exception used to indicate runtime lexical_cast failure.
[endsect]
[endsect]
[section Frequently Asked Questions]
* [*Question:] Why does `lexical_cast<int8_t>("127")` throw `bad_lexical_cast`?
* [*Answer:] The type `int8_t` is a `typedef` to `char` or `signed char`. Lexical conversion to these types is simply reading a byte from source but since the source has more than one byte, the exception is thrown.
Please use other integer types such as `int` or `short int`. If bounds checking is important, you can also
call __numericcast__:
`numeric_cast<int8_t>(lexical_cast<int>("127"));`
[pre
]
* [*Question:] Why does `lexical_cast<unsigned char>("127")` throw `bad_lexical_cast`?
* [*Answer:] Lexical conversion to any char type is simply reading a byte from source. But since the source has more than one byte, the exception is thrown.
Please use other integer types such as `int` or `short int`. If bounds checking is important, you can also
call __numericcast__:
`numeric_cast<unsigned char>(lexical_cast<int>("127"));`
[pre
]
* [*Question:] What does `lexical_cast<std::string>` of an `int8_t` or `uint8_t` not do what I expect?
* [*Answer:] As above, note that int8_t and uint8_t are actually chars and are formatted as such. To avoid
this, cast to an integer type first: `lexical_cast<std::string>(static_cast<int>(n));`
[pre
]
* [*Question:] The implementation always resets the `ios_base::skipws` flag of an underlying stream object.
It breaks my `operator>>` that works only in presence of this flag. Can you remove code that resets the flag?
* [*Answer:] May be in a future version. There is no requirement in
__proposallong__ to reset the flag but
remember that __proposalshort__ is not yet accepted by the committee. By the way, it's a great opportunity to
make your `operator>>` more general.
Read a good C++ book, study `std::sentry` and [@boost:libs/io/doc/ios_state.html `ios_state_saver`].
[pre
]
* [*Question:] Why `std::cout << boost::lexical_cast<unsigned int>("-1");` does not throw, but outputs 4294967295?
* [*Answer:] `boost::lexical_cast` has the behavior of `std::stringstream`, which uses `num_get` functions of
`std::locale` to convert numbers. If we look at the Programming languages — C++, we'll see, that `num_get` uses
the rules of `scanf` for conversions. And in the C99 standard for unsigned input value minus sign is optional, so
if a negative number is read, no errors will arise and the result will be the two's complement.
[pre
]
* [*Question:] Why `boost::lexical_cast<int>(L'A');` outputs 65 and `boost::lexical_cast<wchar_t>(L"65");` does not throw?
* [*Answer:] If you are using an old version of Visual Studio or compile code with /Zc:wchar_t- flag,
`boost::lexical_cast` sees single `wchar_t` character as `unsigned short`. It is not a `boost::lexical_cast` mistake, but a
limitation of compiler options that you use.
[pre
]
* [*Question:] Why `boost::lexical_cast<double>("-1.#IND");` throws `boost::bad_lexical_cast`?
* [*Answer:] `"-1.#IND"` is a compiler extension, that violates standard. You shall input `"-nan"`, `"nan"`, `"inf"`
, `"-inf"` (case insensitive) strings to get NaN and Inf values. `boost::lexical_cast<string>` outputs `"-nan"`, `"nan"`,
`"inf"`, `"-inf"` strings, when has NaN or Inf input values.
[pre
]
* [*Question:] What is the fastest way to convert a non zero terminated string or a substring using `boost::lexical_cast`?
* [*Answer:] Use `boost::iterator_range` for conversion or `lexical_cast` overload with two parameters. For example, if you whant to convert to `int` two characters from a string `str`, you shall write `lexical_cast<int>(make_iterator_range(str.data(), str.data() + 2));` or `lexical_cast<int>(str.data(), 2);`.
[endsect]
[section Changes]
* [*boost 1.54.0 :]
* Fix some issues with `boost::int128_type` and `boost::uint128_type` conversions. Notify user at compile time
if the `std::numeric_limits` are not specialized for 128bit types and `boost::lexical_cast` can not make conversions.
* [*boost 1.54.0 :]
* Added code to convert `boost::int128_type` and `boost::uint128_type` types (requires GCC 4.7 or higher).
* Conversions to pointers will now fail to compile, instead of throwing at runtime.
* Restored ability to get pointers to `lexical_cast` function (was broken in 1.53.0).
* [*boost 1.53.0 :]
* Much better input and output streams detection for user defined types.
* [*boost 1.52.0 :]
* Restored compilation on MSVC-2003 (was broken in 1.51.0).
* Added `lexical_cast(const CharType* chars, std::size_t count)` function overload.
* [*boost 1.51.0 :]
* Better performance, less memory usage for `boost::array<character_type, N>` and `std::array<character_type, N>` conversions.
* [*boost 1.50.0 :]
* `boost::bad_lexical_cast` exception is now globaly visible and can be catched even if code is compiled with -fvisibility=hidden.
* Now it is possible to compile library with disabled exceptions.
* Better performance, less memory usage and bugfixes for `boost::iterator_range<character_type*>` conversions.
* [*boost 1.49.0 :]
* Restored work with typedefed wchar_t (compilation flag /Zc:wchar_t- for Visual Studio).
* Better performance and less memory usage for `boost::container::basic_string` conversions.
* [*boost 1.48.0 :]
* Added code to work with Inf and NaN on any platform.
* Better performance and less memory usage for conversions to float type (and to double type, if `sizeof(double) < sizeof(long double)`).
* [*boost 1.47.0 :]
* Optimizations for "C" and other locales without number grouping.
* Better performance and less memory usage for unsigned char and signed char conversions.
* Better performance and less memory usage for conversions to arithmetic types.
* Better performance and less memory usage for conversions from arithmetic type to arithmetic type.
* Directly construct Target from Source on some conversions (like conversions from string to string, from char array to string, from char to char and others).
* [*boost 1.34.0 :]
* Better performance for many combinations of Source and Target types. For more details refer to Alexander Nasonovs article [@http://accu.org/index.php/journals/1375 Fine Tuning for lexical_cast, Overload #74, August 2006] [@http://www.accu.org/var/uploads/journals/overload74.pdf (PDF)].
* [*boost 1.33.0 :]
* Call-by-const reference for the parameters. This requires partial specialization of class templates, so it doesn't work for MSVC 6, and it uses the original pass by value there.
* The MSVC 6 support is deprecated, and will be removed in a future Boost version.
* [*Earlier :]
* The previous version of lexical_cast used the default stream precision for reading and writing floating-point numbers. For numerics that have a corresponding specialization of `std::numeric_limits`, the current version now chooses a precision to match.
* The previous version of lexical_cast did not support conversion to or from any wide-character-based types. For compilers with full language and library support for wide characters, `lexical_cast` now supports conversions from `wchar_t`, `wchar_t *`, and `std::wstring` and to `wchar_t` and `std::wstring`.
* The previous version of `lexical_cast` assumed that the conventional stream extractor operators were sufficient for reading values. However, string I/O is asymmetric, with the result that spaces play the role of I/O separators rather than string content. The current version fixes this error for `std::string` and, where supported, `std::wstring`: `lexical_cast<std::string>("Hello, World")` succeeds instead of failing with a `bad_lexical_cast` exception.
* The previous version of `lexical_cast` allowed unsafe and meaningless conversions to pointers. The current version now throws a `bad_lexical_cast` for conversions to pointers: `lexical_cast<char *>("Goodbye, World")` now throws an exception instead of causing undefined behavior.
[endsect]
[section Performance]
In most cases `boost::lexical_cast` is faster than `scanf`, `printf`, `std::stringstream`. For more detailed info you can look at the tables below.
[section Tests description]
All the tests measure execution speed in milliseconds for 10000 iterations of the following code blocks:
[table:legend Tests source code
[[Test name] [Code]]
[[lexical_cast]
[``
_out = boost::lexical_cast<OUTTYPE>(_in);
``]
]
[[std::stringstream with construction]
[``
std::stringstream ss;
ss << _in;
if (ss.fail()) throw std::logic_error(descr);
ss >> _out;
if (ss.fail()) throw std::logic_error(descr);
``]
]
[[std::stringstream without construction]
[``
ss << _in; // ss is an instance of std::stringstream
if (ss.fail()) throw std::logic_error(descr);
ss >> _out;
if (ss.fail()) throw std::logic_error(descr);
/* reseting std::stringstream to use it again */
ss.str(std::string());
ss.clear();
``]
]
[[scanf/printf]
[``
typename OUTTYPE::value_type buffer[500];
sprintf( (char*)buffer, conv, _in);
_out = buffer;
``]
]
]
Fastest results are highlitened with "!!! *x* !!!".
Do not use this results to compare compilers, because tests were taken on different hardware.
[endsect]
[/ BEGIN of section, generated by performance measuring program ]
[section Clang version 3.0 (tags/RELEASE_30/final)]
[table:id Performance Table ( Clang version 3.0 (tags/RELEASE_30/final))
[[From->To] [lexical_cast] [std::stringstream with construction] [std::stringstream without construction][scanf/printf]]
[[ string->char ][ !!! *<1* !!! ][ 169 ][ 9 ][ 10 ]]
[[ string->signed char ][ !!! *<1* !!! ][ 108 ][ 8 ][ 10 ]]
[[ string->unsigned char ][ !!! *<1* !!! ][ 103 ][ 9 ][ 10 ]]
[[ string->int ][ !!! *6* !!! ][ 117 ][ 24 ][ 24 ]]
[[ string->short ][ !!! *7* !!! ][ 115 ][ 20 ][ 24 ]]
[[ string->long int ][ !!! *7* !!! ][ 115 ][ 19 ][ 22 ]]
[[ string->long long ][ !!! *8* !!! ][ 116 ][ 21 ][ 23 ]]
[[ string->unsigned int ][ !!! *6* !!! ][ 121 ][ 18 ][ 23 ]]
[[ string->unsigned short ][ !!! *6* !!! ][ 116 ][ 19 ][ 22 ]]
[[ string->unsigned long int ][ !!! *7* !!! ][ 117 ][ 23 ][ 21 ]]
[[ string->unsigned long long ][ !!! *8* !!! ][ 118 ][ 19 ][ 34 ]]
[[ string->float ][ !!! *13* !!! ][ 201 ][ 55 ][ 41 ]]
[[ string->double ][ !!! *14* !!! ][ 151 ][ 54 ][ 41 ]]
[[ string->long double ][ 195 ][ 231 ][ 67 ][ !!! *42* !!! ]]
[[ string->array<char, 50> ][ !!! *<1* !!! ][ 121 ][ 18 ][ 12 ]]
[[ string->string ][ !!! *1* !!! ][ 124 ][ 27 ][ --- ]]
[[ string->container::string ][ !!! *3* !!! ][ 114 ][ 25 ][ --- ]]
[[ string->char ][ 7 ][ 111 ][ 25 ][ !!! *7* !!! ]]
[[ string->signed char ][ !!! *6* !!! ][ 112 ][ 30 ][ 26 ]]
[[ string->unsigned char ][ !!! *6* !!! ][ 113 ][ 25 ][ 24 ]]
[[ int->string ][ !!! *12* !!! ][ 126 ][ 36 ][ 21 ]]
[[ short->string ][ !!! *11* !!! ][ 135 ][ 30 ][ 21 ]]
[[ long int->string ][ !!! *11* !!! ][ 128 ][ 28 ][ 21 ]]
[[ long long->string ][ !!! *12* !!! ][ 126 ][ 32 ][ 24 ]]
[[ unsigned int->string ][ !!! *11* !!! ][ 131 ][ 36 ][ 22 ]]
[[ unsigned short->string ][ !!! *11* !!! ][ 130 ][ 28 ][ 22 ]]
[[ unsigned long int->string ][ !!! *11* !!! ][ 130 ][ 36 ][ 22 ]]
[[ unsigned long long->string ][ !!! *11* !!! ][ 127 ][ 43 ][ 25 ]]
[[ float->string ][ 53 ][ 190 ][ 83 ][ !!! *41* !!! ]]
[[ double->string ][ 59 ][ 197 ][ 82 ][ !!! *44* !!! ]]
[[ long double->string ][ 118 ][ 229 ][ 101 ][ !!! *44* !!! ]]
[[ char*->char ][ !!! *1* !!! ][ 105 ][ 9 ][ 9 ]]
[[ char*->signed char ][ !!! *1* !!! ][ 107 ][ 10 ][ 10 ]]
[[ char*->unsigned char ][ !!! *1* !!! ][ 106 ][ 9 ][ 11 ]]
[[ char*->int ][ !!! *7* !!! ][ 149 ][ 25 ][ 24 ]]
[[ char*->short ][ !!! *7* !!! ][ 118 ][ 20 ][ 22 ]]
[[ char*->long int ][ !!! *9* !!! ][ 117 ][ 20 ][ 28 ]]
[[ char*->long long ][ !!! *9* !!! ][ 128 ][ 23 ][ 29 ]]
[[ char*->unsigned int ][ !!! *7* !!! ][ 120 ][ 19 ][ 23 ]]
[[ char*->unsigned short ][ !!! *7* !!! ][ 125 ][ 20 ][ 22 ]]
[[ char*->unsigned long int ][ !!! *8* !!! ][ 125 ][ 21 ][ 24 ]]
[[ char*->unsigned long long ][ !!! *8* !!! ][ 130 ][ 19 ][ 22 ]]
[[ char*->float ][ !!! *14* !!! ][ 162 ][ 56 ][ 41 ]]
[[ char*->double ][ !!! *16* !!! ][ 151 ][ 54 ][ 39 ]]
[[ char*->long double ][ 111 ][ 176 ][ 58 ][ !!! *42* !!! ]]
[[ char*->array<char, 50> ][ !!! *1* !!! ][ 116 ][ 20 ][ 17 ]]
[[ char*->string ][ !!! *8* !!! ][ 125 ][ 27 ][ --- ]]
[[ char*->container::string ][ !!! *2* !!! ][ 115 ][ 26 ][ --- ]]
[[ unsigned char*->char ][ !!! *1* !!! ][ 101 ][ 9 ][ 9 ]]
[[ unsigned char*->signed char ][ !!! *1* !!! ][ 104 ][ 9 ][ 11 ]]
[[ unsigned char*->unsigned char ][ !!! *1* !!! ][ 103 ][ 9 ][ 13 ]]
[[ unsigned char*->int ][ !!! *8* !!! ][ 116 ][ 20 ][ 24 ]]
[[ unsigned char*->short ][ !!! *7* !!! ][ 121 ][ 20 ][ 26 ]]
[[ unsigned char*->long int ][ !!! *8* !!! ][ 118 ][ 20 ][ 22 ]]
[[ unsigned char*->long long ][ !!! *8* !!! ][ 122 ][ 20 ][ 23 ]]
[[ unsigned char*->unsigned int ][ !!! *6* !!! ][ 119 ][ 22 ][ 23 ]]
[[ unsigned char*->unsigned short ][ !!! *7* !!! ][ 122 ][ 20 ][ 22 ]]
[[ unsigned char*->unsigned long int ][ !!! *8* !!! ][ 125 ][ 21 ][ 22 ]]
[[ unsigned char*->unsigned long long ][ !!! *8* !!! ][ 122 ][ 19 ][ 25 ]]
[[ unsigned char*->float ][ !!! *14* !!! ][ 162 ][ 62 ][ 37 ]]
[[ unsigned char*->double ][ !!! *15* !!! ][ 151 ][ 58 ][ 39 ]]
[[ unsigned char*->long double ][ 116 ][ 156 ][ 58 ][ !!! *42* !!! ]]
[[ unsigned char*->array<char, 50> ][ !!! *1* !!! ][ 122 ][ 19 ][ 15 ]]
[[ unsigned char*->string ][ !!! *8* !!! ][ 124 ][ 27 ][ --- ]]
[[ unsigned char*->container::string ][ !!! *4* !!! ][ 119 ][ 25 ][ --- ]]
[[ signed char*->char ][ !!! *1* !!! ][ 107 ][ 9 ][ 9 ]]
[[ signed char*->signed char ][ !!! *1* !!! ][ 108 ][ 10 ][ 11 ]]
[[ signed char*->unsigned char ][ !!! *1* !!! ][ 106 ][ 9 ][ 11 ]]
[[ signed char*->int ][ !!! *7* !!! ][ 122 ][ 21 ][ 22 ]]
[[ signed char*->short ][ !!! *7* !!! ][ 126 ][ 20 ][ 22 ]]
[[ signed char*->long int ][ !!! *8* !!! ][ 119 ][ 20 ][ 23 ]]
[[ signed char*->long long ][ !!! *8* !!! ][ 119 ][ 21 ][ 26 ]]
[[ signed char*->unsigned int ][ !!! *6* !!! ][ 124 ][ 18 ][ 22 ]]
[[ signed char*->unsigned short ][ !!! *7* !!! ][ 124 ][ 21 ][ 23 ]]
[[ signed char*->unsigned long int ][ !!! *8* !!! ][ 121 ][ 24 ][ 23 ]]
[[ signed char*->unsigned long long ][ !!! *8* !!! ][ 122 ][ 20 ][ 22 ]]
[[ signed char*->float ][ !!! *14* !!! ][ 167 ][ 56 ][ 37 ]]
[[ signed char*->double ][ !!! *14* !!! ][ 162 ][ 53 ][ 40 ]]
[[ signed char*->long double ][ 110 ][ 152 ][ 56 ][ !!! *42* !!! ]]
[[ signed char*->array<char, 50> ][ !!! *1* !!! ][ 117 ][ 19 ][ 12 ]]
[[ signed char*->string ][ !!! *8* !!! ][ 132 ][ 27 ][ --- ]]
[[ signed char*->container::string ][ !!! *4* !!! ][ 116 ][ 26 ][ --- ]]
[[ iterator_range<char*>->char ][ !!! *<1* !!! ][ 112 ][ 14 ][ 9 ]]
[[ iterator_range<char*>->signed char ][ !!! *<1* !!! ][ 107 ][ 13 ][ 10 ]]
[[ iterator_range<char*>->unsigned char ][ !!! *<1* !!! ][ 145 ][ 15 ][ 10 ]]
[[ iterator_range<char*>->int ][ !!! *6* !!! ][ 119 ][ 22 ][ 23 ]]
[[ iterator_range<char*>->short ][ !!! *6* !!! ][ 115 ][ 22 ][ 23 ]]
[[ iterator_range<char*>->long int ][ !!! *7* !!! ][ 115 ][ 25 ][ 22 ]]
[[ iterator_range<char*>->long long ][ !!! *7* !!! ][ 117 ][ 21 ][ 23 ]]
[[ iterator_range<char*>->unsigned int ][ !!! *6* !!! ][ 118 ][ 22 ][ 22 ]]
[[ iterator_range<char*>->unsigned short ][ !!! *6* !!! ][ 117 ][ 24 ][ 22 ]]
[[ iterator_range<char*>->unsigned long int ][ !!! *7* !!! ][ 124 ][ 25 ][ 22 ]]
[[ iterator_range<char*>->unsigned long long ][ !!! *7* !!! ][ 119 ][ 22 ][ 22 ]]
[[ iterator_range<char*>->float ][ !!! *13* !!! ][ 159 ][ 42 ][ 41 ]]
[[ iterator_range<char*>->double ][ !!! *14* !!! ][ 152 ][ 40 ][ 40 ]]
[[ iterator_range<char*>->long double ][ 113 ][ 155 ][ 58 ][ !!! *54* !!! ]]
[[ iterator_range<char*>->array<char, 50> ][ !!! *<1* !!! ][ 127 ][ 23 ][ 13 ]]
[[ iterator_range<char*>->string ][ !!! *7* !!! ][ 132 ][ 30 ][ --- ]]
[[ iterator_range<char*>->container::string ][ !!! *3* !!! ][ 122 ][ 24 ][ --- ]]
[[ array<char, 50>->char ][ !!! *<1* !!! ][ 110 ][ 9 ][ 10 ]]
[[ array<char, 50>->signed char ][ !!! *<1* !!! ][ 119 ][ 9 ][ 13 ]]
[[ array<char, 50>->unsigned char ][ !!! *<1* !!! ][ 106 ][ 13 ][ 11 ]]
[[ array<char, 50>->int ][ !!! *6* !!! ][ 131 ][ 21 ][ 22 ]]
[[ array<char, 50>->short ][ !!! *7* !!! ][ 119 ][ 22 ][ 28 ]]
[[ array<char, 50>->long int ][ !!! *8* !!! ][ 133 ][ 21 ][ 26 ]]
[[ array<char, 50>->long long ][ !!! *8* !!! ][ 115 ][ 22 ][ 23 ]]
[[ array<char, 50>->unsigned int ][ !!! *6* !!! ][ 118 ][ 18 ][ 22 ]]
[[ array<char, 50>->unsigned short ][ !!! *7* !!! ][ 119 ][ 19 ][ 22 ]]
[[ array<char, 50>->unsigned long int ][ !!! *7* !!! ][ 118 ][ 23 ][ 21 ]]
[[ array<char, 50>->unsigned long long ][ !!! *7* !!! ][ 117 ][ 20 ][ 22 ]]
[[ array<char, 50>->float ][ !!! *15* !!! ][ 156 ][ 53 ][ 36 ]]
[[ array<char, 50>->double ][ !!! *15* !!! ][ 148 ][ 55 ][ 39 ]]
[[ array<char, 50>->long double ][ 110 ][ 150 ][ 56 ][ !!! *41* !!! ]]
[[ array<char, 50>->array<char, 50> ][ !!! *<1* !!! ][ 117 ][ 19 ][ 12 ]]
[[ array<char, 50>->string ][ !!! *7* !!! ][ 124 ][ 26 ][ --- ]]
[[ array<char, 50>->container::string ][ !!! *4* !!! ][ 115 ][ 26 ][ --- ]]
[[ int->int ][ !!! *<1* !!! ][ 117 ][ 24 ][ --- ]]
[[ float->double ][ !!! *<1* !!! ][ 245 ][ 125 ][ --- ]]
[[ char->signed char ][ !!! *<1* !!! ][ 100 ][ 9 ][ --- ]]
]
[endsect]
[section GNU C++ version 4.6.3]
[table:id Performance Table ( GNU C++ version 4.6.3)
[[From->To] [lexical_cast] [std::stringstream with construction] [std::stringstream without construction][scanf/printf]]
[[ string->char ][ !!! *<1* !!! ][ 142 ][ 10 ][ 18 ]]
[[ string->signed char ][ !!! *<1* !!! ][ 111 ][ 8 ][ 10 ]]
[[ string->unsigned char ][ !!! *<1* !!! ][ 101 ][ 8 ][ 10 ]]
[[ string->int ][ !!! *7* !!! ][ 110 ][ 20 ][ 24 ]]
[[ string->short ][ !!! *6* !!! ][ 109 ][ 20 ][ 25 ]]
[[ string->long int ][ !!! *7* !!! ][ 113 ][ 19 ][ 24 ]]
[[ string->long long ][ !!! *7* !!! ][ 116 ][ 24 ][ 23 ]]
[[ string->unsigned int ][ !!! *6* !!! ][ 110 ][ 19 ][ 23 ]]
[[ string->unsigned short ][ !!! *5* !!! ][ 116 ][ 18 ][ 23 ]]
[[ string->unsigned long int ][ !!! *7* !!! ][ 111 ][ 22 ][ 23 ]]
[[ string->unsigned long long ][ !!! *7* !!! ][ 108 ][ 20 ][ 22 ]]
[[ string->float ][ !!! *11* !!! ][ 161 ][ 54 ][ 38 ]]
[[ string->double ][ !!! *11* !!! ][ 146 ][ 56 ][ 41 ]]
[[ string->long double ][ 113 ][ 151 ][ 59 ][ !!! *43* !!! ]]
[[ string->array<char, 50> ][ !!! *<1* !!! ][ 107 ][ 18 ][ 14 ]]
[[ string->string ][ !!! *2* !!! ][ 127 ][ 24 ][ --- ]]
[[ string->container::string ][ !!! *3* !!! ][ 142 ][ 26 ][ --- ]]
[[ string->char ][ !!! *7* !!! ][ 110 ][ 23 ][ 17 ]]
[[ string->signed char ][ !!! *7* !!! ][ 114 ][ 23 ][ 24 ]]
[[ string->unsigned char ][ !!! *7* !!! ][ 110 ][ 25 ][ 24 ]]
[[ int->string ][ !!! *12* !!! ][ 127 ][ 31 ][ 22 ]]
[[ short->string ][ !!! *13* !!! ][ 129 ][ 31 ][ 22 ]]
[[ long int->string ][ !!! *12* !!! ][ 125 ][ 30 ][ 22 ]]
[[ long long->string ][ !!! *13* !!! ][ 127 ][ 34 ][ 24 ]]
[[ unsigned int->string ][ !!! *13* !!! ][ 127 ][ 27 ][ 21 ]]
[[ unsigned short->string ][ !!! *12* !!! ][ 127 ][ 28 ][ 22 ]]
[[ unsigned long int->string ][ !!! *12* !!! ][ 131 ][ 27 ][ 22 ]]
[[ unsigned long long->string ][ !!! *12* !!! ][ 125 ][ 28 ][ 24 ]]
[[ float->string ][ 51 ][ 200 ][ 81 ][ !!! *40* !!! ]]
[[ double->string ][ 56 ][ 194 ][ 82 ][ !!! *48* !!! ]]
[[ long double->string ][ 65 ][ 220 ][ 82 ][ !!! *41* !!! ]]
[[ char*->char ][ !!! *<1* !!! ][ 104 ][ 10 ][ 9 ]]
[[ char*->signed char ][ !!! *<1* !!! ][ 101 ][ 10 ][ 11 ]]
[[ char*->unsigned char ][ !!! *<1* !!! ][ 99 ][ 10 ][ 12 ]]
[[ char*->int ][ !!! *6* !!! ][ 112 ][ 23 ][ 24 ]]
[[ char*->short ][ !!! *6* !!! ][ 115 ][ 21 ][ 23 ]]
[[ char*->long int ][ !!! *8* !!! ][ 111 ][ 21 ][ 24 ]]
[[ char*->long long ][ !!! *9* !!! ][ 112 ][ 21 ][ 30 ]]
[[ char*->unsigned int ][ !!! *7* !!! ][ 112 ][ 22 ][ 24 ]]
[[ char*->unsigned short ][ !!! *6* !!! ][ 119 ][ 19 ][ 23 ]]
[[ char*->unsigned long int ][ !!! *7* !!! ][ 115 ][ 22 ][ 23 ]]
[[ char*->unsigned long long ][ !!! *7* !!! ][ 115 ][ 20 ][ 23 ]]
[[ char*->float ][ !!! *12* !!! ][ 153 ][ 54 ][ 39 ]]
[[ char*->double ][ !!! *12* !!! ][ 153 ][ 61 ][ 41 ]]
[[ char*->long double ][ 108 ][ 160 ][ 61 ][ !!! *49* !!! ]]
[[ char*->array<char, 50> ][ !!! *<1* !!! ][ 107 ][ 20 ][ 14 ]]
[[ char*->string ][ !!! *7* !!! ][ 123 ][ 26 ][ --- ]]
[[ char*->container::string ][ !!! *2* !!! ][ 121 ][ 24 ][ --- ]]
[[ unsigned char*->char ][ !!! *<1* !!! ][ 97 ][ 10 ][ 9 ]]
[[ unsigned char*->signed char ][ !!! *<1* !!! ][ 98 ][ 10 ][ 12 ]]
[[ unsigned char*->unsigned char ][ !!! *<1* !!! ][ 99 ][ 11 ][ 12 ]]
[[ unsigned char*->int ][ !!! *6* !!! ][ 112 ][ 22 ][ 24 ]]
[[ unsigned char*->short ][ !!! *10* !!! ][ 111 ][ 24 ][ 24 ]]
[[ unsigned char*->long int ][ !!! *8* !!! ][ 110 ][ 23 ][ 24 ]]
[[ unsigned char*->long long ][ !!! *9* !!! ][ 115 ][ 21 ][ 25 ]]
[[ unsigned char*->unsigned int ][ !!! *6* !!! ][ 111 ][ 24 ][ 23 ]]
[[ unsigned char*->unsigned short ][ !!! *6* !!! ][ 118 ][ 19 ][ 23 ]]
[[ unsigned char*->unsigned long int ][ !!! *8* !!! ][ 112 ][ 21 ][ 23 ]]
[[ unsigned char*->unsigned long long ][ !!! *13* !!! ][ 109 ][ 20 ][ 23 ]]
[[ unsigned char*->float ][ !!! *12* !!! ][ 154 ][ 56 ][ 39 ]]
[[ unsigned char*->double ][ !!! *17* !!! ][ 150 ][ 58 ][ 41 ]]
[[ unsigned char*->long double ][ 108 ][ 149 ][ 68 ][ !!! *43* !!! ]]
[[ unsigned char*->array<char, 50> ][ !!! *1* !!! ][ 107 ][ 19 ][ 15 ]]
[[ unsigned char*->string ][ !!! *8* !!! ][ 124 ][ 26 ][ --- ]]
[[ unsigned char*->container::string ][ !!! *4* !!! ][ 121 ][ 24 ][ --- ]]
[[ signed char*->char ][ !!! *<1* !!! ][ 99 ][ 10 ][ 9 ]]
[[ signed char*->signed char ][ !!! *<1* !!! ][ 99 ][ 10 ][ 10 ]]
[[ signed char*->unsigned char ][ !!! *<1* !!! ][ 99 ][ 10 ][ 12 ]]
[[ signed char*->int ][ !!! *6* !!! ][ 113 ][ 28 ][ 24 ]]
[[ signed char*->short ][ !!! *6* !!! ][ 110 ][ 21 ][ 25 ]]
[[ signed char*->long int ][ !!! *8* !!! ][ 110 ][ 21 ][ 24 ]]
[[ signed char*->long long ][ !!! *9* !!! ][ 116 ][ 21 ][ 24 ]]
[[ signed char*->unsigned int ][ !!! *7* !!! ][ 114 ][ 21 ][ 23 ]]
[[ signed char*->unsigned short ][ !!! *6* !!! ][ 116 ][ 20 ][ 23 ]]
[[ signed char*->unsigned long int ][ !!! *8* !!! ][ 113 ][ 27 ][ 23 ]]
[[ signed char*->unsigned long long ][ !!! *8* !!! ][ 110 ][ 20 ][ 23 ]]
[[ signed char*->float ][ !!! *12* !!! ][ 155 ][ 53 ][ 44 ]]
[[ signed char*->double ][ !!! *13* !!! ][ 150 ][ 60 ][ 42 ]]
[[ signed char*->long double ][ 108 ][ 151 ][ 62 ][ !!! *44* !!! ]]
[[ signed char*->array<char, 50> ][ !!! *1* !!! ][ 107 ][ 19 ][ 15 ]]
[[ signed char*->string ][ !!! *8* !!! ][ 124 ][ 26 ][ --- ]]
[[ signed char*->container::string ][ !!! *4* !!! ][ 121 ][ 24 ][ --- ]]
[[ iterator_range<char*>->char ][ !!! *<1* !!! ][ 103 ][ 14 ][ 10 ]]
[[ iterator_range<char*>->signed char ][ !!! *<1* !!! ][ 102 ][ 15 ][ 12 ]]
[[ iterator_range<char*>->unsigned char ][ !!! *<1* !!! ][ 102 ][ 14 ][ 12 ]]
[[ iterator_range<char*>->int ][ !!! *6* !!! ][ 115 ][ 23 ][ 24 ]]
[[ iterator_range<char*>->short ][ !!! *5* !!! ][ 110 ][ 22 ][ 24 ]]
[[ iterator_range<char*>->long int ][ !!! *7* !!! ][ 109 ][ 22 ][ 29 ]]
[[ iterator_range<char*>->long long ][ !!! *7* !!! ][ 111 ][ 24 ][ 28 ]]
[[ iterator_range<char*>->unsigned int ][ !!! *6* !!! ][ 114 ][ 22 ][ 23 ]]
[[ iterator_range<char*>->unsigned short ][ !!! *5* !!! ][ 115 ][ 20 ][ 22 ]]
[[ iterator_range<char*>->unsigned long int ][ !!! *7* !!! ][ 123 ][ 26 ][ 23 ]]
[[ iterator_range<char*>->unsigned long long ][ !!! *7* !!! ][ 110 ][ 23 ][ 24 ]]
[[ iterator_range<char*>->float ][ !!! *11* !!! ][ 153 ][ 38 ][ 38 ]]
[[ iterator_range<char*>->double ][ !!! *11* !!! ][ 140 ][ 43 ][ 40 ]]
[[ iterator_range<char*>->long double ][ 108 ][ 147 ][ !!! *41* !!! ][ 46 ]]
[[ iterator_range<char*>->array<char, 50> ][ !!! *<1* !!! ][ 109 ][ 22 ][ 15 ]]
[[ iterator_range<char*>->string ][ !!! *8* !!! ][ 122 ][ 29 ][ --- ]]
[[ iterator_range<char*>->container::string ][ !!! *3* !!! ][ 117 ][ 23 ][ --- ]]
[[ array<char, 50>->char ][ !!! *<1* !!! ][ 98 ][ 10 ][ 9 ]]
[[ array<char, 50>->signed char ][ !!! *<1* !!! ][ 99 ][ 9 ][ 12 ]]
[[ array<char, 50>->unsigned char ][ !!! *<1* !!! ][ 102 ][ 9 ][ 12 ]]
[[ array<char, 50>->int ][ !!! *6* !!! ][ 119 ][ 23 ][ 23 ]]
[[ array<char, 50>->short ][ !!! *6* !!! ][ 111 ][ 21 ][ 26 ]]
[[ array<char, 50>->long int ][ !!! *7* !!! ][ 115 ][ 20 ][ 28 ]]
[[ array<char, 50>->long long ][ !!! *9* !!! ][ 110 ][ 21 ][ 26 ]]
[[ array<char, 50>->unsigned int ][ !!! *6* !!! ][ 115 ][ 22 ][ 23 ]]
[[ array<char, 50>->unsigned short ][ !!! *6* !!! ][ 115 ][ 19 ][ 23 ]]
[[ array<char, 50>->unsigned long int ][ !!! *7* !!! ][ 118 ][ 23 ][ 23 ]]
[[ array<char, 50>->unsigned long long ][ !!! *7* !!! ][ 109 ][ 20 ][ 24 ]]
[[ array<char, 50>->float ][ !!! *12* !!! ][ 160 ][ 53 ][ 38 ]]
[[ array<char, 50>->double ][ !!! *11* !!! ][ 147 ][ 57 ][ 41 ]]
[[ array<char, 50>->long double ][ 109 ][ 154 ][ 59 ][ !!! *42* !!! ]]
[[ array<char, 50>->array<char, 50> ][ !!! *1* !!! ][ 105 ][ 19 ][ 14 ]]
[[ array<char, 50>->string ][ !!! *8* !!! ][ 129 ][ 26 ][ --- ]]
[[ array<char, 50>->container::string ][ !!! *4* !!! ][ 116 ][ 25 ][ --- ]]
[[ int->int ][ !!! *<1* !!! ][ 118 ][ 24 ][ --- ]]
[[ float->double ][ !!! *<1* !!! ][ 242 ][ 132 ][ --- ]]
[[ char->signed char ][ !!! *<1* !!! ][ 94 ][ 8 ][ --- ]]
]
[endsect]
[section GNU C++ version 4.5.3]
[table:id Performance Table ( GNU C++ version 4.5.3)
[[From->To] [lexical_cast] [std::stringstream with construction] [std::stringstream without construction][scanf/printf]]
[[ string->char ][ !!! *<1* !!! ][ 153 ][ 15 ][ 9 ]]
[[ string->signed char ][ !!! *<1* !!! ][ 134 ][ 8 ][ 10 ]]
[[ string->unsigned char ][ !!! *<1* !!! ][ 97 ][ 8 ][ 14 ]]
[[ string->int ][ !!! *7* !!! ][ 115 ][ 22 ][ 22 ]]
[[ string->short ][ !!! *5* !!! ][ 112 ][ 19 ][ 21 ]]
[[ string->long int ][ !!! *7* !!! ][ 110 ][ 19 ][ 24 ]]
[[ string->long long ][ !!! *7* !!! ][ 115 ][ 21 ][ 23 ]]
[[ string->unsigned int ][ !!! *6* !!! ][ 113 ][ 20 ][ 23 ]]
[[ string->unsigned short ][ !!! *5* !!! ][ 116 ][ 18 ][ 23 ]]
[[ string->unsigned long int ][ !!! *7* !!! ][ 111 ][ 20 ][ 23 ]]
[[ string->unsigned long long ][ !!! *7* !!! ][ 115 ][ 18 ][ 23 ]]
[[ string->float ][ !!! *14* !!! ][ 153 ][ 55 ][ 38 ]]
[[ string->double ][ !!! *11* !!! ][ 151 ][ 60 ][ 38 ]]
[[ string->long double ][ 107 ][ 151 ][ 59 ][ !!! *44* !!! ]]
[[ string->array<char, 50> ][ !!! *<1* !!! ][ 107 ][ 18 ][ 12 ]]
[[ string->string ][ !!! *2* !!! ][ 129 ][ 49 ][ --- ]]
[[ string->container::string ][ !!! *9* !!! ][ 199 ][ 22 ][ --- ]]
[[ string->char ][ !!! *7* !!! ][ 114 ][ 27 ][ 16 ]]
[[ string->signed char ][ !!! *7* !!! ][ 116 ][ 32 ][ 23 ]]
[[ string->unsigned char ][ !!! *7* !!! ][ 114 ][ 27 ][ 22 ]]
[[ int->string ][ !!! *11* !!! ][ 125 ][ 31 ][ 21 ]]
[[ short->string ][ !!! *11* !!! ][ 126 ][ 33 ][ 21 ]]
[[ long int->string ][ !!! *11* !!! ][ 126 ][ 32 ][ 22 ]]
[[ long long->string ][ !!! *11* !!! ][ 118 ][ 30 ][ 23 ]]
[[ unsigned int->string ][ !!! *11* !!! ][ 125 ][ 31 ][ 20 ]]
[[ unsigned short->string ][ !!! *12* !!! ][ 128 ][ 30 ][ 21 ]]
[[ unsigned long int->string ][ !!! *11* !!! ][ 131 ][ 30 ][ 21 ]]
[[ unsigned long long->string ][ !!! *11* !!! ][ 127 ][ 32 ][ 23 ]]
[[ float->string ][ 49 ][ 197 ][ 92 ][ !!! *39* !!! ]]
[[ double->string ][ 56 ][ 195 ][ 80 ][ !!! *43* !!! ]]
[[ long double->string ][ 60 ][ 222 ][ 88 ][ !!! *42* !!! ]]
[[ char*->char ][ !!! *<1* !!! ][ 100 ][ 10 ][ 9 ]]
[[ char*->signed char ][ !!! *<1* !!! ][ 99 ][ 10 ][ 10 ]]
[[ char*->unsigned char ][ !!! *<1* !!! ][ 106 ][ 10 ][ 10 ]]
[[ char*->int ][ !!! *7* !!! ][ 113 ][ 23 ][ 22 ]]
[[ char*->short ][ !!! *6* !!! ][ 113 ][ 21 ][ 23 ]]
[[ char*->long int ][ !!! *8* !!! ][ 116 ][ 21 ][ 23 ]]
[[ char*->long long ][ !!! *8* !!! ][ 115 ][ 21 ][ 21 ]]
[[ char*->unsigned int ][ !!! *6* !!! ][ 114 ][ 25 ][ 22 ]]
[[ char*->unsigned short ][ !!! *6* !!! ][ 119 ][ 20 ][ 23 ]]
[[ char*->unsigned long int ][ !!! *8* !!! ][ 114 ][ 23 ][ 23 ]]
[[ char*->unsigned long long ][ !!! *7* !!! ][ 111 ][ 20 ][ 24 ]]
[[ char*->float ][ !!! *16* !!! ][ 154 ][ 54 ][ 38 ]]
[[ char*->double ][ !!! *12* !!! ][ 149 ][ 59 ][ 40 ]]
[[ char*->long double ][ 107 ][ 166 ][ 62 ][ !!! *44* !!! ]]
[[ char*->array<char, 50> ][ !!! *1* !!! ][ 108 ][ 20 ][ 12 ]]
[[ char*->string ][ !!! *8* !!! ][ 125 ][ 28 ][ --- ]]
[[ char*->container::string ][ !!! *2* !!! ][ 123 ][ 24 ][ --- ]]
[[ unsigned char*->char ][ !!! *<1* !!! ][ 104 ][ 11 ][ 9 ]]
[[ unsigned char*->signed char ][ !!! *<1* !!! ][ 106 ][ 10 ][ 10 ]]
[[ unsigned char*->unsigned char ][ !!! *<1* !!! ][ 101 ][ 10 ][ 10 ]]
[[ unsigned char*->int ][ !!! *7* !!! ][ 117 ][ 22 ][ 24 ]]
[[ unsigned char*->short ][ !!! *6* !!! ][ 111 ][ 26 ][ 22 ]]
[[ unsigned char*->long int ][ !!! *8* !!! ][ 111 ][ 23 ][ 23 ]]
[[ unsigned char*->long long ][ !!! *8* !!! ][ 114 ][ 21 ][ 23 ]]
[[ unsigned char*->unsigned int ][ !!! *7* !!! ][ 115 ][ 20 ][ 25 ]]
[[ unsigned char*->unsigned short ][ !!! *6* !!! ][ 113 ][ 20 ][ 22 ]]
[[ unsigned char*->unsigned long int ][ !!! *8* !!! ][ 115 ][ 25 ][ 24 ]]
[[ unsigned char*->unsigned long long ][ !!! *7* !!! ][ 113 ][ 25 ][ 25 ]]
[[ unsigned char*->float ][ !!! *16* !!! ][ 158 ][ 55 ][ 38 ]]
[[ unsigned char*->double ][ !!! *12* !!! ][ 155 ][ 62 ][ 40 ]]
[[ unsigned char*->long double ][ 108 ][ 153 ][ 60 ][ !!! *41* !!! ]]
[[ unsigned char*->array<char, 50> ][ !!! *1* !!! ][ 111 ][ 19 ][ 12 ]]
[[ unsigned char*->string ][ !!! *8* !!! ][ 125 ][ 30 ][ --- ]]
[[ unsigned char*->container::string ][ !!! *4* !!! ][ 121 ][ 23 ][ --- ]]
[[ signed char*->char ][ !!! *<1* !!! ][ 98 ][ 14 ][ 9 ]]
[[ signed char*->signed char ][ !!! *<1* !!! ][ 98 ][ 11 ][ 10 ]]
[[ signed char*->unsigned char ][ !!! *<1* !!! ][ 99 ][ 10 ][ 10 ]]
[[ signed char*->int ][ !!! *7* !!! ][ 111 ][ 22 ][ 24 ]]
[[ signed char*->short ][ !!! *6* !!! ][ 123 ][ 22 ][ 23 ]]
[[ signed char*->long int ][ !!! *8* !!! ][ 112 ][ 21 ][ 23 ]]
[[ signed char*->long long ][ !!! *8* !!! ][ 114 ][ 24 ][ 24 ]]
[[ signed char*->unsigned int ][ !!! *6* !!! ][ 114 ][ 19 ][ 22 ]]
[[ signed char*->unsigned short ][ !!! *6* !!! ][ 112 ][ 21 ][ 24 ]]
[[ signed char*->unsigned long int ][ !!! *8* !!! ][ 114 ][ 23 ][ 22 ]]
[[ signed char*->unsigned long long ][ !!! *8* !!! ][ 116 ][ 22 ][ 24 ]]
[[ signed char*->float ][ !!! *16* !!! ][ 156 ][ 55 ][ 38 ]]
[[ signed char*->double ][ !!! *12* !!! ][ 151 ][ 59 ][ 39 ]]
[[ signed char*->long double ][ 111 ][ 159 ][ 60 ][ !!! *44* !!! ]]
[[ signed char*->array<char, 50> ][ !!! *1* !!! ][ 107 ][ 24 ][ 12 ]]
[[ signed char*->string ][ !!! *8* !!! ][ 122 ][ 28 ][ --- ]]
[[ signed char*->container::string ][ !!! *4* !!! ][ 122 ][ 23 ][ --- ]]
[[ iterator_range<char*>->char ][ !!! *<1* !!! ][ 103 ][ 13 ][ 10 ]]
[[ iterator_range<char*>->signed char ][ !!! *<1* !!! ][ 103 ][ 13 ][ 10 ]]
[[ iterator_range<char*>->unsigned char ][ !!! *<1* !!! ][ 104 ][ 14 ][ 10 ]]
[[ iterator_range<char*>->int ][ !!! *6* !!! ][ 115 ][ 23 ][ 24 ]]
[[ iterator_range<char*>->short ][ !!! *7* !!! ][ 111 ][ 21 ][ 24 ]]
[[ iterator_range<char*>->long int ][ !!! *7* !!! ][ 108 ][ 21 ][ 23 ]]
[[ iterator_range<char*>->long long ][ !!! *7* !!! ][ 114 ][ 24 ][ 23 ]]
[[ iterator_range<char*>->unsigned int ][ !!! *6* !!! ][ 111 ][ 22 ][ 23 ]]
[[ iterator_range<char*>->unsigned short ][ !!! *5* !!! ][ 114 ][ 20 ][ 23 ]]
[[ iterator_range<char*>->unsigned long int ][ !!! *7* !!! ][ 119 ][ 25 ][ 24 ]]
[[ iterator_range<char*>->unsigned long long ][ !!! *7* !!! ][ 110 ][ 20 ][ 24 ]]
[[ iterator_range<char*>->float ][ !!! *15* !!! ][ 148 ][ 38 ][ 40 ]]
[[ iterator_range<char*>->double ][ !!! *10* !!! ][ 146 ][ 41 ][ 40 ]]
[[ iterator_range<char*>->long double ][ 103 ][ 138 ][ !!! *39* !!! ][ 42 ]]
[[ iterator_range<char*>->array<char, 50> ][ !!! *<1* !!! ][ 109 ][ 22 ][ 13 ]]
[[ iterator_range<char*>->string ][ !!! *7* !!! ][ 121 ][ 32 ][ --- ]]
[[ iterator_range<char*>->container::string ][ !!! *3* !!! ][ 120 ][ 24 ][ --- ]]
[[ array<char, 50>->char ][ !!! *<1* !!! ][ 102 ][ 9 ][ 9 ]]
[[ array<char, 50>->signed char ][ !!! *<1* !!! ][ 97 ][ 9 ][ 10 ]]
[[ array<char, 50>->unsigned char ][ !!! *<1* !!! ][ 99 ][ 9 ][ 10 ]]
[[ array<char, 50>->int ][ !!! *7* !!! ][ 114 ][ 22 ][ 23 ]]
[[ array<char, 50>->short ][ !!! *6* !!! ][ 116 ][ 21 ][ 23 ]]
[[ array<char, 50>->long int ][ !!! *7* !!! ][ 109 ][ 20 ][ 23 ]]
[[ array<char, 50>->long long ][ !!! *7* !!! ][ 114 ][ 21 ][ 23 ]]
[[ array<char, 50>->unsigned int ][ !!! *7* !!! ][ 119 ][ 20 ][ 25 ]]
[[ array<char, 50>->unsigned short ][ !!! *6* !!! ][ 120 ][ 20 ][ 23 ]]
[[ array<char, 50>->unsigned long int ][ !!! *7* !!! ][ 113 ][ 20 ][ 21 ]]
[[ array<char, 50>->unsigned long long ][ !!! *7* !!! ][ 112 ][ 20 ][ 24 ]]
[[ array<char, 50>->float ][ !!! *16* !!! ][ 155 ][ 57 ][ 38 ]]
[[ array<char, 50>->double ][ !!! *11* !!! ][ 152 ][ 59 ][ 42 ]]
[[ array<char, 50>->long double ][ 107 ][ 152 ][ 60 ][ !!! *41* !!! ]]
[[ array<char, 50>->array<char, 50> ][ !!! *1* !!! ][ 111 ][ 20 ][ 12 ]]
[[ array<char, 50>->string ][ !!! *8* !!! ][ 123 ][ 36 ][ --- ]]
[[ array<char, 50>->container::string ][ !!! *4* !!! ][ 128 ][ 23 ][ --- ]]
[[ int->int ][ !!! *<1* !!! ][ 118 ][ 26 ][ --- ]]
[[ float->double ][ !!! *<1* !!! ][ 233 ][ 120 ][ --- ]]
[[ char->signed char ][ !!! *<1* !!! ][ 97 ][ 8 ][ --- ]]
]
[endsect]
[section GNU C++ version 4.4.7]
[table:id Performance Table ( GNU C++ version 4.4.7)
[[From->To] [lexical_cast] [std::stringstream with construction] [std::stringstream without construction][scanf/printf]]
[[ string->char ][ !!! *<1* !!! ][ 111 ][ 8 ][ 9 ]]
[[ string->signed char ][ !!! *<1* !!! ][ 100 ][ 8 ][ 10 ]]
[[ string->unsigned char ][ !!! *<1* !!! ][ 102 ][ 8 ][ 11 ]]
[[ string->int ][ !!! *6* !!! ][ 114 ][ 21 ][ 23 ]]
[[ string->short ][ !!! *5* !!! ][ 120 ][ 21 ][ 29 ]]
[[ string->long int ][ !!! *7* !!! ][ 114 ][ 22 ][ 26 ]]
[[ string->long long ][ !!! *7* !!! ][ 118 ][ 21 ][ 23 ]]
[[ string->unsigned int ][ !!! *7* !!! ][ 115 ][ 21 ][ 23 ]]
[[ string->unsigned short ][ !!! *5* !!! ][ 119 ][ 18 ][ 22 ]]
[[ string->unsigned long int ][ !!! *7* !!! ][ 115 ][ 20 ][ 23 ]]
[[ string->unsigned long long ][ !!! *9* !!! ][ 116 ][ 26 ][ 24 ]]
[[ string->float ][ !!! *12* !!! ][ 165 ][ 53 ][ 40 ]]
[[ string->double ][ !!! *12* !!! ][ 154 ][ 54 ][ 40 ]]
[[ string->long double ][ 112 ][ 148 ][ 61 ][ !!! *45* !!! ]]
[[ string->array<char, 50> ][ !!! *<1* !!! ][ 120 ][ 19 ][ 14 ]]
[[ string->string ][ !!! *2* !!! ][ 141 ][ 55 ][ --- ]]
[[ string->container::string ][ !!! *2* !!! ][ 164 ][ 36 ][ --- ]]
[[ string->char ][ !!! *7* !!! ][ 161 ][ 24 ][ 18 ]]
[[ string->signed char ][ !!! *6* !!! ][ 109 ][ 25 ][ 24 ]]
[[ string->unsigned char ][ !!! *6* !!! ][ 109 ][ 25 ][ 25 ]]
[[ int->string ][ !!! *11* !!! ][ 128 ][ 32 ][ 23 ]]
[[ short->string ][ !!! *12* !!! ][ 136 ][ 54 ][ 34 ]]
[[ long int->string ][ !!! *15* !!! ][ 187 ][ 41 ][ 23 ]]
[[ long long->string ][ !!! *11* !!! ][ 128 ][ 30 ][ 29 ]]
[[ unsigned int->string ][ !!! *13* !!! ][ 124 ][ 29 ][ 23 ]]
[[ unsigned short->string ][ !!! *11* !!! ][ 128 ][ 30 ][ 22 ]]
[[ unsigned long int->string ][ !!! *11* !!! ][ 131 ][ 30 ][ 22 ]]
[[ unsigned long long->string ][ !!! *11* !!! ][ 133 ][ 33 ][ 29 ]]
[[ float->string ][ 52 ][ 187 ][ 90 ][ !!! *39* !!! ]]
[[ double->string ][ 58 ][ 190 ][ 86 ][ !!! *45* !!! ]]
[[ long double->string ][ 70 ][ 218 ][ 88 ][ !!! *47* !!! ]]
[[ char*->char ][ !!! *<1* !!! ][ 99 ][ 11 ][ 9 ]]
[[ char*->signed char ][ !!! *<1* !!! ][ 99 ][ 11 ][ 10 ]]
[[ char*->unsigned char ][ !!! *<1* !!! ][ 100 ][ 12 ][ 10 ]]
[[ char*->int ][ !!! *6* !!! ][ 117 ][ 23 ][ 21 ]]
[[ char*->short ][ !!! *6* !!! ][ 115 ][ 28 ][ 23 ]]
[[ char*->long int ][ !!! *7* !!! ][ 119 ][ 22 ][ 24 ]]
[[ char*->long long ][ !!! *7* !!! ][ 114 ][ 23 ][ 22 ]]
[[ char*->unsigned int ][ !!! *6* !!! ][ 113 ][ 21 ][ 21 ]]
[[ char*->unsigned short ][ !!! *6* !!! ][ 120 ][ 21 ][ 21 ]]
[[ char*->unsigned long int ][ !!! *7* !!! ][ 117 ][ 25 ][ 23 ]]
[[ char*->unsigned long long ][ !!! *7* !!! ][ 119 ][ 23 ][ 21 ]]
[[ char*->float ][ !!! *13* !!! ][ 160 ][ 61 ][ 36 ]]
[[ char*->double ][ !!! *13* !!! ][ 152 ][ 54 ][ 40 ]]
[[ char*->long double ][ 116 ][ 173 ][ 58 ][ !!! *43* !!! ]]
[[ char*->array<char, 50> ][ !!! *1* !!! ][ 121 ][ 20 ][ 12 ]]
[[ char*->string ][ !!! *7* !!! ][ 126 ][ 29 ][ --- ]]
[[ char*->container::string ][ !!! *2* !!! ][ 119 ][ 27 ][ --- ]]
[[ unsigned char*->char ][ !!! *<1* !!! ][ 96 ][ 12 ][ 9 ]]
[[ unsigned char*->signed char ][ !!! *<1* !!! ][ 95 ][ 11 ][ 12 ]]
[[ unsigned char*->unsigned char ][ !!! *<1* !!! ][ 95 ][ 12 ][ 12 ]]
[[ unsigned char*->int ][ !!! *6* !!! ][ 113 ][ 27 ][ 24 ]]
[[ unsigned char*->short ][ !!! *6* !!! ][ 120 ][ 23 ][ 21 ]]
[[ unsigned char*->long int ][ !!! *7* !!! ][ 114 ][ 22 ][ 23 ]]
[[ unsigned char*->long long ][ !!! *7* !!! ][ 114 ][ 23 ][ 23 ]]
[[ unsigned char*->unsigned int ][ !!! *6* !!! ][ 115 ][ 23 ][ 23 ]]
[[ unsigned char*->unsigned short ][ !!! *6* !!! ][ 120 ][ 21 ][ 23 ]]
[[ unsigned char*->unsigned long int ][ !!! *7* !!! ][ 117 ][ 23 ][ 21 ]]
[[ unsigned char*->unsigned long long ][ !!! *7* !!! ][ 121 ][ 23 ][ 21 ]]
[[ unsigned char*->float ][ !!! *12* !!! ][ 161 ][ 58 ][ 39 ]]
[[ unsigned char*->double ][ !!! *13* !!! ][ 153 ][ 54 ][ 38 ]]
[[ unsigned char*->long double ][ 110 ][ 150 ][ 62 ][ !!! *43* !!! ]]
[[ unsigned char*->array<char, 50> ][ !!! *1* !!! ][ 113 ][ 20 ][ 12 ]]
[[ unsigned char*->string ][ !!! *8* !!! ][ 124 ][ 30 ][ --- ]]
[[ unsigned char*->container::string ][ !!! *3* !!! ][ 118 ][ 27 ][ --- ]]
[[ signed char*->char ][ !!! *<1* !!! ][ 99 ][ 11 ][ 9 ]]
[[ signed char*->signed char ][ !!! *<1* !!! ][ 102 ][ 12 ][ 10 ]]
[[ signed char*->unsigned char ][ !!! *<1* !!! ][ 99 ][ 12 ][ 10 ]]
[[ signed char*->int ][ !!! *6* !!! ][ 114 ][ 30 ][ 23 ]]
[[ signed char*->short ][ !!! *6* !!! ][ 118 ][ 23 ][ 23 ]]
[[ signed char*->long int ][ !!! *7* !!! ][ 119 ][ 22 ][ 21 ]]
[[ signed char*->long long ][ !!! *7* !!! ][ 114 ][ 23 ][ 26 ]]
[[ signed char*->unsigned int ][ !!! *6* !!! ][ 114 ][ 26 ][ 23 ]]
[[ signed char*->unsigned short ][ !!! *6* !!! ][ 121 ][ 22 ][ 23 ]]
[[ signed char*->unsigned long int ][ !!! *7* !!! ][ 126 ][ 23 ][ 21 ]]
[[ signed char*->unsigned long long ][ !!! *7* !!! ][ 114 ][ 22 ][ 21 ]]
[[ signed char*->float ][ !!! *12* !!! ][ 163 ][ 57 ][ 39 ]]
[[ signed char*->double ][ !!! *13* !!! ][ 156 ][ 53 ][ 40 ]]
[[ signed char*->long double ][ 112 ][ 156 ][ 56 ][ !!! *42* !!! ]]
[[ signed char*->array<char, 50> ][ !!! *1* !!! ][ 117 ][ 20 ][ 12 ]]
[[ signed char*->string ][ !!! *8* !!! ][ 127 ][ 28 ][ --- ]]
[[ signed char*->container::string ][ !!! *4* !!! ][ 112 ][ 27 ][ --- ]]
[[ iterator_range<char*>->char ][ !!! *<1* !!! ][ 103 ][ 14 ][ 9 ]]
[[ iterator_range<char*>->signed char ][ !!! *<1* !!! ][ 104 ][ 16 ][ 10 ]]
[[ iterator_range<char*>->unsigned char ][ !!! *<1* !!! ][ 103 ][ 16 ][ 10 ]]
[[ iterator_range<char*>->int ][ !!! *6* !!! ][ 121 ][ 22 ][ 21 ]]
[[ iterator_range<char*>->short ][ !!! *7* !!! ][ 112 ][ 23 ][ 23 ]]
[[ iterator_range<char*>->long int ][ !!! *7* !!! ][ 115 ][ 24 ][ 23 ]]
[[ iterator_range<char*>->long long ][ !!! *7* !!! ][ 113 ][ 24 ][ 23 ]]
[[ iterator_range<char*>->unsigned int ][ !!! *6* !!! ][ 117 ][ 26 ][ 23 ]]
[[ iterator_range<char*>->unsigned short ][ !!! *5* !!! ][ 120 ][ 20 ][ 23 ]]
[[ iterator_range<char*>->unsigned long int ][ !!! *7* !!! ][ 124 ][ 28 ][ 21 ]]
[[ iterator_range<char*>->unsigned long long ][ !!! *7* !!! ][ 113 ][ 22 ][ 21 ]]
[[ iterator_range<char*>->float ][ !!! *11* !!! ][ 190 ][ 58 ][ 63 ]]
[[ iterator_range<char*>->double ][ !!! *20* !!! ][ 194 ][ 44 ][ 39 ]]
[[ iterator_range<char*>->long double ][ 116 ][ 145 ][ 46 ][ !!! *44* !!! ]]
[[ iterator_range<char*>->array<char, 50> ][ !!! *<1* !!! ][ 116 ][ 23 ][ 15 ]]
[[ iterator_range<char*>->string ][ !!! *7* !!! ][ 127 ][ 33 ][ --- ]]
[[ iterator_range<char*>->container::string ][ !!! *3* !!! ][ 112 ][ 24 ][ --- ]]
[[ array<char, 50>->char ][ !!! *<1* !!! ][ 98 ][ 11 ][ 10 ]]
[[ array<char, 50>->signed char ][ !!! *<1* !!! ][ 99 ][ 12 ][ 15 ]]
[[ array<char, 50>->unsigned char ][ !!! *<1* !!! ][ 100 ][ 11 ][ 10 ]]
[[ array<char, 50>->int ][ !!! *6* !!! ][ 114 ][ 27 ][ 22 ]]
[[ array<char, 50>->short ][ !!! *5* !!! ][ 113 ][ 23 ][ 23 ]]
[[ array<char, 50>->long int ][ !!! *7* !!! ][ 118 ][ 22 ][ 23 ]]
[[ array<char, 50>->long long ][ !!! *7* !!! ][ 114 ][ 26 ][ 23 ]]
[[ array<char, 50>->unsigned int ][ !!! *6* !!! ][ 113 ][ 27 ][ 23 ]]
[[ array<char, 50>->unsigned short ][ !!! *5* !!! ][ 124 ][ 21 ][ 23 ]]
[[ array<char, 50>->unsigned long int ][ !!! *7* !!! ][ 116 ][ 23 ][ 21 ]]
[[ array<char, 50>->unsigned long long ][ !!! *7* !!! ][ 115 ][ 22 ][ 21 ]]
[[ array<char, 50>->float ][ !!! *11* !!! ][ 162 ][ 58 ][ 36 ]]
[[ array<char, 50>->double ][ !!! *13* !!! ][ 155 ][ 54 ][ 44 ]]
[[ array<char, 50>->long double ][ 111 ][ 149 ][ 55 ][ !!! *42* !!! ]]
[[ array<char, 50>->array<char, 50> ][ !!! *1* !!! ][ 114 ][ 18 ][ 14 ]]
[[ array<char, 50>->string ][ !!! *7* !!! ][ 129 ][ 29 ][ --- ]]
[[ array<char, 50>->container::string ][ !!! *3* !!! ][ 113 ][ 26 ][ --- ]]
[[ int->int ][ !!! *<1* !!! ][ 114 ][ 25 ][ --- ]]
[[ float->double ][ !!! *<1* !!! ][ 236 ][ 121 ][ --- ]]
[[ char->signed char ][ !!! *<1* !!! ][ 97 ][ 8 ][ --- ]]
]
[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
@@ -1,35 +0,0 @@
// Copyright 2013 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
//[lexical_cast_args_example
//`The following example treats command line arguments as a sequence of numeric data
#include <boost/lexical_cast.hpp>
#include <vector>
int main(int /*argc*/, char * argv[])
{
using boost::lexical_cast;
using boost::bad_lexical_cast;
std::vector<short> args;
while (*++argv)
{
try
{
args.push_back(lexical_cast<short>(*argv));
}
catch(const bad_lexical_cast &)
{
args.push_back(0);
}
}
// ...
}
//] [/lexical_cast_args_example]
-61
View File
@@ -1,61 +0,0 @@
// Copyright 2013 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
//[lexical_cast_stringize
/*`
In this example we'll make a `stringize` method that accepts a sequence, converts
each element of the sequence into string and appends that string to the result.
Example is based on the example from the [@http://www.packtpub.com/boost-cplusplus-application-development-cookbook/book Boost C++ Application Development Cookbook]
by Antony Polukhin, ISBN 9781849514880.
Step 1: Making a functor that converts any type to a string and remembers result:
*/
#include <boost/lexical_cast.hpp>
struct stringize_functor {
private:
std::string& result;
public:
explicit stringize_functor(std::string& res)
: result(res)
{}
template <class T>
void operator()(const T& v) const {
result += boost::lexical_cast<std::string>(v);
}
};
//` Step 2: Applying `stringize_functor` to each element in sequence:
#include <boost/fusion/include/for_each.hpp>
template <class Sequence>
std::string stringize(const Sequence& seq) {
std::string result;
boost::fusion::for_each(seq, stringize_functor(result));
return result;
}
//` Step 3: Using the `stringize` with different types:
#include <cassert>
#include <boost/fusion/adapted/boost_tuple.hpp>
#include <boost/fusion/adapted/std_pair.hpp>
int main() {
boost::tuple<char, int, char, int> decim('-', 10, 'e', 5);
assert(stringize(decim) == "-10e5");
std::pair<short, std::string> value_and_type(270, "Kelvin");
assert(stringize(value_and_type) == "270Kelvin");
}
//] [/lexical_cast_stringize]
-52
View File
@@ -1,52 +0,0 @@
// Copyright 2013 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
#include <boost/lexical_cast.hpp>
#include <string>
#include <cstdio>
//[lexical_cast_log_errno
//`The following example uses numeric data in a string expression:
void log_message(const std::string &);
void log_errno(int yoko)
{
log_message("Error " + boost::lexical_cast<std::string>(yoko) + ": " + strerror(yoko));
}
//] [/lexical_cast_log_errno]
//[lexical_cast_fixed_buffer
//`The following example converts some number and puts it to file:
void number_to_file(int number, FILE* file)
{
typedef boost::array<char, 50> buf_t; // You can use std::array if your compiler supports it
buf_t buffer = boost::lexical_cast<buf_t>(number); // No dynamic memory allocation
fputs(buffer.begin(), file);
}
//] [/lexical_cast_fixed_buffer]
//[lexical_cast_substring_conversion
//`The following example takes part of the string and converts it to `int`:
int convert_strings_part(const std::string& s, std::size_t pos, std::size_t n)
{
return boost::lexical_cast<int>(s.data() + pos, n);
}
//] [/lexical_cast_substring_conversion]
void log_message(const std::string &) {}
int main()
{
return 0;
}
-39
View File
@@ -1,39 +0,0 @@
// Copyright 2013 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
//[lexical_cast_variant_to_long_double
/*`
In this example we'll make a `to_long_double` method that converts value of the Boost.Variant to `long double`.
*/
#include <boost/lexical_cast.hpp>
#include <boost/variant.hpp>
#include <cassert>
struct to_long_double_functor: boost::static_visitor<long double> {
template <class T>
long double operator()(const T& v) const {
// Lexical cast has many optimizations including optimizations for situations that usually
// occur in generic programming, like std::string to std::string or arithmetic type to arithmetic type conversion.
return boost::lexical_cast<long double>(v);
}
};
// Throws `boost::bad_lexical_cast` if value of the variant is not convertible to `long double`
template <class Variant>
long double to_long_double(const Variant& v) {
return boost::apply_visitor(to_long_double_functor(), v);
}
int main() {
boost::variant<char, int, std::string> v1('0'), v2("10.0001"), v3(1);
long double sum = to_long_double(v1) + to_long_double(v2) + to_long_double(v3);
assert(sum > 11 && sum < 11.1);
}
//] [/lexical_cast_variant_to_long_double]
-184
View File
@@ -1,184 +0,0 @@
// Copyright Alexander Nasonov & Paul A. Bristow 2006.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
#define BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
#include <climits>
#include <ios>
#include <limits>
#include <boost/config.hpp>
#include <boost/integer_traits.hpp>
#ifndef BOOST_NO_IS_ABSTRACT
// Fix for SF:1358600 - lexical_cast & pure virtual functions & VC 8 STL
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_abstract.hpp>
#endif
#if defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || \
(defined(BOOST_MSVC) && (BOOST_MSVC<1310))
#define BOOST_LCAST_NO_COMPILE_TIME_PRECISION
#endif
#ifdef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
#include <boost/assert.hpp>
#else
#include <boost/static_assert.hpp>
#endif
namespace boost { namespace detail {
class lcast_abstract_stub {};
#ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
// Calculate an argument to pass to std::ios_base::precision from
// lexical_cast. See alternative implementation for broken standard
// libraries in lcast_get_precision below. Keep them in sync, please.
template<class T>
struct lcast_precision
{
#ifdef BOOST_NO_IS_ABSTRACT
typedef std::numeric_limits<T> limits; // No fix for SF:1358600.
#else
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
boost::is_abstract<T>
, std::numeric_limits<lcast_abstract_stub>
, std::numeric_limits<T>
>::type limits;
#endif
BOOST_STATIC_CONSTANT(bool, use_default_precision =
!limits::is_specialized || limits::is_exact
);
BOOST_STATIC_CONSTANT(bool, is_specialized_bin =
!use_default_precision &&
limits::radix == 2 && limits::digits > 0
);
BOOST_STATIC_CONSTANT(bool, is_specialized_dec =
!use_default_precision &&
limits::radix == 10 && limits::digits10 > 0
);
BOOST_STATIC_CONSTANT(std::streamsize, streamsize_max =
boost::integer_traits<std::streamsize>::const_max
);
BOOST_STATIC_CONSTANT(unsigned int, precision_dec = limits::digits10 + 1U);
BOOST_STATIC_ASSERT(!is_specialized_dec ||
precision_dec <= streamsize_max + 0UL
);
BOOST_STATIC_CONSTANT(unsigned long, precision_bin =
2UL + limits::digits * 30103UL / 100000UL
);
BOOST_STATIC_ASSERT(!is_specialized_bin ||
(limits::digits + 0UL < ULONG_MAX / 30103UL &&
precision_bin > limits::digits10 + 0UL &&
precision_bin <= streamsize_max + 0UL)
);
BOOST_STATIC_CONSTANT(std::streamsize, value =
is_specialized_bin ? precision_bin
: is_specialized_dec ? precision_dec : 6
);
};
#endif
template<class T>
inline std::streamsize lcast_get_precision(T* = 0)
{
#ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
return lcast_precision<T>::value;
#else // Follow lcast_precision algorithm at run-time:
#ifdef BOOST_NO_IS_ABSTRACT
typedef std::numeric_limits<T> limits; // No fix for SF:1358600.
#else
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
boost::is_abstract<T>
, std::numeric_limits<lcast_abstract_stub>
, std::numeric_limits<T>
>::type limits;
#endif
bool const use_default_precision =
!limits::is_specialized || limits::is_exact;
if(!use_default_precision)
{ // Includes all built-in floating-point types, float, double ...
// and UDT types for which digits (significand bits) is defined (not zero)
bool const is_specialized_bin =
limits::radix == 2 && limits::digits > 0;
bool const is_specialized_dec =
limits::radix == 10 && limits::digits10 > 0;
std::streamsize const streamsize_max =
(boost::integer_traits<std::streamsize>::max)();
if(is_specialized_bin)
{ // Floating-point types with
// limits::digits defined by the specialization.
unsigned long const digits = limits::digits;
unsigned long const precision = 2UL + digits * 30103UL / 100000UL;
// unsigned long is selected because it is at least 32-bits
// and thus ULONG_MAX / 30103UL is big enough for all types.
BOOST_ASSERT(
digits < ULONG_MAX / 30103UL &&
precision > limits::digits10 + 0UL &&
precision <= streamsize_max + 0UL
);
return precision;
}
else if(is_specialized_dec)
{ // Decimal Floating-point type, most likely a User Defined Type
// rather than a real floating-point hardware type.
unsigned int const precision = limits::digits10 + 1U;
BOOST_ASSERT(precision <= streamsize_max + 0UL);
return precision;
}
}
// Integral type (for which precision has no effect)
// or type T for which limits is NOT specialized,
// so assume stream precision remains the default 6 decimal digits.
// Warning: if your User-defined Floating-point type T is NOT specialized,
// then you may lose accuracy by only using 6 decimal digits.
// To avoid this, you need to specialize T with either
// radix == 2 and digits == the number of significand bits,
// OR
// radix = 10 and digits10 == the number of decimal digits.
return 6;
#endif
}
template<class T>
inline void lcast_set_precision(std::ios_base& stream, T*)
{
stream.precision(lcast_get_precision<T>());
}
template<class Source, class Target>
inline void lcast_set_precision(std::ios_base& stream, Source*, Target*)
{
std::streamsize const s = lcast_get_precision(static_cast<Source*>(0));
std::streamsize const t = lcast_get_precision(static_cast<Target*>(0));
stream.precision(s > t ? s : t);
}
}}
#endif // BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
+18 -9
View File
@@ -2,28 +2,37 @@
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef IMPLICIT_CAST_DWA200356_HPP
# define IMPLICIT_CAST_DWA200356_HPP
# include <boost/mpl/identity.hpp>
#ifndef BOOST_IMPLICIT_CAST_DWA200356_HPP
#define BOOST_IMPLICIT_CAST_DWA200356_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
namespace boost {
namespace detail {
template<class T> struct icast_identity
{
using type = T;
};
} // namespace detail
// implementation originally suggested by C. Green in
// http://lists.boost.org/MailArchives/boost/msg00886.php
// The use of identity creates a non-deduced form, so that the
// explicit template argument must be supplied
template <typename T>
inline T implicit_cast (typename mpl::identity<T>::type x) {
constexpr T implicit_cast (typename boost::detail::icast_identity<T>::type x) {
return x;
}
// incomplete return type now is here
//template <typename T>
//void implicit_cast (...);
} // namespace boost
#endif // IMPLICIT_CAST_DWA200356_HPP
#endif // BOOST_IMPLICIT_CAST_DWA200356_HPP
File diff suppressed because it is too large Load Diff
@@ -1,6 +1,7 @@
// boost cast.hpp header file ----------------------------------------------//
// boost polymorphic_cast.hpp header file ----------------------------------------------//
// (C) Copyright Kevlin Henney and Dave Abrahams 1999.
// (C) Copyright Boris Rasin 2014.
// 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)
@@ -8,7 +9,12 @@
// See http://www.boost.org/libs/conversion for Documentation.
// Revision History
// 23 JUn 05 numeric_cast removed and redirected to the new verion (Fernando Cacciola)
// 10 Nov 14 polymorphic_pointer_downcast moved to a separate header,
// minor improvements to stisfy latest Boost coding style
// 08 Nov 14 Add polymorphic_pointer_downcast (Boris Rasin)
// 09 Jun 14 "cast.hpp" was renamed to "polymorphic_cast.hpp" and
// inclusion of numeric_cast was removed (Antony Polukhin)
// 23 Jun 05 numeric_cast removed and redirected to the new version (Fernando Cacciola)
// 02 Apr 01 Removed BOOST_NO_LIMITS workarounds and included
// <boost/limits.hpp> instead (the workaround did not
// actually compile when BOOST_NO_LIMITS was defined in
@@ -25,7 +31,7 @@
// 19 Oct 00 Fix numeric_cast for floating-point types (Dave Abrahams)
// 15 Jul 00 Suppress numeric_cast warnings for GCC, Borland and MSVC
// (Dave Abrahams)
// 30 Jun 00 More MSVC6 wordarounds. See comments below. (Dave Abrahams)
// 30 Jun 00 More MSVC6 workarounds. See comments below. (Dave Abrahams)
// 28 Jun 00 Removed implicit_cast<>. See comment below. (Beman Dawes)
// 27 Jun 00 More MSVC6 workarounds
// 15 Jun 00 Add workarounds for MSVC6
@@ -40,26 +46,27 @@
// place in nested namespace.
// 3 Aug 99 Initial version
#ifndef BOOST_CAST_HPP
#define BOOST_CAST_HPP
#ifndef BOOST_POLYMORPHIC_CAST_HPP
#define BOOST_POLYMORPHIC_CAST_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
# include <boost/config.hpp>
# include <boost/assert.hpp>
# include <typeinfo>
# include <boost/type.hpp>
# include <boost/limits.hpp>
# include <boost/detail/select_type.hpp>
# include <boost/throw_exception.hpp>
// It has been demonstrated numerous times that MSVC 6.0 fails silently at link
// time if you use a template function which has template parameters that don't
// appear in the function's argument list.
//
// TODO: Add this to config.hpp?
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
# else
# define BOOST_EXPLICIT_DEFAULT_TARGET
# endif
# include <memory> // std::addressof
# include <typeinfo>
# include <type_traits>
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
#define BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST constexpr
#else
#define BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST inline
#endif
namespace boost
{
@@ -73,16 +80,16 @@ namespace boost
// section 15.8 exercise 1, page 425.
template <class Target, class Source>
inline Target polymorphic_cast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST Target polymorphic_cast(Source* x)
{
Target tmp = dynamic_cast<Target>(x);
if ( tmp == 0 ) throw std::bad_cast();
if ( tmp == 0 ) boost::throw_exception( std::bad_cast() );
return tmp;
}
// polymorphic_downcast ----------------------------------------------------//
// BOOST_ASSERT() checked polymorphic downcast. Crosscasts prohibited.
// BOOST_ASSERT() checked raw pointer polymorphic downcast. Crosscasts prohibited.
// WARNING: Because this cast uses BOOST_ASSERT(), it violates
// the One Definition Rule if used in multiple translation units
@@ -92,16 +99,34 @@ namespace boost
// Contributed by Dave Abrahams
template <class Target, class Source>
inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST Target polymorphic_downcast(Source* x)
{
BOOST_ASSERT( dynamic_cast<Target>(x) == x ); // detect logic error
return static_cast<Target>(x);
}
# undef BOOST_EXPLICIT_DEFAULT_TARGET
// BOOST_ASSERT() checked reference polymorphic downcast. Crosscasts prohibited.
// WARNING: Because this cast uses BOOST_ASSERT(), it violates
// the One Definition Rule if used in multiple translation units
// where BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER
// NDEBUG are defined inconsistently.
// Contributed by Julien Delacroix
template <class Target, class Source>
BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST typename std::enable_if<
std::is_reference<Target>::value, Target
>::type polymorphic_downcast(Source& x)
{
using target_pointer_type = typename std::remove_reference<Target>::type*;
return *boost::polymorphic_downcast<target_pointer_type>(
std::addressof(x)
);
}
} // namespace boost
# include <boost/numeric/conversion/cast.hpp>
#undef BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST
#endif // BOOST_CAST_HPP
#endif // BOOST_POLYMORPHIC_CAST_HPP
@@ -0,0 +1,60 @@
// boost polymorphic_pointer_cast.hpp header file ----------------------------------------------//
// (C) Copyright Boris Rasin, 2014-2021.
// (C) Copyright Antony Polukhin, 2014-2026.
// 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)
// See http://www.boost.org/libs/conversion for Documentation.
#ifndef BOOST_CONVERSION_POLYMORPHIC_POINTER_CAST_HPP
#define BOOST_CONVERSION_POLYMORPHIC_POINTER_CAST_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
# include <boost/assert.hpp>
# include <boost/pointer_cast.hpp>
# include <boost/throw_exception.hpp>
namespace boost
{
// See the documentation for descriptions of how to choose between
// static_pointer_cast<>, dynamic_pointer_cast<>, polymorphic_pointer_cast<> and polymorphic_pointer_downcast<>
// polymorphic_pointer_downcast --------------------------------------------//
// BOOST_ASSERT() checked polymorphic downcast. Crosscasts prohibited.
// Supports any type with static_pointer_cast/dynamic_pointer_cast functions:
// built-in pointers, std::shared_ptr, boost::shared_ptr, boost::intrusive_ptr, etc.
// WARNING: Because this cast uses BOOST_ASSERT(), it violates
// the One Definition Rule if used in multiple translation units
// where BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER
// NDEBUG are defined inconsistently.
// Contributed by Boris Rasin
template <typename Target, typename Source>
inline auto polymorphic_pointer_downcast (const Source& x)
-> decltype(static_pointer_cast<Target>(x))
{
BOOST_ASSERT(dynamic_pointer_cast<Target> (x) == x);
return static_pointer_cast<Target> (x);
}
template <typename Target, typename Source>
inline auto polymorphic_pointer_cast (const Source& x)
-> decltype(dynamic_pointer_cast<Target>(x))
{
auto tmp = dynamic_pointer_cast<Target> (x);
if ( !tmp ) boost::throw_exception( std::bad_cast() );
return tmp;
}
} // namespace boost
#endif // BOOST_CONVERSION_POLYMORPHIC_POINTER_CAST_HPP
+32 -42
View File
@@ -1,49 +1,39 @@
<html>
<!DOCTYPE html>
<!--
Copyright (c) 2016 Mikhail Maximov
vigorous.activity at gmail dot com
Copyright (c) Antony Polukhin, 2021-2026
Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at http://boost.org/LICENSE_1_0.txt)
boost-no-inspect
-->
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Boost Conversion Library</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=../../doc/html/conversion.html">
<title>Boost.Conversion</title>
<style>
.copyright
{
color: #666666;
font-size: small;
}
body {
background: #fff;
color: #000;
}
a {
color: #00f;
text-decoration: none;
}
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1><img border="0" src="../../boost.png" align="center" width="277" height="86">Boost
Conversion Library</h1>
<p>The Conversion Library improves program safety and clarity by performing
otherwise messy conversions.&nbsp; It includes cast-style function templates designed to complement the C++
Standard's built-in casts.</p>
<p>To reduce coupling, particularly to standard library IOStreams, the Boost
Conversion Library is
supplied by several headers:</p>
<ul>
<li>The <a href="cast.htm">boost/cast</a> header provides <b>polymorphic_cast&lt;&gt;</b>
and <b>polymorphic_downcast&lt;&gt;</b> to perform safe casting between
polymorphic types.<br>
</li>
<li>The <a href="../../doc/html/boost_lexical_cast.html">boost/lexical_cast</a> header provides <b>lexical_cast&lt;&gt;</b>
general literal text conversions, such as an <code>int</code> represented as
a <code>string</code>, or vice-versa.</li>
</ul>
<hr>
<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>
<p>
Automatic redirection failed, please go to
<a href="../../doc/html/conversion.html">../../doc/html/conversion.html</a>
</p>
<p>
&copy; Antony Polukhin, 2014-2024
</p>
</body>
</html>
-16
View File
@@ -1,16 +0,0 @@
<!--
Copyright 2005-2007 Daniel James.
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)
-->
<html>
<head>
<meta http-equiv="refresh" content="0; URL=../../doc/html/boost_lexical_cast.html">
</head>
<body>
Automatic redirection failed, please go to
<a href="../../doc/html/boost_lexical_cast.html">../../doc/html/boost_lexical_cast.html</a>
</body>
</html>
-622
View File
@@ -1,622 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Terje Sletteb and Kevlin Henney, 2005.
// Copyright Alexander Nasonov, 2006.
// Copyright Antony Polukhin, 2011-2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
//
// Note: The unit test no longer compile on MSVC 6, but lexical_cast itself works for it.
//
// We need this #define before any #includes: otherwise msvc will emit warnings
// deep within std::string, resulting from our (perfectly legal) use of basic_string
// with a custom traits class:
//
#define _SCL_SECURE_NO_WARNINGS
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#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)) \
&& !(defined(BOOST_MSVC) && BOOST_MSVC < 1300)
#define LCAST_TEST_LONGLONG
#endif
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
template<class CharT>
struct my_traits : std::char_traits<CharT>
{
};
template<class CharT>
struct my_allocator : std::allocator<CharT>
{
};
using namespace boost;
void test_conversion_to_char();
void test_conversion_to_int();
void test_conversion_to_double();
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_from_wchar_t();
void test_conversion_to_wchar_t();
void test_conversion_from_wstring();
void test_conversion_to_wstring();
void test_bad_lexical_cast();
void test_no_whitespace_stripping();
void test_volatile_types_conversions();
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
void test_traits();
void test_wtraits();
void test_allocator();
void test_wallocator();
#endif
void test_char_types_conversions();
void operators_overload_test();
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
void test_char16_conversions();
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
void test_char32_conversions();
#endif
void test_getting_pointer_to_function();
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_conversion_to_char));
suite->add(BOOST_TEST_CASE(test_conversion_to_int));
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_string));
suite->add(BOOST_TEST_CASE(test_conversion_with_nonconst_char));
#ifndef BOOST_LCAST_NO_WCHAR_T
suite->add(BOOST_TEST_CASE(test_conversion_from_wchar_t));
suite->add(BOOST_TEST_CASE(test_conversion_to_wchar_t));
suite->add(BOOST_TEST_CASE(test_conversion_from_wstring));
suite->add(BOOST_TEST_CASE(test_conversion_to_wstring));
#endif
suite->add(BOOST_TEST_CASE(test_bad_lexical_cast));
suite->add(BOOST_TEST_CASE(test_no_whitespace_stripping));
suite->add(BOOST_TEST_CASE(test_volatile_types_conversions));
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
suite->add(BOOST_TEST_CASE(&test_traits));
suite->add(BOOST_TEST_CASE(&test_wtraits));
suite->add(BOOST_TEST_CASE(&test_allocator));
suite->add(BOOST_TEST_CASE(&test_wallocator));
#endif
suite->add(BOOST_TEST_CASE(&test_char_types_conversions));
suite->add(BOOST_TEST_CASE(&operators_overload_test));
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
suite->add(BOOST_TEST_CASE(&test_char16_conversions));
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
suite->add(BOOST_TEST_CASE(&test_char32_conversions));
#endif
suite->add(BOOST_TEST_CASE(&test_getting_pointer_to_function));
return suite;
}
void test_conversion_to_char()
{
BOOST_CHECK_EQUAL('A', lexical_cast<char>('A'));
BOOST_CHECK_EQUAL(' ', lexical_cast<char>(' '));
BOOST_CHECK_EQUAL('1', lexical_cast<char>(1));
BOOST_CHECK_EQUAL('0', lexical_cast<char>(0));
BOOST_CHECK_THROW(lexical_cast<char>(123), bad_lexical_cast);
BOOST_CHECK_EQUAL('1', lexical_cast<char>(1.0));
BOOST_CHECK_EQUAL('1', lexical_cast<char>(true));
BOOST_CHECK_EQUAL('0', lexical_cast<char>(false));
BOOST_CHECK_EQUAL('A', lexical_cast<char>("A"));
BOOST_CHECK_EQUAL(' ', lexical_cast<char>(" "));
BOOST_CHECK_THROW(lexical_cast<char>(""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<char>("Test"), bad_lexical_cast);
BOOST_CHECK_EQUAL('A', lexical_cast<char>(std::string("A")));
BOOST_CHECK_EQUAL(' ', lexical_cast<char>(std::string(" ")));
BOOST_CHECK_THROW(
lexical_cast<char>(std::string("")), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<char>(std::string("Test")), bad_lexical_cast);
}
void test_conversion_to_int()
{
BOOST_CHECK_EQUAL(1, lexical_cast<int>('1'));
BOOST_CHECK_EQUAL(0, lexical_cast<int>('0'));
BOOST_CHECK_THROW(lexical_cast<int>('A'), bad_lexical_cast);
BOOST_CHECK_EQUAL(1, lexical_cast<int>(1));
BOOST_CHECK_EQUAL(1, lexical_cast<int>(1.0));
BOOST_CHECK_EQUAL(
(std::numeric_limits<int>::max)(),
lexical_cast<int>((std::numeric_limits<int>::max)()));
BOOST_CHECK_EQUAL(
(std::numeric_limits<int>::min)(),
lexical_cast<int>((std::numeric_limits<int>::min)()));
BOOST_CHECK_THROW(lexical_cast<int>(1.23), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<int>(1e20), bad_lexical_cast);
BOOST_CHECK_EQUAL(1, lexical_cast<int>(true));
BOOST_CHECK_EQUAL(0, lexical_cast<int>(false));
BOOST_CHECK_EQUAL(123, lexical_cast<int>("123"));
BOOST_CHECK_THROW(
lexical_cast<int>(" 123"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<int>(""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<int>("Test"), bad_lexical_cast);
BOOST_CHECK_EQUAL(123, lexical_cast<int>("123"));
BOOST_CHECK_EQUAL(123, lexical_cast<int>(std::string("123")));
BOOST_CHECK_THROW(
lexical_cast<int>(std::string(" 123")), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<int>(std::string("")), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<int>(std::string("Test")), bad_lexical_cast);
}
void test_conversion_with_nonconst_char()
{
std::vector<char> buffer;
buffer.push_back('1');
buffer.push_back('\0');
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(&buffer[0]), 1);
std::vector<unsigned char> buffer2;
buffer2.push_back('1');
buffer2.push_back('\0');
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(&buffer2[0]), 1);
std::vector<unsigned char> buffer3;
buffer3.push_back('1');
buffer3.push_back('\0');
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(&buffer3[0]), 1);
#ifndef BOOST_LCAST_NO_WCHAR_T
std::vector<wchar_t> buffer4;
buffer4.push_back(L'1');
buffer4.push_back(L'\0');
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(&buffer4[0]), 1);
#endif
}
void test_conversion_to_double()
{
BOOST_CHECK_CLOSE_FRACTION(1.0, lexical_cast<double>('1'), (std::numeric_limits<double>::epsilon()));
BOOST_CHECK_THROW(lexical_cast<double>('A'), bad_lexical_cast);
BOOST_CHECK_CLOSE_FRACTION(1.0, lexical_cast<double>(1), (std::numeric_limits<double>::epsilon()));
BOOST_CHECK_CLOSE_FRACTION(1.23, lexical_cast<double>(1.23), (std::numeric_limits<double>::epsilon()));
BOOST_CHECK_CLOSE_FRACTION(1.234567890, lexical_cast<double>(1.234567890), std::numeric_limits<double>::epsilon());
BOOST_CHECK_CLOSE_FRACTION(1.234567890, lexical_cast<double>("1.234567890"), std::numeric_limits<double>::epsilon());
BOOST_CHECK_CLOSE_FRACTION(1.0, lexical_cast<double>(true), (std::numeric_limits<double>::epsilon()));
BOOST_CHECK_CLOSE_FRACTION(0.0, lexical_cast<double>(false), (std::numeric_limits<double>::epsilon()));
BOOST_CHECK_CLOSE_FRACTION(1.23, lexical_cast<double>("1.23"), (std::numeric_limits<double>::epsilon()));
BOOST_CHECK_THROW(lexical_cast<double>(""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<double>("Test"), bad_lexical_cast);
BOOST_CHECK_CLOSE_FRACTION(1.23, lexical_cast<double>(std::string("1.23")), (std::numeric_limits<double>::epsilon()));
BOOST_CHECK_THROW(
lexical_cast<double>(std::string("")), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<double>(std::string("Test")), bad_lexical_cast);
}
void test_conversion_to_bool()
{
BOOST_CHECK_EQUAL(true, lexical_cast<bool>('1'));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>('0'));
BOOST_CHECK_THROW(lexical_cast<bool>('A'), bad_lexical_cast);
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(1));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(0));
BOOST_CHECK_THROW(lexical_cast<bool>(123), bad_lexical_cast);
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(1.0));
BOOST_CHECK_THROW(lexical_cast<bool>(-123), bad_lexical_cast);
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(0.0));
BOOST_CHECK_THROW(lexical_cast<bool>(1234), bad_lexical_cast);
#if !defined(_CRAYC)
// Looks like a bug in CRAY compiler (throws bad_lexical_cast)
// TODO: localize the bug and report it to developers.
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(true));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(false));
#endif
BOOST_CHECK_EQUAL(true, lexical_cast<bool>("1"));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>("0"));
BOOST_CHECK_THROW(lexical_cast<bool>(""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<bool>("Test"), bad_lexical_cast);
BOOST_CHECK_EQUAL(true, lexical_cast<bool>("1"));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>("0"));
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(std::string("1")));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(std::string("0")));
BOOST_CHECK_THROW(lexical_cast<bool>(1.0001L), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<bool>(2), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<bool>(2u), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<bool>(-1), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<bool>(-2), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<bool>(std::string("")), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<bool>(std::string("Test")), bad_lexical_cast);
BOOST_CHECK(lexical_cast<bool>("+1") == true );
BOOST_CHECK(lexical_cast<bool>("+0") == false );
BOOST_CHECK(lexical_cast<bool>("-0") == false );
BOOST_CHECK_THROW(lexical_cast<bool>("--0"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<bool>("-+-0"), bad_lexical_cast);
}
void test_conversion_to_string()
{
char buf[] = "hello";
char* str = buf;
BOOST_CHECK_EQUAL(str, lexical_cast<std::string>(str));
BOOST_CHECK_EQUAL("A", lexical_cast<std::string>('A'));
BOOST_CHECK_EQUAL(" ", lexical_cast<std::string>(' '));
BOOST_CHECK_EQUAL("123", lexical_cast<std::string>(123));
BOOST_CHECK_EQUAL("1.23", lexical_cast<std::string>(1.23));
BOOST_CHECK_EQUAL("1.111111111", lexical_cast<std::string>(1.111111111));
BOOST_CHECK_EQUAL("1", lexical_cast<std::string>(true));
BOOST_CHECK_EQUAL("0", lexical_cast<std::string>(false));
BOOST_CHECK_EQUAL("Test", lexical_cast<std::string>("Test"));
BOOST_CHECK_EQUAL(" ", lexical_cast<std::string>(" "));
BOOST_CHECK_EQUAL("", lexical_cast<std::string>(""));
BOOST_CHECK_EQUAL("Test", lexical_cast<std::string>(std::string("Test")));
BOOST_CHECK_EQUAL(" ", lexical_cast<std::string>(std::string(" ")));
BOOST_CHECK_EQUAL("", lexical_cast<std::string>(std::string("")));
}
void test_conversion_from_to_wchar_t_alias()
{
BOOST_CHECK_EQUAL(123u, lexical_cast<unsigned short>("123"));
BOOST_CHECK_EQUAL(123u, lexical_cast<unsigned int>("123"));
BOOST_CHECK_EQUAL(123u, lexical_cast<unsigned long>("123"));
BOOST_CHECK_EQUAL(std::string("123"),
lexical_cast<std::string>(static_cast<unsigned short>(123)));
BOOST_CHECK_EQUAL(std::string("123"), lexical_cast<std::string>(123u));
BOOST_CHECK_EQUAL(std::string("123"), lexical_cast<std::string>(123ul));
}
void test_conversion_from_wchar_t()
{
#ifndef BOOST_LCAST_NO_WCHAR_T
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_CHECK_EQUAL(1, lexical_cast<int>(L'1'));
BOOST_CHECK_THROW(lexical_cast<int>(L'A'), bad_lexical_cast);
#endif
BOOST_CHECK_EQUAL(123, lexical_cast<int>(L"123"));
BOOST_CHECK_THROW(lexical_cast<int>(L""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<int>(L"Test"), bad_lexical_cast);
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_CHECK_EQUAL(1.0, lexical_cast<double>(L'1'));
BOOST_CHECK_THROW(lexical_cast<double>(L'A'), bad_lexical_cast);
#endif
BOOST_CHECK_EQUAL(1.23, lexical_cast<double>(L"1.23"));
BOOST_CHECK_THROW(lexical_cast<double>(L""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<double>(L"Test"), bad_lexical_cast);
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(L'1'));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(L'0'));
BOOST_CHECK_THROW(lexical_cast<bool>(L'A'), bad_lexical_cast);
#endif
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(L"1"));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(L"0"));
BOOST_CHECK_THROW(lexical_cast<bool>(L""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<bool>(L"Test"), bad_lexical_cast);
#endif
}
void test_conversion_to_wchar_t()
{
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>(1));
BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>(0));
BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>('1'));
BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>('0'));
BOOST_CHECK_THROW(lexical_cast<wchar_t>(123), bad_lexical_cast);
BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>(1.0));
BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>(0.0));
BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>(true));
BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>(false));
BOOST_CHECK_EQUAL(L'A', lexical_cast<wchar_t>(L'A'));
BOOST_CHECK_EQUAL(L' ', lexical_cast<wchar_t>(L' '));
BOOST_CHECK_EQUAL(L'A', lexical_cast<wchar_t>(L"A"));
BOOST_CHECK_EQUAL(L' ', lexical_cast<wchar_t>(L" "));
BOOST_CHECK_THROW(lexical_cast<wchar_t>(L""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<wchar_t>(L"Test"), bad_lexical_cast);
BOOST_CHECK_EQUAL(L'A', lexical_cast<wchar_t>(std::wstring(L"A")));
BOOST_CHECK_EQUAL(L' ', lexical_cast<wchar_t>(std::wstring(L" ")));
BOOST_CHECK_THROW(
lexical_cast<wchar_t>(std::wstring(L"")), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<wchar_t>(std::wstring(L"Test")), bad_lexical_cast);
#endif
BOOST_CHECK(true);
}
void test_conversion_from_wstring()
{
#ifndef BOOST_LCAST_NO_WCHAR_T
BOOST_CHECK_EQUAL(123, lexical_cast<int>(std::wstring(L"123")));
BOOST_CHECK_THROW(
lexical_cast<int>(std::wstring(L"")), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<int>(std::wstring(L"Test")), bad_lexical_cast);
BOOST_CHECK_EQUAL(true, lexical_cast<bool>(std::wstring(L"1")));
BOOST_CHECK_EQUAL(false, lexical_cast<bool>(std::wstring(L"0")));
BOOST_CHECK_THROW(
lexical_cast<bool>(std::wstring(L"")), bad_lexical_cast);
BOOST_CHECK_THROW(
lexical_cast<bool>(std::wstring(L"Test")), bad_lexical_cast);
#endif
BOOST_CHECK(true);
}
void test_conversion_to_wstring()
{
#ifndef BOOST_LCAST_NO_WCHAR_T
wchar_t buf[] = L"hello";
wchar_t* str = buf;
BOOST_CHECK(str == lexical_cast<std::wstring>(str));
BOOST_CHECK(L"123" == lexical_cast<std::wstring>(123));
BOOST_CHECK(L"1.23" == lexical_cast<std::wstring>(1.23));
BOOST_CHECK(L"1" == lexical_cast<std::wstring>(true));
BOOST_CHECK(L"0" == lexical_cast<std::wstring>(false));
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_CHECK(L"A" == lexical_cast<std::wstring>(L'A'));
BOOST_CHECK(L" " == lexical_cast<std::wstring>(L' '));
BOOST_CHECK(L"A" == lexical_cast<std::wstring>('A'));
#endif
BOOST_CHECK(L"Test" == lexical_cast<std::wstring>(L"Test"));
BOOST_CHECK(L" " == lexical_cast<std::wstring>(L" "));
BOOST_CHECK(L"" == lexical_cast<std::wstring>(L""));
BOOST_CHECK(L"Test" == lexical_cast<std::wstring>(std::wstring(L"Test")));
BOOST_CHECK(L" " == lexical_cast<std::wstring>(std::wstring(L" ")));
BOOST_CHECK(L"" == lexical_cast<std::wstring>(std::wstring(L"")));
#endif
BOOST_CHECK(true);
}
void test_bad_lexical_cast()
{
try
{
lexical_cast<int>(std::string("Test"));
BOOST_CHECK(false); // Exception expected
}
catch(const bad_lexical_cast &e)
{
BOOST_CHECK(e.source_type() == typeid(std::string));
BOOST_CHECK(e.target_type() == typeid(int));
}
}
void test_no_whitespace_stripping()
{
BOOST_CHECK_THROW(lexical_cast<int>(" 123"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<int>("123 "), bad_lexical_cast);
}
void test_volatile_types_conversions()
{
volatile int i1 = 100000;
BOOST_CHECK_EQUAL("100000", boost::lexical_cast<std::string>(i1));
volatile const int i2 = 100000;
BOOST_CHECK_EQUAL("100000", boost::lexical_cast<std::string>(i2));
volatile const long int i3 = 1000000;
BOOST_CHECK_EQUAL("1000000", boost::lexical_cast<std::string>(i3));
}
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
void test_traits()
{
typedef std::basic_string<char, my_traits<char> > my_string;
my_string const s("s");
BOOST_CHECK(boost::lexical_cast<char>(s) == s[0]);
BOOST_CHECK(boost::lexical_cast<my_string>(s) == s);
BOOST_CHECK(boost::lexical_cast<my_string>(-1) == "-1");
}
void test_wtraits()
{
typedef std::basic_string<wchar_t, my_traits<wchar_t> > my_string;
my_string const s(L"s");
BOOST_CHECK(boost::lexical_cast<wchar_t>(s) == s[0]);
BOOST_CHECK(boost::lexical_cast<my_string>(s) == s);
//BOOST_CHECK(boost::lexical_cast<my_string>(-1) == L"-1");
// Commented out because gcc 3.3 doesn't support this:
// basic_ostream<wchar_t, my_traits<wchar_t> > o; o << -1;
}
void test_allocator()
{
// Following test cause compilation error on MSVC2012:
// (Reason: cannot convert from 'std::_Wrap_alloc<_Alloc>' to 'const my_allocator<CharT>')
//
// MSVC developer is notified about this issue
#if !defined(_MSC_VER) || (_MSC_VER < 1700)
typedef std::basic_string< char
, std::char_traits<char>
, my_allocator<char>
> my_string;
my_string s("s");
BOOST_CHECK(boost::lexical_cast<char>(s) == s[0]);
BOOST_CHECK(boost::lexical_cast<std::string>(s) == "s");
BOOST_CHECK(boost::lexical_cast<my_string>(s) == s);
BOOST_CHECK(boost::lexical_cast<my_string>(1) == "1");
BOOST_CHECK(boost::lexical_cast<my_string>("s") == s);
BOOST_CHECK(boost::lexical_cast<my_string>(std::string("s")) == s);
#endif
}
void test_wallocator()
{
// Following test cause compilation error on MSVC2012:
// (Reason: cannot convert from 'std::_Wrap_alloc<_Alloc>' to 'const my_allocator<CharT>')
//
// MSVC developer is notified about this issue
#if !defined(_MSC_VER) || (_MSC_VER < 1700)
typedef std::basic_string< wchar_t
, std::char_traits<wchar_t>
, my_allocator<wchar_t>
> my_string;
my_string s(L"s");
BOOST_CHECK(boost::lexical_cast<wchar_t>(s) == s[0]);
BOOST_CHECK(boost::lexical_cast<std::wstring>(s) == L"s");
BOOST_CHECK(boost::lexical_cast<my_string>(s) == s);
BOOST_CHECK(boost::lexical_cast<my_string>(1) == L"1");
BOOST_CHECK(boost::lexical_cast<my_string>(L"s") == s);
BOOST_CHECK(boost::lexical_cast<my_string>(std::wstring(L"s")) == s);
#endif
}
#endif
void test_char_types_conversions()
{
const char c_arr[] = "Test array of chars";
const unsigned char uc_arr[] = "Test array of chars";
const signed char sc_arr[] = "Test array of chars";
BOOST_CHECK(boost::lexical_cast<std::string>(c_arr) == std::string(c_arr));
BOOST_CHECK(boost::lexical_cast<std::string>(uc_arr) == std::string(c_arr));
BOOST_CHECK(boost::lexical_cast<std::string>(sc_arr) == std::string(c_arr));
BOOST_CHECK(boost::lexical_cast<char>(c_arr[0]) == c_arr[0]);
BOOST_CHECK(boost::lexical_cast<char>(uc_arr[0]) == c_arr[0]);
BOOST_CHECK(boost::lexical_cast<char>(sc_arr[0]) == c_arr[0]);
BOOST_CHECK(boost::lexical_cast<unsigned char>(c_arr[0]) == uc_arr[0]);
BOOST_CHECK(boost::lexical_cast<unsigned char>(uc_arr[0]) == uc_arr[0]);
BOOST_CHECK(boost::lexical_cast<unsigned char>(sc_arr[0]) == uc_arr[0]);
BOOST_CHECK(boost::lexical_cast<signed char>(c_arr[0]) == sc_arr[0]);
BOOST_CHECK(boost::lexical_cast<signed char>(uc_arr[0]) == sc_arr[0]);
BOOST_CHECK(boost::lexical_cast<signed char>(sc_arr[0]) == sc_arr[0]);
#ifndef BOOST_LCAST_NO_WCHAR_T
const wchar_t wc_arr[]=L"Test array of chars";
BOOST_CHECK(boost::lexical_cast<std::wstring>(wc_arr) == std::wstring(wc_arr));
BOOST_CHECK(boost::lexical_cast<wchar_t>(wc_arr[0]) == wc_arr[0]);
#endif
}
struct foo_operators_test
{
foo_operators_test() : f(2) {}
int f;
};
template <typename OStream>
OStream& operator<<(OStream& ostr, const foo_operators_test& foo)
{
ostr << foo.f;
return ostr;
}
template <typename IStream>
IStream& operator>>(IStream& istr, foo_operators_test& foo)
{
istr >> foo.f;
return istr;
}
void operators_overload_test()
{
foo_operators_test foo;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(foo), "2");
BOOST_CHECK_EQUAL((boost::lexical_cast<foo_operators_test>("2")).f, 2);
// Must compile
(void)boost::lexical_cast<foo_operators_test>(foo);
}
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
void test_char16_conversions()
{
BOOST_CHECK(u"100" == lexical_cast<std::u16string>(u"100"));
BOOST_CHECK(u"1" == lexical_cast<std::u16string>(u'1'));
}
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
void test_char32_conversions()
{
BOOST_CHECK(U"100" == lexical_cast<std::u32string>(U"100"));
BOOST_CHECK(U"1" == lexical_cast<std::u32string>(U'1'));
}
#endif
void test_getting_pointer_to_function()
{
// Just checking that &lexical_cast<To, From> is not ambiguous
typedef char char_arr[4];
typedef int(*f1)(const char_arr&);
f1 p1 = &boost::lexical_cast<int, char_arr>;
BOOST_CHECK(p1);
typedef int(*f2)(const std::string&);
f2 p2 = &boost::lexical_cast<int, std::string>;
BOOST_CHECK(p2);
typedef std::string(*f3)(const int&);
f3 p3 = &boost::lexical_cast<std::string, int>;
BOOST_CHECK(p3);
std::vector<int> values;
std::vector<std::string> ret;
std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast<std::string, int>);
}
+16
View File
@@ -0,0 +1,16 @@
{
"key": "conversion",
"name": "Conversion",
"authors": [
"Dave Abrahams",
"Kevlin Henney"
],
"description": "Polymorphic casts.",
"category": [
"Miscellaneous"
],
"maintainers": [
"Antony Polukhin <antoshkka -at- gmail.com>"
],
"cxxstd": "11"
}
-101
View File
@@ -1,101 +0,0 @@
// boost utility cast test program -----------------------------------------//
// (C) Copyright Beman Dawes, Dave Abrahams 1999. 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)
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 28 Set 04 factored out numeric_cast<> test (Fernando Cacciola)
// 20 Jan 01 removed use of <limits> for portability to raw GCC (David Abrahams)
// 28 Jun 00 implicit_cast removed (Beman Dawes)
// 30 Aug 99 value_cast replaced by numeric_cast
// 3 Aug 99 Initial Version
#include <iostream>
#include <climits>
#include <cfloat> // for DBL_MAX (Peter Schmid)
#include <boost/cast.hpp>
#include "boost/test/minimal.hpp"
# if SCHAR_MAX == LONG_MAX
# error "This test program doesn't work if SCHAR_MAX == LONG_MAX"
# endif
using namespace boost;
using std::cout;
int test_main( int , char * [] )
{
# ifdef NDEBUG
cout << "NDEBUG is defined\n";
# else
cout << "NDEBUG is not defined\n";
# endif
cout << "\nBeginning tests...\n";
// test implicit_cast and numeric_cast -------------------------------------//
// tests which should succeed
long small_value = 1;
long small_negative_value = -1;
long large_value = LONG_MAX;
long large_negative_value = LONG_MIN;
signed char c = 0;
c = static_cast<signed char>(large_value);
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
c = 0;
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
c = 0;
c = numeric_cast<signed char>( small_negative_value );
BOOST_CHECK( c == -1 );
// These tests courtesy of Joe R NWP Swatosh<joe.r.swatosh@usace.army.mil>
BOOST_CHECK( 0.0f == numeric_cast<float>( 0.0 ) );
BOOST_CHECK( 0.0 == numeric_cast<double>( 0.0 ) );
// tests which should result in errors being detected
bool caught_exception = false;
try { c = numeric_cast<signed char>( large_value ); }
catch (bad_numeric_cast)
{ cout<<"caught bad_numeric_cast #1\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
caught_exception = false;
try { c = numeric_cast<signed char>( large_negative_value ); }
catch (bad_numeric_cast)
{ cout<<"caught bad_numeric_cast #2\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
unsigned long ul;
caught_exception = false;
try { ul = numeric_cast<unsigned long>( large_negative_value ); }
catch (bad_numeric_cast)
{ cout<<"caught bad_numeric_cast #3\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
caught_exception = false;
try { ul = numeric_cast<unsigned long>( small_negative_value ); }
catch (bad_numeric_cast)
{ cout<<"caught bad_numeric_cast #4\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
caught_exception = false;
try { numeric_cast<int>( DBL_MAX ); }
catch (bad_numeric_cast)
{ cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
(void)ul; // Supressing GCC warning about set but unused wariable
return 0 ;
}
-29
View File
@@ -1,29 +0,0 @@
#==============================================================================
# Copyright (c) 2012 Antony Polukhin
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#==============================================================================
# performance tests
import testing ;
import path ;
path-constant TEST_DIR : . ;
project performance/test
: source-location ./
: requirements
# <library>/boost/chrono//boost_chrono
# <library>/boost/system//boost_system
<link>static
<target-os>freebsd:<linkflags>"-lrt"
<target-os>linux:<linkflags>"-lrt"
<toolset>gcc:<cxxflags>-fvisibility=hidden
<toolset>intel-linux:<cxxflags>-fvisibility=hidden
<toolset>sun:<cxxflags>-xldscope=hidden
: default-build release
;
run performance_test.cpp : $(TEST_DIR) ;
-369
View File
@@ -1,369 +0,0 @@
// (C) Copyright Antony Polukhin 2012.
// Use, modification and distribution are subject to 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)
// See http://www.boost.org/libs/config for most recent version.
//
// Testing lexical_cast<> performance
//
#define BOOST_ERROR_CODE_HEADER_ONLY
#define BOOST_CHRONO_HEADER_ONLY
#include <boost/lexical_cast.hpp>
#include <boost/chrono.hpp>
#include <fstream>
#include <cstring>
#include <boost/container/string.hpp>
// File to output data
std::fstream fout;
namespace boost {
inline std::istream& operator>> (std::istream& in, boost::array<char,50>& res) {
in >> res.begin();
return in;
}
}
template <class OutT, class InT>
static inline void test_lexical(const InT& in_val) {
OutT out_val = boost::lexical_cast<OutT>(in_val);
(void)out_val;
}
template <class OutT, class InT>
static inline void test_ss_constr(const InT& in_val) {
OutT out_val;
std::stringstream ss;
ss << in_val;
if (ss.fail()) throw std::logic_error("descr");
ss >> out_val;
if (ss.fail()) throw std::logic_error("descr");
}
template <class OutT, class CharT, std::size_t N>
static inline void test_ss_constr(const boost::array<CharT, N>& in_val) {
OutT out_val;
std::stringstream ss;
ss << in_val.begin();
if (ss.fail()) throw std::logic_error("descr");
ss >> out_val;
if (ss.fail()) throw std::logic_error("descr");
}
template <class OutT, class StringStreamT, class CharT, std::size_t N>
static inline void test_ss_noconstr(StringStreamT& ss, const boost::array<CharT, N>& in_val) {
OutT out_val;
ss << in_val.begin(); // ss is an instance of std::stringstream
if (ss.fail()) throw std::logic_error("descr");
ss >> out_val;
if (ss.fail()) throw std::logic_error("descr");
/* reseting std::stringstream to use it again */
ss.str(std::string());
ss.clear();
}
template <class OutT, class StringStreamT, class InT>
static inline void test_ss_noconstr(StringStreamT& ss, const InT& in_val) {
OutT out_val;
ss << in_val; // ss is an instance of std::stringstream
if (ss.fail()) throw std::logic_error("descr");
ss >> out_val;
if (ss.fail()) throw std::logic_error("descr");
/* reseting std::stringstream to use it again */
ss.str(std::string());
ss.clear();
}
struct structure_sprintf {
template <class OutT, class BufferT, class InT>
static inline void test(BufferT* buffer, const InT& in_val, const char* const conv) {
sprintf(buffer, conv, in_val);
OutT out_val(buffer);
}
template <class OutT, class BufferT>
static inline void test(BufferT* buffer, const std::string& in_val, const char* const conv) {
sprintf(buffer, conv, in_val.c_str());
OutT out_val(buffer);
}
};
struct structure_sscanf {
template <class OutT, class BufferT, class CharT, std::size_t N>
static inline void test(BufferT* /*buffer*/, const boost::array<CharT, N>& in_val, const char* const conv) {
OutT out_val;
sscanf(in_val.cbegin(), conv, &out_val);
}
template <class OutT, class BufferT, class InT>
static inline void test(BufferT* /*buffer*/, const InT& in_val, const char* const conv) {
OutT out_val;
sscanf(reinterpret_cast<const char*>(in_val), conv, &out_val);
}
template <class OutT, class BufferT>
static inline void test(BufferT* /*buffer*/, const std::string& in_val, const char* const conv) {
OutT out_val;
sscanf(in_val.c_str(), conv, &out_val);
}
template <class OutT, class BufferT>
static inline void test(BufferT* /*buffer*/, const boost::iterator_range<const char*>& in_val, const char* const conv) {
OutT out_val;
sscanf(in_val.begin(), conv, &out_val);
}
};
struct structure_fake {
template <class OutT, class BufferT, class InT>
static inline void test(BufferT* /*buffer*/, const InT& /*in_val*/, const char* const /*conv*/) {}
};
static const int fake_test_value = 9999;
template <class T>
static inline void min_fancy_output(T v1, T v2, T v3, T v4) {
const char beg_mark[] = "!!! *";
const char end_mark[] = "* !!!";
const char no_mark[] = "";
unsigned int res = 4;
if (v1 < v2 && v1 < v3 && v1 < v4) res = 1;
if (v2 < v1 && v2 < v3 && v2 < v4) res = 2;
if (v3 < v1 && v3 < v2 && v3 < v4) res = 3;
fout << "[ "
<< (res == 1 ? beg_mark : no_mark)
;
if (v1) fout << v1;
else fout << "<1";
fout << (res == 1 ? end_mark : no_mark)
<< " ][ "
<< (res == 2 ? beg_mark : no_mark)
;
if (v2) fout << v2;
else fout << "<1";
fout << (res == 2 ? end_mark : no_mark)
<< " ][ "
<< (res == 3 ? beg_mark : no_mark)
;
if (v3) fout << v3;
else fout << "<1";
fout << (res == 3 ? end_mark : no_mark)
<< " ][ "
<< (res == 4 ? beg_mark : no_mark)
;
if (!v4) fout << "<1";
else if (v4 == fake_test_value) fout << "---";
else fout << v4;
fout
<< (res == 4 ? end_mark : no_mark)
<< " ]";
}
template <unsigned int IetartionsCountV, class ToT, class SprintfT, class FromT>
static inline void perf_test_impl(const FromT& in_val, const char* const conv) {
typedef boost::chrono::steady_clock test_clock;
test_clock::time_point start;
typedef boost::chrono::milliseconds duration_t;
duration_t lexical_cast_time, ss_constr_time, ss_noconstr_time, printf_time;
start = test_clock::now();
for (unsigned int i = 0; i < IetartionsCountV; ++i) {
test_lexical<ToT>(in_val);
test_lexical<ToT>(in_val);
test_lexical<ToT>(in_val);
test_lexical<ToT>(in_val);
}
lexical_cast_time = boost::chrono::duration_cast<duration_t>(test_clock::now() - start);
start = test_clock::now();
for (unsigned int i = 0; i < IetartionsCountV; ++i) {
test_ss_constr<ToT>(in_val);
test_ss_constr<ToT>(in_val);
test_ss_constr<ToT>(in_val);
test_ss_constr<ToT>(in_val);
}
ss_constr_time = boost::chrono::duration_cast<duration_t>(test_clock::now() - start);
std::stringstream ss;
start = test_clock::now();
for (unsigned int i = 0; i < IetartionsCountV; ++i) {
test_ss_noconstr<ToT>(ss, in_val);
test_ss_noconstr<ToT>(ss, in_val);
test_ss_noconstr<ToT>(ss, in_val);
test_ss_noconstr<ToT>(ss, in_val);
}
ss_noconstr_time = boost::chrono::duration_cast<duration_t>(test_clock::now() - start);
char buffer[128];
start = test_clock::now();
for (unsigned int i = 0; i < IetartionsCountV; ++i) {
SprintfT::template test<ToT>(buffer, in_val, conv);
SprintfT::template test<ToT>(buffer, in_val, conv);
SprintfT::template test<ToT>(buffer, in_val, conv);
SprintfT::template test<ToT>(buffer, in_val, conv);
}
printf_time = boost::chrono::duration_cast<duration_t>(test_clock::now() - start);
min_fancy_output(
lexical_cast_time.count(),
ss_constr_time.count(),
ss_noconstr_time.count(),
boost::is_same<SprintfT, structure_fake>::value ? fake_test_value : printf_time.count()
);
}
template <class ToT, class SprintfT, class FromT>
static inline void perf_test(const std::string& test_name, const FromT& in_val, const char* const conv) {
const unsigned int ITERATIONSCOUNT = 100000;
fout << " [[ " << test_name << " ]";
perf_test_impl<ITERATIONSCOUNT/4, ToT, SprintfT>(in_val, conv);
fout << "]\n";
}
template <class ConverterT>
void string_like_test_set(const std::string& from) {
typedef structure_sscanf ssc_t;
ConverterT conv;
perf_test<char, ssc_t>(from + "->char", conv("c"), "%c");
perf_test<signed char, ssc_t>(from + "->signed char", conv("c"), "%hhd");
perf_test<unsigned char, ssc_t>(from + "->unsigned char", conv("c"), "%hhu");
perf_test<int, ssc_t>(from + "->int", conv("100"), "%d");
perf_test<short, ssc_t>(from + "->short", conv("100"), "%hd");
perf_test<long int, ssc_t>(from + "->long int", conv("100"), "%ld");
perf_test<boost::long_long_type, ssc_t>(from + "->long long", conv("100"), "%lld");
perf_test<unsigned int, ssc_t>(from + "->unsigned int", conv("100"), "%u");
perf_test<unsigned short, ssc_t>(from + "->unsigned short", conv("100"), "%hu");
perf_test<unsigned long int, ssc_t>(from + "->unsigned long int", conv("100"), "%lu");
perf_test<boost::ulong_long_type, ssc_t>(from + "->unsigned long long", conv("100"), "%llu");
// perf_test<bool, ssc_t>(from + "->bool", conv("1"), "%");
perf_test<float, ssc_t>(from + "->float", conv("1.123"), "%f");
perf_test<double, ssc_t>(from + "->double", conv("1.123"), "%lf");
perf_test<long double, ssc_t>(from + "->long double", conv("1.123"), "%Lf");
perf_test<boost::array<char, 50>, ssc_t>(from + "->array<char, 50>", conv("1.123"), "%s");
perf_test<std::string, structure_fake>(from + "->string", conv("string"), "%Lf");
perf_test<boost::container::string, structure_fake>(from + "->container::string"
, conv("string"), "%Lf");
}
struct to_string_conv {
std::string operator()(const char* const c) const {
return c;
}
};
struct to_char_conv {
const char* operator()(const char* const c) const {
return c;
}
};
struct to_uchar_conv {
const unsigned char* operator()(const char* const c) const {
return reinterpret_cast<const unsigned char*>(c);
}
};
struct to_schar_conv {
const signed char* operator()(const char* const c) const {
return reinterpret_cast<const signed char*>(c);
}
};
struct to_iterator_range {
boost::iterator_range<const char*> operator()(const char* const c) const {
return boost::make_iterator_range(c, c + std::strlen(c));
}
};
struct to_array_50 {
boost::array<char, 50> operator()(const char* const c) const {
boost::array<char, 50> ret;
std::strcpy(ret.begin(), c);
return ret;
}
};
int main(int argc, char** argv) {
BOOST_ASSERT(argc >= 2);
std::string output_path(argv[1]);
output_path += "/results.txt";
fout.open(output_path.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
BOOST_ASSERT(fout);
fout << "[section " << BOOST_COMPILER << "]\n"
<< "[table:id Performance Table ( "<< BOOST_COMPILER << ")\n"
<< "[[From->To] [lexical_cast] [std::stringstream with construction] "
<< "[std::stringstream without construction][scanf/printf]]\n";
// From std::string to ...
string_like_test_set<to_string_conv>("string");
// From ... to std::string
perf_test<std::string, structure_sprintf>("string->char", 'c', "%c");
perf_test<std::string, structure_sprintf>("string->signed char", static_cast<signed char>('c'), "%hhd");
perf_test<std::string, structure_sprintf>("string->unsigned char", static_cast<unsigned char>('c'), "%hhu");
perf_test<std::string, structure_sprintf>("int->string", 100, "%d");
perf_test<std::string, structure_sprintf>("short->string", static_cast<short>(100), "%hd");
perf_test<std::string, structure_sprintf>("long int->string", 100l, "%ld");
perf_test<std::string, structure_sprintf>("long long->string", 100ll, "%lld");
perf_test<std::string, structure_sprintf>("unsigned int->string", static_cast<unsigned short>(100u), "%u");
perf_test<std::string, structure_sprintf>("unsigned short->string", 100u, "%hu");
perf_test<std::string, structure_sprintf>("unsigned long int->string", 100ul, "%lu");
perf_test<std::string, structure_sprintf>("unsigned long long->string", static_cast<boost::ulong_long_type>(100), "%llu");
// perf_test<bool, structure_sscanf>("bool->string", std::string("1"), "%");
perf_test<std::string, structure_sprintf>("float->string", 1.123f, "%f");
perf_test<std::string, structure_sprintf>("double->string", 1.123, "%lf");
perf_test<std::string, structure_sprintf>("long double->string", 1.123L, "%Lf");
string_like_test_set<to_char_conv>("char*");
string_like_test_set<to_uchar_conv>("unsigned char*");
string_like_test_set<to_schar_conv>("signed char*");
string_like_test_set<to_iterator_range>("iterator_range<char*>");
string_like_test_set<to_array_50>("array<char, 50>");
perf_test<int, structure_fake>("int->int", 100, "");
perf_test<double, structure_fake>("float->double", 100.0f, "");
perf_test<signed char, structure_fake>("char->signed char", 'c', "");
fout << "]\n"
<< "[endsect]\n\n";
return 0;
}
-308
View File
@@ -1,308 +0,0 @@
// what: simple unit test framework
// who: developed by Kevlin Henney
// when: November 2000
// where: tested with BCC 5.5, MSVC 6.0, and g++ 2.91
//
// ChangeLog:
// 20 Jan 2001 - Fixed a warning for MSVC (Dave Abrahams)
#ifndef TEST_INCLUDED
#define TEST_INCLUDED
#include <exception>
#include <iostream>
#include <strstream> // for out-of-the-box g++
#include <string>
namespace test // test tuple comprises name and nullary function (object)
{
template<typename string_type, typename function_type>
struct test
{
string_type name;
function_type action;
static test make(string_type name, function_type action)
{
test result; // MSVC aggreggate initializer bugs
result.name = name;
result.action = action;
return result;
}
};
}
namespace test // failure exception used to indicate checked test failures
{
class failure : public std::exception
{
public: // struction (default cases are OK)
failure(const std::string & why)
: reason(why)
{
}
// std::~string has no exception-specification (could throw anything),
// but we need to be compatible with std::~exception's empty one
// see std::15.4p13 and std::15.4p3
~failure() throw()
{
}
public: // usage
virtual const char * what() const throw()
{
return reason.c_str();
}
private: // representation
std::string reason;
};
}
namespace test // not_implemented exception used to mark unimplemented tests
{
class not_implemented : public std::exception
{
public: // usage (default ctor and dtor are OK)
virtual const char * what() const throw()
{
return "not implemented";
}
};
}
namespace test // test utilities
{
inline void check(bool condition, const std::string & description)
{
if(!condition)
{
throw failure(description);
}
}
inline void check_true(bool value, const std::string & description)
{
check(value, "expected true: " + description);
}
inline void check_false(bool value, const std::string & description)
{
check(!value, "expected false: " + description);
}
template<typename lhs_type, typename rhs_type>
void check_equal(
const lhs_type & lhs, const rhs_type & rhs,
const std::string & description)
{
check(lhs == rhs, "expected equal values: " + description);
}
template<typename lhs_type, typename rhs_type>
void check_unequal(
const lhs_type & lhs, const rhs_type & rhs,
const std::string & description)
{
check(lhs != rhs, "expected unequal values: " + description);
}
inline void check_null(const void* ptr, const std::string & description)
{
check(!ptr, "expected null pointer: " + description);
}
inline void check_non_null(const void* ptr, const std::string & description)
{
check(ptr != 0, "expected non-null pointer: " + description);
}
}
#define TEST_CHECK_THROW(expression, exception, description) \
try \
{ \
expression; \
throw ::test::failure(description); \
} \
catch(exception &) \
{ \
}
namespace test // memory tracking (enabled if test new and delete linked in)
{
class allocations
{
public: // singleton access
static allocations & instance()
{
static allocations singleton;
return singleton;
}
public: // logging
void clear()
{
alloc_count = dealloc_count = 0;
}
void allocation()
{
++alloc_count;
}
void deallocation()
{
++dealloc_count;
}
public: // reporting
unsigned long allocated() const
{
return alloc_count;
}
unsigned long deallocated() const
{
return dealloc_count;
}
bool balanced() const
{
return alloc_count == dealloc_count;
}
private: // structors (default dtor is fine)
allocations()
: alloc_count(0), dealloc_count(0)
{
}
private: // prevention
allocations(const allocations &);
allocations & operator=(const allocations &);
private: // state
unsigned long alloc_count, dealloc_count;
};
}
namespace test // tester is the driver class for a sequence of tests
{
template<typename test_iterator>
class tester
{
public: // structors (default destructor is OK)
tester(test_iterator first_test, test_iterator after_last_test)
: begin(first_test), end(after_last_test)
{
}
public: // usage
bool operator()(); // returns true if all tests passed
private: // representation
test_iterator begin, end;
private: // prevention
tester(const tester &);
tester &operator=(const tester &);
};
template<typename test_iterator>
bool tester<test_iterator>::operator()()
{
using namespace std;
unsigned long passed = 0, failed = 0, unimplemented = 0;
for(test_iterator current = begin; current != end; ++current)
{
cerr << "[" << current->name << "] " << flush;
string result = "passed"; // optimistic
try
{
allocations::instance().clear();
current->action();
if(!allocations::instance().balanced())
{
unsigned long allocated = allocations::instance().allocated();
unsigned long deallocated = allocations::instance().deallocated();
ostrstream report;
report << "new/delete ("
<< allocated << " allocated, "
<< deallocated << " deallocated)"
<< ends;
const char * text = report.str();
report.freeze(false);
throw failure(text);
}
++passed;
}
catch(const failure & caught)
{
(result = "failed: ") += caught.what();
++failed;
}
catch(const not_implemented &)
{
result = "not implemented";
++unimplemented;
}
catch(const exception & caught)
{
(result = "exception: ") += caught.what();
++failed;
}
catch(...)
{
result = "failed with unknown exception";
++failed;
}
cerr << result << endl;
}
cerr << passed + failed << " tests: "
<< passed << " passed, "
<< failed << " failed";
if(unimplemented)
{
cerr << " (" << unimplemented << " not implemented)";
}
cerr << endl;
return failed == 0;
}
}
#endif
// Copyright Kevlin Henney, 2000. All rights reserved.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
+17
View File
@@ -0,0 +1,17 @@
# Copyright (c) 2016-2026 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
include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(NOT HAVE_BOOST_TEST)
return()
endif()
set(BOOST_TEST_LINK_LIBRARIES Boost::conversion Boost::core)
boost_test(TYPE run SOURCES cast_test.cpp)
boost_test(TYPE run SOURCES implicit_cast.cpp)
boost_test(TYPE compile-fail SOURCES implicit_cast_fail.cpp)
boost_test(TYPE compile-fail SOURCES implicit_cast_fail2.cpp)
boost_test(TYPE run SOURCES polymorphic_cast_test.cpp LINK_LIBRARIES Boost::smart_ptr)
+9 -51
View File
@@ -1,20 +1,20 @@
# Copyright (C) 2001-2003 Douglas Gregor
# Copyright (C) 2011-2013 Antony Polukhin
# Copyright (C) Antony Polukhin, 2011-2024
#
# 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)
#
require-b2 5.0.1 ;
import-search /boost/config/checks ;
import config : requires ;
import testing ;
import feature ;
project
: requirements
<library>/boost/test//boost_unit_test_framework
<link>static
<toolset>gcc-4.7:<cxxflags>-ftrapv
<toolset>gcc-4.6:<cxxflags>-ftrapv
<toolset>clang:<cxxflags>-ftrapv
<library>/boost/conversion//boost_conversion
[ requires cxx11_decltype ]
# default to all warnings on:
<warnings>all
# set warnings as errors for those compilers we know we get warning free:
@@ -22,52 +22,10 @@ project
<toolset>gcc:<cxxflags>-Wno-uninitialized
;
# Thanks to Steven Watanabe for helping with <nowchar> feature
feature.feature nowchar : on :
composite optional propagated link-incompatible ;
feature.compose <nowchar>on : <cxxflags>/Zc:wchar_t- ;
test-suite conversion
: [ run implicit_cast.cpp ]
[ compile-fail implicit_cast_fail.cpp ]
[ run ../cast_test.cpp ]
[ run ../numeric_cast_test.cpp ]
[ run ../lexical_cast_test.cpp ]
[ run lexical_cast_loopback_test.cpp ]
[ run lexical_cast_abstract_test.cpp ]
[ run lexical_cast_noncopyable_test.cpp ]
[ run lexical_cast_vc8_bug_test.cpp ]
[ run lexical_cast_wchars_test.cpp ]
[ run lexical_cast_float_types_test.cpp ]
[ run lexical_cast_inf_nan_test.cpp ]
[ run lexical_cast_containers_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>clang:<cxxflags>-Wno-long-long ]
[ run lexical_cast_empty_input_test.cpp ]
[ run lexical_cast_pointers_test.cpp ]
[ compile lexical_cast_typedefed_wchar_test.cpp : <toolset>msvc:<nowchar>on ]
[ run lexical_cast_typedefed_wchar_test_runtime.cpp : : : <toolset>msvc:<nowchar>on <toolset>msvc,<stdlib>stlport:<build>no ]
[ run lexical_cast_no_locale_test.cpp : : : <define>BOOST_NO_STD_LOCALE <define>BOOST_LEXICAL_CAST_ASSUME_C_LOCALE ]
[ run lexical_cast_no_exceptions_test.cpp : : : <define>BOOST_NO_EXCEPTIONS
<toolset>gcc-4.3:<cxxflags>-fno-exceptions
<toolset>gcc-4.4:<cxxflags>-fno-exceptions
<toolset>gcc-4.5:<cxxflags>-fno-exceptions
<toolset>gcc-4.6:<cxxflags>-fno-exceptions
<toolset>gcc-4.7:<cxxflags>-fno-exceptions
<toolset>gcc-4.8:<cxxflags>-fno-exceptions
<toolset>clang:<cxxflags>-fno-exceptions
]
[ run lexical_cast_iterator_range_test.cpp ]
[ run lexical_cast_arrays_test.cpp ]
[ run lexical_cast_integral_types_test.cpp ]
[ run lexical_cast_stream_detection_test.cpp ]
[ run lexical_cast_stream_traits_test.cpp ]
[ compile-fail lexical_cast_to_pointer_test.cpp ]
[ run lexical_cast_filesystem_test.cpp ../../filesystem/build//boost_filesystem/<link>static ]
[ run cast_test.cpp ]
[ run polymorphic_cast_test.cpp : : : <library>/boost/smart_ptr//boost_smart_ptr ]
[ compile-fail implicit_cast_fail2.cpp ]
;
# 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) ] ;
}
+87
View File
@@ -0,0 +1,87 @@
# Use, modification, and distribution are
# subject to 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)
#
# Copyright Antony Polukhin, 2016-2025.
#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file
# and how it can be used with Boost libraries.
#
# File revision #6
init:
# boost-local/libs/ folder to put this library into. This may be useful, if you're for example running Travis
# from `Boost.DLL` repo while Boost already has `dll` and with to replace `dll` with content of`Boost.DLL`.
#
# Otherwise just leave the default value - set BOOST_LIBS_FOLDER=%APPVEYOR_PROJECT_NAME%
- set BOOST_LIBS_FOLDER=%APPVEYOR_PROJECT_NAME%
###############################################################################################################
# From this point and below code is same for all the Boost libs
###############################################################################################################
version: 1.84.{build}-{branch}
# branches to build
branches:
except:
- gh-pages
skip_tags: true
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1,clang-win
CXXSTD: 14,17
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
before_build:
- set BOOST_BRANCH=develop
- if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master
- echo "Testing %APPVEYOR_PROJECT_NAME%"
# Cloning Boost libraries (fast nondeep cloning)
- set BOOST=C:/boost-local
- git clone -b %BOOST_BRANCH% --depth 10 https://github.com/boostorg/boost.git %BOOST%
- cd %BOOST%
- git submodule update --init --depth 10 tools/build tools/boostdep
- rm -rf %BOOST%/libs/%BOOST_LIBS_FOLDER%
- mv -f %APPVEYOR_BUILD_FOLDER% %BOOST%/libs/%BOOST_LIBS_FOLDER%
- python tools/boostdep/depinst/depinst.py --git_args "--depth 10 --jobs 2" %BOOST_LIBS_FOLDER%
build_script:
- cmd /c bootstrap
- b2.exe headers
- cd %BOOST%/libs/%BOOST_LIBS_FOLDER%/test
after_build:
before_test:
test_script:
- PATH=%ADDPATH%%PATH%
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
- echo "Running command ..\..\..\b2 -j3 toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release"
- ..\..\..\b2.exe -j3 toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release cxxflags="-DBOOST_TRAVISCI_BUILD"
after_test:
on_success:
on_failure:
on_finish:
+57 -24
View File
@@ -14,13 +14,8 @@
// 3 Aug 99 Initial Version
#include <iostream>
#include <climits>
#include <cfloat> // for DBL_MAX (Peter Schmid)
#include <boost/cast.hpp>
# if SCHAR_MAX == LONG_MAX
# error "This test program doesn't work if SCHAR_MAX == LONG_MAX"
# endif
#include <boost/polymorphic_cast.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost;
using std::cout;
@@ -43,6 +38,48 @@ namespace
};
}
constexpr bool compile_time_polymorphic_cast_check() {
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
Derived derived;
Base* base = &derived;
return polymorphic_cast<Derived*>(base) != nullptr;
#endif
return true;
}
static_assert(
compile_time_polymorphic_cast_check(),
"polymorphic_cast does not work at compile time"
);
constexpr bool compile_time_polymorphic_downcast_check() {
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
Derived derived;
Base* base = &derived;
return polymorphic_downcast<Derived*>(base) != nullptr;
#endif
return true;
}
static_assert(
compile_time_polymorphic_downcast_check(),
"polymorphic_downcast does not work at compile time"
);
constexpr bool compile_time_polymorphic_downcast2_check() {
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
Derived derived;
Base& base = derived;
Derived& derived_again = polymorphic_downcast<Derived&>(base);
(void)derived_again;
#endif
return true;
}
static_assert(
compile_time_polymorphic_downcast2_check(),
"polymorphic_downcast does not work at compile time"
);
int main( int argc, char * argv[] )
{
@@ -57,35 +94,31 @@ int main( int argc, char * argv[] )
// test polymorphic_cast ---------------------------------------------------//
// tests which should succeed
Base * base = new Derived;
Base2 * base2 = 0;
Derived * derived = 0;
derived = polymorphic_downcast<Derived*>( base ); // downcast
assert( derived->kind() == 'D' );
Derived derived_instance;
Base * base = &derived_instance;
Derived * derived = polymorphic_downcast<Derived*>( base ); // downcast
BOOST_TEST( derived->kind() == 'D' );
derived = 0;
derived = polymorphic_cast<Derived*>( base ); // downcast, throw on error
assert( derived->kind() == 'D' );
BOOST_TEST( derived->kind() == 'D' );
base2 = polymorphic_cast<Base2*>( base ); // crosscast
assert( base2->kind2() == '2' );
Base2 * base2 = polymorphic_cast<Base2*>( base ); // crosscast
BOOST_TEST( base2->kind2() == '2' );
// tests which should result in errors being detected
int err_count = 0;
base = new Base;
Base base_instance;
base = &base_instance;
if ( argc > 1 && *argv[1] == '1' )
{ derived = polymorphic_downcast<Derived*>( base ); } // #1 assert failure
bool caught_exception = false;
try { derived = polymorphic_cast<Derived*>( base ); }
catch (std::bad_cast)
catch (const std::bad_cast&)
{ cout<<"caught bad_cast\n"; caught_exception = true; }
if ( !caught_exception ) ++err_count;
BOOST_TEST( caught_exception );
// the following is just so generated code can be inspected
if ( derived->kind() == 'B' ) ++err_count;
BOOST_TEST( derived->kind() != 'B' );
cout << err_count << " errors detected\nTest "
<< (err_count==0 ? "passed\n" : "failed\n");
return err_count;
return boost::report_errors();
} // main
+9 -4
View File
@@ -4,8 +4,9 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/implicit_cast.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/type.hpp>
using boost::implicit_cast;
using boost::type;
@@ -18,8 +19,8 @@ struct foo
operator long() const { return 0; }
};
typedef type<long> long_type;
typedef type<foo> foo_type;
using long_type = type<long>;
using foo_type = type<foo>;
int main()
{
@@ -29,10 +30,14 @@ int main()
type<foo> f = check_return(boost::implicit_cast<foo>("hello"));
type<long> z = check_return(boost::implicit_cast<long>(foo("hello")));
// warning supression:
// warning suppression:
(void)x;
(void)f;
(void)z;
constexpr long value = boost::implicit_cast<long>(42);
BOOST_TEST(value == 42L);
return boost::report_errors();
}
+1 -7
View File
@@ -4,10 +4,6 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/implicit_cast.hpp>
#include <boost/type.hpp>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
using boost::implicit_cast;
@@ -16,11 +12,9 @@ struct foo
explicit foo(char const*) {}
};
int test_main(int, char*[])
int main()
{
foo x = implicit_cast<foo>("foobar");
(void)x; // warning suppression.
BOOST_CHECK(false); // suppressing warning about 'boost::unit_test::{anonymous}::unit_test_log' defined but not used
return 0;
}
+19
View File
@@ -0,0 +1,19 @@
//
// Test that implicit_cast requires a template argument
//
// Copyright 2014 Peter Dimov
//
// 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/implicit_cast.hpp>
int main()
{
int x = boost::implicit_cast( 1 );
(void)x;
return 0;
}
-61
View File
@@ -1,61 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Sergey Shandar 2005, Alexander Nasonov, 2007.
//
// 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 abstract class. Bug 1358600:
// http://sf.net/tracker/?func=detail&aid=1358600&group_id=7586&atid=107586
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost;
void test_abstract();
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_abstract));
return suite;
}
class A
{
public:
virtual void out(std::ostream &) const = 0;
};
class B: public A
{
public:
virtual void out(std::ostream &O) const { O << "B"; }
};
std::ostream &operator<<(std::ostream &O, const A &a)
{
a.out(O);
return O;
}
void test_abstract()
{
const A &a = B();
BOOST_CHECK(boost::lexical_cast<std::string>(a) == "B");
}
-377
View File
@@ -1,377 +0,0 @@
// Testing boost::lexical_cast with boost::container::string.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/array.hpp>
void testing_boost_array_output_conversion();
void testing_std_array_output_conversion();
void testing_boost_array_input_conversion();
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 =
BOOST_TEST_SUITE("Testing boost::lexical_cast with boost::array and std::array");
suite->add(BOOST_TEST_CASE(testing_boost_array_output_conversion));
suite->add(BOOST_TEST_CASE(testing_std_array_output_conversion));
suite->add(BOOST_TEST_CASE(testing_boost_array_input_conversion));
suite->add(BOOST_TEST_CASE(testing_std_array_input_conversion));
return suite;
}
template <template <class, std::size_t> class ArrayT, class T>
static void testing_template_array_output_on_spec_value(T val)
{
typedef ArrayT<char, 300> arr_type;
typedef ArrayT<char, 1> short_arr_type;
typedef ArrayT<unsigned char, 300> uarr_type;
typedef ArrayT<unsigned char, 1> ushort_arr_type;
typedef ArrayT<signed char, 4> sarr_type;
typedef ArrayT<signed char, 3> sshort_arr_type;
std::string ethalon("100");
using namespace std;
{
arr_type res1 = lexical_cast<arr_type>(val);
BOOST_CHECK_EQUAL(&res1[0], ethalon);
const arr_type res2 = lexical_cast<arr_type>(val);
BOOST_CHECK_EQUAL(&res2[0], ethalon);
BOOST_CHECK_THROW(lexical_cast<short_arr_type>(val), boost::bad_lexical_cast);
}
{
uarr_type res1 = lexical_cast<uarr_type>(val);
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(&res1[0]), ethalon);
const uarr_type res2 = lexical_cast<uarr_type>(val);
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(&res2[0]), ethalon);
BOOST_CHECK_THROW(lexical_cast<ushort_arr_type>(val), boost::bad_lexical_cast);
}
{
sarr_type res1 = lexical_cast<sarr_type>(val);
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(&res1[0]), ethalon);
const sarr_type res2 = lexical_cast<sarr_type>(val);
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(&res2[0]), ethalon);
BOOST_CHECK_THROW(lexical_cast<sshort_arr_type>(val), boost::bad_lexical_cast);
}
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING)
typedef ArrayT<wchar_t, 300> warr_type;
typedef ArrayT<wchar_t, 3> wshort_arr_type;
std::wstring wethalon(L"100");
{
warr_type res = lexical_cast<warr_type>(val);
BOOST_CHECK(&res[0] == wethalon);
}
{
const warr_type res = lexical_cast<warr_type>(val);
BOOST_CHECK(&res[0] == wethalon);
}
BOOST_CHECK_THROW(lexical_cast<wshort_arr_type>(val), boost::bad_lexical_cast);
#endif
#ifdef BOOST_LC_RUNU16
typedef ArrayT<char16_t, 300> u16arr_type;
typedef ArrayT<char16_t, 3> u16short_arr_type;
std::u16string u16ethalon(u"100");
{
u16arr_type res = lexical_cast<u16arr_type>(val);
BOOST_CHECK(&res[0] == u16ethalon);
}
{
const u16arr_type res = lexical_cast<u16arr_type>(val);
BOOST_CHECK(&res[0] == u16ethalon);
}
BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), boost::bad_lexical_cast);
#endif
#ifdef BOOST_LC_RUNU32
typedef ArrayT<char32_t, 300> u32arr_type;
typedef ArrayT<char32_t, 3> u32short_arr_type;
std::u32string u32ethalon(U"100");
{
u32arr_type res = lexical_cast<u32arr_type>(val);
BOOST_CHECK(&res[0] == u32ethalon);
}
{
const u32arr_type res = lexical_cast<u32arr_type>(val);
BOOST_CHECK(&res[0] == u32ethalon);
}
BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), boost::bad_lexical_cast);
#endif
}
template <template <class, std::size_t> class ArrayT>
static void testing_template_array_output_on_char_value()
{
typedef ArrayT<char, 300> arr_type;
typedef ArrayT<char, 1> short_arr_type;
typedef ArrayT<unsigned char, 300> uarr_type;
typedef ArrayT<unsigned char, 1> ushort_arr_type;
typedef ArrayT<signed char, 4> sarr_type;
typedef ArrayT<signed char, 3> sshort_arr_type;
const char val[] = "100";
std::string ethalon("100");
using namespace std;
{
arr_type res1 = lexical_cast<arr_type>(val);
BOOST_CHECK_EQUAL(&res1[0], ethalon);
const arr_type res2 = lexical_cast<arr_type>(val);
BOOST_CHECK_EQUAL(&res2[0], ethalon);
BOOST_CHECK_THROW(lexical_cast<short_arr_type>(val), boost::bad_lexical_cast);
}
{
uarr_type res1 = lexical_cast<uarr_type>(val);
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(&res1[0]), ethalon);
const uarr_type res2 = lexical_cast<uarr_type>(val);
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(&res2[0]), ethalon);
BOOST_CHECK_THROW(lexical_cast<ushort_arr_type>(val), boost::bad_lexical_cast);
}
{
sarr_type res1 = lexical_cast<sarr_type>(val);
BOOST_CHECK_EQUAL(reinterpret_cast<char*>(&res1[0]), ethalon);
const sarr_type res2 = lexical_cast<sarr_type>(val);
BOOST_CHECK_EQUAL(reinterpret_cast<const char*>(&res2[0]), ethalon);
BOOST_CHECK_THROW(lexical_cast<sshort_arr_type>(val), boost::bad_lexical_cast);
}
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING)
typedef ArrayT<wchar_t, 4> warr_type;
typedef ArrayT<wchar_t, 3> wshort_arr_type;
std::wstring wethalon(L"100");
{
warr_type res = lexical_cast<warr_type>(val);
BOOST_CHECK(&res[0] == wethalon);
warr_type res3 = lexical_cast<warr_type>(wethalon);
BOOST_CHECK(&res3[0] == wethalon);
}
{
const warr_type res = lexical_cast<warr_type>(val);
BOOST_CHECK(&res[0] == wethalon);
const warr_type res3 = lexical_cast<warr_type>(wethalon);
BOOST_CHECK(&res3[0] == wethalon);
}
BOOST_CHECK_THROW(lexical_cast<wshort_arr_type>(val), boost::bad_lexical_cast);
#endif
#ifdef BOOST_LC_RUNU16
typedef ArrayT<char16_t, 300> u16arr_type;
typedef ArrayT<char16_t, 3> u16short_arr_type;
std::u16string u16ethalon(u"100");
{
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
u16arr_type res = lexical_cast<u16arr_type>(val);
BOOST_CHECK(&res[0] == u16ethalon);
#endif
u16arr_type res3 = lexical_cast<u16arr_type>(u16ethalon);
BOOST_CHECK(&res3[0] == u16ethalon);
}
{
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
const u16arr_type res = lexical_cast<u16arr_type>(val);
BOOST_CHECK(&res[0] == u16ethalon);
#endif
const u16arr_type res3 = lexical_cast<u16arr_type>(u16ethalon);
BOOST_CHECK(&res3[0] == u16ethalon);
}
// Some compillers may throw std::bad_alloc here
BOOST_CHECK_THROW(lexical_cast<u16short_arr_type>(val), std::exception);
#endif
#ifdef BOOST_LC_RUNU32
typedef ArrayT<char32_t, 300> u32arr_type;
typedef ArrayT<char32_t, 3> u32short_arr_type;
std::u32string u32ethalon(U"100");
{
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
u32arr_type res = lexical_cast<u32arr_type>(val);
BOOST_CHECK(&res[0] == u32ethalon);
#endif
u32arr_type res3 = lexical_cast<u32arr_type>(u32ethalon);
BOOST_CHECK(&res3[0] == u32ethalon);
}
{
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
const u32arr_type res = lexical_cast<u32arr_type>(val);
BOOST_CHECK(&res[0] == u32ethalon);
#endif
const u32arr_type res3 = lexical_cast<u32arr_type>(u32ethalon);
BOOST_CHECK(&res3[0] == u32ethalon);
}
// Some compillers may throw std::bad_alloc here
BOOST_CHECK_THROW(lexical_cast<u32short_arr_type>(val), std::exception);
#endif
}
void testing_boost_array_output_conversion()
{
testing_template_array_output_on_char_value<boost::array>();
testing_template_array_output_on_spec_value<boost::array>(100);
testing_template_array_output_on_spec_value<boost::array>(static_cast<short>(100));
testing_template_array_output_on_spec_value<boost::array>(static_cast<unsigned short>(100));
testing_template_array_output_on_spec_value<boost::array>(static_cast<unsigned int>(100));
}
void testing_std_array_output_conversion()
{
#ifndef BOOST_NO_CXX11_HDR_ARRAY
testing_template_array_output_on_char_value<std::array>();
testing_template_array_output_on_spec_value<std::array>(100);
testing_template_array_output_on_spec_value<std::array>(static_cast<short>(100));
testing_template_array_output_on_spec_value<std::array>(static_cast<unsigned short>(100));
testing_template_array_output_on_spec_value<std::array>(static_cast<unsigned int>(100));
#endif
BOOST_CHECK(true);
}
template <template <class, std::size_t> class ArrayT>
static void testing_generic_array_input_conversion()
{
{
ArrayT<char, 4> var_zero_terminated = {{ '1', '0', '0', '\0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_zero_terminated), "100");
BOOST_CHECK_EQUAL(lexical_cast<int>(var_zero_terminated), 100);
ArrayT<char, 3> var_none_terminated = {{ '1', '0', '0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_none_terminated), "100");
BOOST_CHECK_EQUAL(lexical_cast<short>(var_none_terminated), static_cast<short>(100));
ArrayT<const char, 4> var_zero_terminated_const_char = {{ '1', '0', '0', '\0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_zero_terminated_const_char), "100");
ArrayT<const char, 3> var_none_terminated_const_char = {{ '1', '0', '0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_none_terminated_const_char), "100");
const ArrayT<char, 4> var_zero_terminated_const_var = {{ '1', '0', '0', '\0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_zero_terminated_const_var), "100");
const ArrayT<char, 3> var_none_terminated_const_var = {{ '1', '0', '0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_none_terminated_const_var), "100");
const ArrayT<const char, 4> var_zero_terminated_const_var_const_char = {{ '1', '0', '0', '\0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_zero_terminated_const_var_const_char), "100");
const ArrayT<const char, 3> var_none_terminated_const_var_const_char = {{ '1', '0', '0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_none_terminated_const_var_const_char), "100");
BOOST_CHECK_EQUAL(lexical_cast<int>(var_none_terminated_const_var_const_char), 100);
}
{
const ArrayT<const unsigned char, 4> var_zero_terminated_const_var_const_char = {{ '1', '0', '0', '\0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_zero_terminated_const_var_const_char), "100");
const ArrayT<const unsigned char, 3> var_none_terminated_const_var_const_char = {{ '1', '0', '0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_none_terminated_const_var_const_char), "100");
}
{
const ArrayT<const signed char, 4> var_zero_terminated_const_var_const_char = {{ '1', '0', '0', '\0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_zero_terminated_const_var_const_char), "100");
const ArrayT<const signed char, 3> var_none_terminated_const_var_const_char = {{ '1', '0', '0'}};
BOOST_CHECK_EQUAL(lexical_cast<std::string>(var_none_terminated_const_var_const_char), "100");
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(var_none_terminated_const_var_const_char), 100u);
}
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING)
{
const ArrayT<const wchar_t, 4> var_zero_terminated_const_var_const_char = {{ L'1', L'0', L'0', L'\0'}};
BOOST_CHECK(lexical_cast<std::wstring>(var_zero_terminated_const_var_const_char) == L"100");
const ArrayT<const wchar_t, 3> var_none_terminated_const_var_const_char = {{ L'1', L'0', L'0'}};
BOOST_CHECK(lexical_cast<std::wstring>(var_none_terminated_const_var_const_char) == L"100");
BOOST_CHECK_EQUAL(lexical_cast<int>(var_none_terminated_const_var_const_char), 100);
}
#endif
#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");
BOOST_CHECK_EQUAL(lexical_cast<unsigned short>(var_zero_terminated_const_var_const_char), static_cast<unsigned short>(100));
const ArrayT<const char16_t, 3> var_none_terminated_const_var_const_char = {{ u'1', u'0', u'0'}};
BOOST_CHECK(lexical_cast<std::u16string>(var_none_terminated_const_var_const_char) == u"100");
}
#endif
#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");
const ArrayT<const char32_t, 3> var_none_terminated_const_var_const_char = {{ U'1', U'0', U'0'}};
BOOST_CHECK(lexical_cast<std::u32string>(var_none_terminated_const_var_const_char) == U"100");
BOOST_CHECK_EQUAL(lexical_cast<int>(var_none_terminated_const_var_const_char), 100);
}
#endif
}
void testing_boost_array_input_conversion()
{
testing_generic_array_input_conversion<boost::array>();
}
void testing_std_array_input_conversion()
{
#ifndef BOOST_NO_CXX11_HDR_ARRAY
testing_generic_array_input_conversion<std::array>();
#endif
BOOST_CHECK(true);
}
-83
View File
@@ -1,83 +0,0 @@
// Testing boost::lexical_cast with boost::container::string.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011.
//
// 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/test/unit_test.hpp>
#include <boost/container/string.hpp>
void testing_boost_containers_basic_string();
void testing_boost_containers_string_std_string();
void testing_boost_containers_string_widening();
using namespace boost;
boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("Testing boost::lexical_cast with boost::container::string");
suite->add(BOOST_TEST_CASE(testing_boost_containers_basic_string));
suite->add(BOOST_TEST_CASE(testing_boost_containers_string_std_string));
suite->add(BOOST_TEST_CASE(testing_boost_containers_string_widening));
return suite;
}
void testing_boost_containers_basic_string()
{
BOOST_CHECK("100" == lexical_cast<boost::container::string>("100"));
BOOST_CHECK(L"100" == lexical_cast<boost::container::wstring>(L"100"));
BOOST_CHECK("100" == lexical_cast<boost::container::string>(100));
boost::container::string str("1000");
BOOST_CHECK(1000 == lexical_cast<int>(str));
}
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
void testing_boost_containers_string_std_string()
{
std::string std_str("std_str");
boost::container::string boost_str("boost_str");
BOOST_CHECK(boost::lexical_cast<std::string>(boost_str) == "boost_str");
BOOST_CHECK(boost::lexical_cast<boost::container::string>(std_str) == "std_str");
#ifndef BOOST_LCAST_NO_WCHAR_T
std::wstring std_wstr(L"std_wstr");
boost::container::wstring boost_wstr(L"boost_wstr");
BOOST_CHECK(boost::lexical_cast<std::wstring>(boost_wstr) == L"boost_wstr");
BOOST_CHECK(boost::lexical_cast<boost::container::wstring>(std_wstr) == L"std_wstr");
#endif
}
void testing_boost_containers_string_widening()
{
const char char_array[] = "Test string";
#ifndef BOOST_LCAST_NO_WCHAR_T
const wchar_t wchar_array[] = L"Test string";
BOOST_CHECK(boost::lexical_cast<boost::container::wstring>(char_array) == wchar_array);
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
const char16_t char16_array[] = u"Test string";
BOOST_CHECK(boost::lexical_cast<boost::container::basic_string<char16_t> >(char_array) == char16_array);
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
const char32_t char32_array[] = U"Test string";
BOOST_CHECK(boost::lexical_cast<boost::container::basic_string<char32_t> >(char_array) == char32_array);
#endif
}
-167
View File
@@ -1,167 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/range/iterator_range.hpp>
using namespace boost;
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
template <class T>
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)
BOOST_CHECK_THROW(lexical_cast<boost::ulong_long_type>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<boost::long_long_type>(v), bad_lexical_cast);
#elif defined(BOOST_HAS_MS_INT64)
BOOST_CHECK_THROW(lexical_cast<unsigned __int64>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<__int64>(v), bad_lexical_cast);
#endif
}
void test_empty_iterator_range()
{
boost::iterator_range<char*> v;
do_test_on_empty_input(v);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(v), std::string());
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
boost::iterator_range<const char*> cv;
do_test_on_empty_input(cv);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(cv), std::string());
BOOST_CHECK_THROW(lexical_cast<char>(cv), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(cv), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(cv), bad_lexical_cast);
const boost::iterator_range<const char*> ccv;
do_test_on_empty_input(ccv);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(ccv), std::string());
BOOST_CHECK_THROW(lexical_cast<char>(ccv), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(ccv), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(ccv), bad_lexical_cast);
}
void test_empty_string()
{
std::string v;
do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
#ifndef BOOST_LCAST_NO_WCHAR_T
std::wstring vw;
do_test_on_empty_input(vw);
BOOST_CHECK_THROW(lexical_cast<wchar_t>(vw), bad_lexical_cast);
#endif
// Currently, no compiler and STL library fully support char16_t and char32_t
//#ifndef BOOST_NO_CXX11_CHAR16_T
// std::basic_string<char16_t> v16w;
// do_test_on_empty_input(v16w);
// BOOST_CHECK_THROW(lexical_cast<char16_t>(v16w), bad_lexical_cast);
//#endif
//#ifndef BOOST_NO_CXX11_CHAR32_T
// std::basic_string<char32_t> v32w;
// do_test_on_empty_input(v32w);
// BOOST_CHECK_THROW(lexical_cast<char32_t>(v32w), bad_lexical_cast);
//#endif
}
struct Escape
{
Escape(const std::string& s)
: str_(s)
{}
std::string str_;
};
inline std::ostream& operator<< (std::ostream& o, const Escape& rhs)
{
return o << rhs.str_;
}
void test_empty_user_class()
{
Escape v("");
do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
}
namespace std {
inline std::ostream & operator<<(std::ostream & out, const std::vector<long> & v)
{
std::ostream_iterator<long> it(out);
std::copy(v.begin(), v.end(), it);
assert(out);
return out;
}
}
void test_empty_vector()
{
std::vector<long> v;
do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
}
struct my_string {
friend std::ostream &operator<<(std::ostream& sout, my_string const&/* st*/) {
return sout << "";
}
};
void test_empty_zero_terminated_string()
{
my_string st;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(st), std::string());;
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast. Empty input unit test");
suite->add(BOOST_TEST_CASE(&test_empty_iterator_range));
suite->add(BOOST_TEST_CASE(&test_empty_string));
suite->add(BOOST_TEST_CASE(&test_empty_user_class));
suite->add(BOOST_TEST_CASE(&test_empty_vector));
suite->add(BOOST_TEST_CASE(&test_empty_zero_terminated_string));
return suite;
}
-46
View File
@@ -1,46 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2013.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
//
// Test lexical_cast usage with long filesystem::path. Bug 7704.
#include <boost/config.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/path.hpp>
using namespace boost;
void test_filesystem();
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast unit test");
suite->add(BOOST_TEST_CASE(&test_filesystem));
return suite;
}
void test_filesystem()
{
boost::filesystem::path p;
std::string s1 = "aaaaaaaaaaaaaaaaaaaaaaa";
p = boost::lexical_cast<boost::filesystem::path>(s1);
BOOST_CHECK(!p.empty());
BOOST_CHECK_EQUAL(p, s1);
p.clear();
const char ab[] = "aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
p = boost::lexical_cast<boost::filesystem::path>(ab);
BOOST_CHECK(!p.empty());
BOOST_CHECK_EQUAL(p, ab);
}
-527
View File
@@ -1,527 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
void test_conversion_from_to_float();
void test_conversion_from_to_double();
void test_conversion_from_to_long_double();
using namespace boost;
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast float types unit test");
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_float));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_double));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_long_double));
return suite;
}
// Replace "-,999" with "-999".
template<class CharT>
std::basic_string<CharT> to_str_gcc_workaround(std::basic_string<CharT> str)
{
std::locale loc;
std::numpunct<CharT> const& np = BOOST_USE_FACET(std::numpunct<CharT>, loc);
std::ctype<CharT> const& ct = BOOST_USE_FACET(std::ctype<CharT>, loc);
if(np.grouping().empty())
return str;
CharT prefix[3] = { ct.widen('-'), np.thousands_sep(), CharT() };
if(str.find(prefix) != 0)
return str;
prefix[1] = CharT();
str.replace(0, 2, prefix);
return str;
}
template<class CharT, class T>
std::basic_string<CharT> to_str(T t)
{
std::basic_ostringstream<CharT> o;
o << t;
return to_str_gcc_workaround(o.str());
}
template<class T>
void test_conversion_from_to_float_for_locale()
{
std::locale current_locale;
typedef std::numpunct<char> numpunct;
numpunct const& np = BOOST_USE_FACET(numpunct, current_locale);
if ( !np.grouping().empty() )
{
BOOST_CHECK_THROW(
lexical_cast<T>( std::string("100") + np.thousands_sep() + np.thousands_sep() + "0" )
, bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( std::string("100") + np.thousands_sep() ), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( np.thousands_sep() + std::string("100") ), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( std::string("1") + np.thousands_sep() + np.decimal_point() + "e10" ), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( std::string("1e10") + np.thousands_sep() ), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( std::string("1") + np.thousands_sep() + "e10" ), bad_lexical_cast);
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( to_str< char >(100000) ), 100000, (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( to_str< char >(10000000u) ), 10000000u, (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( to_str< char >(100) ), 100, (std::numeric_limits<T>::epsilon()) );
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( to_str< wchar_t >(100000) ), 100000, (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( to_str< wchar_t >(10000000u) ), 10000000u, (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( to_str< wchar_t >(100) ), 100, (std::numeric_limits<T>::epsilon()) );
#endif
// Exception must not be thrown, when we are using no separators at all
BOOST_CHECK_CLOSE_FRACTION( lexical_cast<T>("30000"), static_cast<T>(30000), (std::numeric_limits<T>::epsilon()) );
}
}
/*
* Converts char* [and wchar_t*] to float number type and checks, that generated
* number does not exceeds allowed epsilon.
*/
#ifndef BOOST_LCAST_NO_WCHAR_T
#define CHECK_CLOSE_ABS_DIFF(VAL,PREFIX) \
converted_val = lexical_cast<test_t>(#VAL); \
BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits<test_t>::epsilon()), \
(converted_val ? converted_val : std::numeric_limits<test_t>::epsilon()), \
std::numeric_limits<test_t>::epsilon() \
); \
BOOST_CHECK_EQUAL(converted_val, lexical_cast<test_t>(L## #VAL) );
#else
#define CHECK_CLOSE_ABS_DIFF(VAL,TYPE) \
converted_val = lexical_cast<test_t>(#VAL); \
BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits<test_t>::epsilon()), \
(converted_val ? converted_val : std::numeric_limits<test_t>::epsilon()), \
std::numeric_limits<test_t>::epsilon() \
);
#endif
template <class TestType>
void test_converion_to_float_types()
{
typedef TestType test_t;
test_t converted_val;
BOOST_CHECK_CLOSE_FRACTION(1.0, lexical_cast<test_t>('1'), (std::numeric_limits<test_t>::epsilon()));
BOOST_CHECK_EQUAL(0.0, lexical_cast<test_t>('0'));
unsigned char const uc_one = '1';
unsigned char const uc_zero ='0';
BOOST_CHECK_CLOSE_FRACTION(1.0, lexical_cast<test_t>(uc_one), (std::numeric_limits<test_t>::epsilon()));
BOOST_CHECK_EQUAL(0.0, lexical_cast<test_t>(uc_zero));
signed char const sc_one = '1';
signed char const sc_zero ='0';
BOOST_CHECK_CLOSE_FRACTION(1.0, lexical_cast<test_t>(sc_one), (std::numeric_limits<test_t>::epsilon()));
BOOST_CHECK_EQUAL(0.0, lexical_cast<test_t>(sc_zero));
BOOST_CHECK_CLOSE_FRACTION(1e34L, lexical_cast<test_t>( "10000000000000000000000000000000000"), (std::numeric_limits<test_t>::epsilon()) );
// VC failes the next test
// BOOST_CHECK_CLOSE_FRACTION(1e-35L, lexical_cast<test_t>("0.00000000000000000000000000000000001"), (std::numeric_limits<test_t>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(
0.1111111111111111111111111111111111111111111111111111111111111111111111111L
, lexical_cast<test_t>("0.1111111111111111111111111111111111111111111111111111111111111111111111111")
, (std::numeric_limits<test_t>::epsilon()) );
CHECK_CLOSE_ABS_DIFF(1,test_t);
BOOST_CHECK_EQUAL(0,lexical_cast<test_t>("0"));
CHECK_CLOSE_ABS_DIFF(-1,test_t);
CHECK_CLOSE_ABS_DIFF(1.0, test_t);
CHECK_CLOSE_ABS_DIFF(0.0, test_t);
CHECK_CLOSE_ABS_DIFF(-1.0,test_t);
CHECK_CLOSE_ABS_DIFF(1e1, test_t);
CHECK_CLOSE_ABS_DIFF(0e1, test_t);
CHECK_CLOSE_ABS_DIFF(-1e1,test_t);
CHECK_CLOSE_ABS_DIFF(1.0e1, test_t);
CHECK_CLOSE_ABS_DIFF(0.0e1, test_t);
CHECK_CLOSE_ABS_DIFF(-1.0e1,test_t);
CHECK_CLOSE_ABS_DIFF(1e-1, test_t);
CHECK_CLOSE_ABS_DIFF(0e-1, test_t);
CHECK_CLOSE_ABS_DIFF(-1e-1,test_t);
CHECK_CLOSE_ABS_DIFF(1.0e-1, test_t);
CHECK_CLOSE_ABS_DIFF(0.0e-1, test_t);
CHECK_CLOSE_ABS_DIFF(-1.0e-1,test_t);
CHECK_CLOSE_ABS_DIFF(1E1, test_t);
CHECK_CLOSE_ABS_DIFF(0E1, test_t);
CHECK_CLOSE_ABS_DIFF(-1E1,test_t);
CHECK_CLOSE_ABS_DIFF(1.0E1, test_t);
CHECK_CLOSE_ABS_DIFF(0.0E1, test_t);
CHECK_CLOSE_ABS_DIFF(-1.0E1,test_t);
CHECK_CLOSE_ABS_DIFF(1E-1, test_t);
CHECK_CLOSE_ABS_DIFF(0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(-1E-1,test_t);
CHECK_CLOSE_ABS_DIFF(1.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(0.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(-1.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(-.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(10.0, test_t);
CHECK_CLOSE_ABS_DIFF(00.0, test_t);
CHECK_CLOSE_ABS_DIFF(-10.0,test_t);
CHECK_CLOSE_ABS_DIFF(10e1, test_t);
CHECK_CLOSE_ABS_DIFF(00e1, test_t);
CHECK_CLOSE_ABS_DIFF(-10e1,test_t);
CHECK_CLOSE_ABS_DIFF(10.0e1, test_t);
CHECK_CLOSE_ABS_DIFF(00.0e1, test_t);
CHECK_CLOSE_ABS_DIFF(-10.0e1,test_t);
CHECK_CLOSE_ABS_DIFF(10e-1, test_t);
CHECK_CLOSE_ABS_DIFF(00e-1, test_t);
CHECK_CLOSE_ABS_DIFF(-10e-1,test_t);
CHECK_CLOSE_ABS_DIFF(10.0e-1, test_t);
CHECK_CLOSE_ABS_DIFF(00.0e-1, test_t);
CHECK_CLOSE_ABS_DIFF(-10.0e-1,test_t);
CHECK_CLOSE_ABS_DIFF(10E1, test_t);
CHECK_CLOSE_ABS_DIFF(00E1, test_t);
CHECK_CLOSE_ABS_DIFF(-10E1,test_t);
CHECK_CLOSE_ABS_DIFF(10.0E1, test_t);
CHECK_CLOSE_ABS_DIFF(00.0E1, test_t);
CHECK_CLOSE_ABS_DIFF(-10.0E1,test_t);
CHECK_CLOSE_ABS_DIFF(10E-1, test_t);
CHECK_CLOSE_ABS_DIFF(00E-1, test_t);
CHECK_CLOSE_ABS_DIFF(-10E-1,test_t);
CHECK_CLOSE_ABS_DIFF(10.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(00.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(-10.0E-1, test_t);
CHECK_CLOSE_ABS_DIFF(-10101.0E-011, test_t);
CHECK_CLOSE_ABS_DIFF(-10101093, test_t);
CHECK_CLOSE_ABS_DIFF(10101093, test_t);
CHECK_CLOSE_ABS_DIFF(-.34, test_t);
CHECK_CLOSE_ABS_DIFF(.34, test_t);
CHECK_CLOSE_ABS_DIFF(.34e10, test_t);
BOOST_CHECK_THROW(lexical_cast<test_t>("-1.e"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("-1.E"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("1.e"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("1.E"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("1.0e"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("1.0E"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("10E"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("10e"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("1.0e-"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("1.0E-"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("10E-"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("10e-"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("e1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("e-1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("e-"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>(".e"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>(".11111111111111111111111111111111111111111111111111111111111111111111ee"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>(".11111111111111111111111111111111111111111111111111111111111111111111e-"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("."), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("-B"), bad_lexical_cast);
// Following two tests are not valid for C++11 compilers
//BOOST_CHECK_THROW(lexical_cast<test_t>("0xB"), bad_lexical_cast);
//BOOST_CHECK_THROW(lexical_cast<test_t>("0x0"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("--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);
BOOST_CHECK_THROW(lexical_cast<test_t>("1e1e1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("1.0e-1e-1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>(" 1.0"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("1.0 "), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>(""), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("-"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>('\0'), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>('-'), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>('.'), bad_lexical_cast);
}
template <class T>
void test_float_typess_for_overflows()
{
typedef T test_t;
test_t minvalue = (std::numeric_limits<test_t>::min)();
std::string s_min_value = lexical_cast<std::string>(minvalue);
BOOST_CHECK_CLOSE_FRACTION(minvalue, lexical_cast<test_t>(minvalue), (std::numeric_limits<test_t>::epsilon()));
BOOST_CHECK_CLOSE_FRACTION(minvalue, lexical_cast<test_t>(s_min_value), (std::numeric_limits<test_t>::epsilon() * 2));
test_t maxvalue = (std::numeric_limits<test_t>::max)();
std::string s_max_value = lexical_cast<std::string>(maxvalue);
BOOST_CHECK_CLOSE_FRACTION(maxvalue, lexical_cast<test_t>(maxvalue), (std::numeric_limits<test_t>::epsilon()));
BOOST_CHECK_CLOSE_FRACTION(maxvalue, lexical_cast<test_t>(s_max_value), (std::numeric_limits<test_t>::epsilon()));
#ifndef _LIBCPP_VERSION
// libc++ had a bug in implementation of stream conversions for values that must be represented as infinity.
// http://llvm.org/bugs/show_bug.cgi?id=15723#c4
BOOST_CHECK_THROW(lexical_cast<test_t>(s_max_value+"1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>(s_max_value+"9"), bad_lexical_cast);
// VC9 can fail the following tests on floats and doubles when using stingstream...
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 )
{
BOOST_CHECK_THROW(lexical_cast<test_t>( (std::numeric_limits<double>::max)() ), bad_lexical_cast);
BOOST_CHECK(
(std::numeric_limits<double>::min)() - std::numeric_limits<test_t>::epsilon()
<= lexical_cast<test_t>( (std::numeric_limits<double>::min)() )
&& lexical_cast<test_t>( (std::numeric_limits<double>::min)() )
<= (std::numeric_limits<double>::min)() + std::numeric_limits<test_t>::epsilon()
);
}
if ( sizeof(test_t) < sizeof(long double) )
{
BOOST_CHECK_THROW(lexical_cast<test_t>( (std::numeric_limits<long double>::max)() ), bad_lexical_cast);
BOOST_CHECK(
(std::numeric_limits<long double>::min)() - std::numeric_limits<test_t>::epsilon()
<= lexical_cast<test_t>( (std::numeric_limits<long double>::min)() )
&& lexical_cast<test_t>( (std::numeric_limits<long double>::min)() )
<= (std::numeric_limits<long double>::min)() + std::numeric_limits<test_t>::epsilon()
);
}
}
#undef CHECK_CLOSE_ABS_DIFF
// Epsilon is multiplied by 2 because of two lexical conversions
#define TEST_TO_FROM_CAST_AROUND_TYPED(VAL,STRING_TYPE) \
test_value = VAL + std::numeric_limits<test_t>::epsilon() * i ; \
converted_val = lexical_cast<test_t>( lexical_cast<STRING_TYPE>(test_value) ); \
BOOST_CHECK_CLOSE_FRACTION( \
test_value, \
converted_val, \
std::numeric_limits<test_t>::epsilon() * 2 \
);
/*
* For interval [ from_mult*epsilon+VAL, to_mult*epsilon+VAL ], converts float type
* numbers to string[wstring] and then back to float type, then compares initial
* values and generated.
* Step is epsilon
*/
#ifndef BOOST_LCAST_NO_WCHAR_T
# define TEST_TO_FROM_CAST_AROUND(VAL) \
for(i=from_mult; i<=to_mult; ++i) { \
TEST_TO_FROM_CAST_AROUND_TYPED(VAL, std::string) \
TEST_TO_FROM_CAST_AROUND_TYPED(VAL, std::wstring) \
}
#else
# define TEST_TO_FROM_CAST_AROUND(VAL) \
for(i=from_mult; i<=to_mult; ++i) { \
TEST_TO_FROM_CAST_AROUND_TYPED(VAL, std::string) \
}
#endif
template <class TestType>
void test_converion_from_to_float_types()
{
typedef TestType test_t;
test_t test_value;
test_t converted_val;
int i;
int from_mult = -50;
int to_mult = 50;
TEST_TO_FROM_CAST_AROUND( 0.0 );
long double val1;
for(val1 = 1.0e-10L; val1 < 1e11; val1*=10 )
TEST_TO_FROM_CAST_AROUND( val1 );
long double val2;
for(val2 = -1.0e-10L; val2 > -1e11; val2*=10 )
TEST_TO_FROM_CAST_AROUND( val2 );
from_mult = -100;
to_mult = 0;
TEST_TO_FROM_CAST_AROUND( (std::numeric_limits<test_t>::max)() );
from_mult = 0;
to_mult = 100;
TEST_TO_FROM_CAST_AROUND( (std::numeric_limits<test_t>::min)() );
}
#undef TEST_TO_FROM_CAST_AROUND
#undef TEST_TO_FROM_CAST_AROUND_TYPED
template<class T, class CharT>
void test_conversion_from_float_to_char(CharT zero)
{
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(0)) == zero + 0);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(1)) == zero + 1);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(2)) == zero + 2);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(3)) == zero + 3);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(4)) == zero + 4);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(5)) == zero + 5);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(6)) == zero + 6);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(7)) == zero + 7);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(8)) == zero + 8);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(9)) == zero + 9);
BOOST_CHECK_THROW(lexical_cast<CharT>(static_cast<T>(10)), bad_lexical_cast);
T t = (std::numeric_limits<T>::max)();
BOOST_CHECK_THROW(lexical_cast<CharT>(t), bad_lexical_cast);
}
template<class T, class CharT>
void test_conversion_from_char_to_float(CharT zero)
{
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 0)), static_cast<T>(0), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 1)), static_cast<T>(1), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 2)), static_cast<T>(2), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 3)), static_cast<T>(3), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 4)), static_cast<T>(4), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 5)), static_cast<T>(5), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 6)), static_cast<T>(6), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 7)), static_cast<T>(7), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 8)), static_cast<T>(8), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>( static_cast<CharT>(zero + 9)), static_cast<T>(9), (std::numeric_limits<T>::epsilon()) );
BOOST_CHECK_THROW(lexical_cast<T>( static_cast<CharT>(zero + 10)), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( static_cast<CharT>(zero - 1)), bad_lexical_cast);
}
struct restore_oldloc
{
std::locale oldloc;
~restore_oldloc() { std::locale::global(oldloc); }
};
template<class T>
void test_conversion_from_to_float()
{ char const zero = '0';
signed char const szero = '0';
unsigned char const uzero = '0';
test_conversion_from_float_to_char<T>(zero);
test_conversion_from_char_to_float<T>(zero);
test_conversion_from_float_to_char<T>(szero);
test_conversion_from_char_to_float<T>(szero);
test_conversion_from_float_to_char<T>(uzero);
test_conversion_from_char_to_float<T>(uzero);
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
wchar_t const wzero = L'0';
test_conversion_from_float_to_char<T>(wzero);
test_conversion_from_char_to_float<T>(wzero);
#endif
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>("+1"), 1, std::numeric_limits<T>::epsilon());
BOOST_CHECK_CLOSE_FRACTION(lexical_cast<T>("+9"), 9, std::numeric_limits<T>::epsilon());
BOOST_CHECK_THROW(lexical_cast<T>("++1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>("-+9"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>("--1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>("+-9"), bad_lexical_cast);
test_converion_to_float_types<T>();
test_float_typess_for_overflows<T>();
test_converion_from_to_float_types<T>();
typedef std::numpunct<char> numpunct;
restore_oldloc guard;
std::locale const& oldloc = guard.oldloc;
std::string grouping1 = BOOST_USE_FACET(numpunct, oldloc).grouping();
std::string grouping2(grouping1);
test_conversion_from_to_float_for_locale<T>();
try
{
std::locale newloc("");
std::locale::global(newloc);
grouping2 = BOOST_USE_FACET(numpunct, newloc).grouping();
}
catch(std::exception const& ex)
{
std::string msg("Failed to set system locale: ");
msg += ex.what();
BOOST_TEST_MESSAGE(msg);
}
if(grouping1 != grouping2)
test_conversion_from_to_float_for_locale<T>();
if(grouping1.empty() && grouping2.empty())
BOOST_TEST_MESSAGE("Formatting with thousands_sep has not been tested");
}
void test_conversion_from_to_float()
{
test_conversion_from_to_float<float>();
}
void test_conversion_from_to_double()
{
test_conversion_from_to_float<double>();
}
void test_conversion_from_to_long_double()
{
// We do not run tests on compilers with bugs
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
test_conversion_from_to_float<long double>();
#endif
BOOST_CHECK(true);
}
-205
View File
@@ -1,205 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/math/special_functions/sign.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
using namespace boost;
template <class T>
bool is_pos_inf(T value)
{
return (boost::math::isinf)(value) && !(boost::math::signbit)(value);
}
template <class T>
bool is_neg_inf(T value)
{
return (boost::math::isinf)(value) && (boost::math::signbit)(value);
}
template <class T>
bool is_pos_nan(T value)
{
return (boost::math::isnan)(value) && !(boost::math::signbit)(value);
}
template <class T>
bool is_neg_nan(T value)
{
/* There is some strange behaviour on Itanium platform with -nan nuber for long double.
* It is a IA64 feature, or it is a boost::math feature, not a lexical_cast bug */
#if defined(__ia64__) || defined(_M_IA64)
return (boost::math::isnan)(value)
&& ( boost::is_same<T, long double >::value || (boost::math::signbit)(value) );
#else
return (boost::math::isnan)(value) && (boost::math::signbit)(value);
#endif
}
template <class T>
void test_inf_nan_templated()
{
typedef T test_t;
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("inf") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("INF") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>("-inf") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>("-INF") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("+inf") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("+INF") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("infinity") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("INFINITY") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>("-infinity") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>("-INFINITY") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("+infinity") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("+INFINITY") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("iNfiNity") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>("INfinity") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>("-inFINITY") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>("-INFINITY") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("nan") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("NAN") ) );
BOOST_CHECK( is_neg_nan( lexical_cast<test_t>("-nan") ) );
BOOST_CHECK( is_neg_nan( lexical_cast<test_t>("-NAN") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("+nan") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("+NAN") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("nAn") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("NaN") ) );
BOOST_CHECK( is_neg_nan( lexical_cast<test_t>("-nAn") ) );
BOOST_CHECK( is_neg_nan( lexical_cast<test_t>("-NaN") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("+Nan") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("+nAN") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("nan()") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>("NAN(some string)") ) );
BOOST_CHECK_THROW( lexical_cast<test_t>("NAN(some string"), bad_lexical_cast );
BOOST_CHECK(lexical_cast<std::string>( (boost::math::changesign)(std::numeric_limits<test_t >::infinity()))
== "-inf" );
BOOST_CHECK(lexical_cast<std::string>( std::numeric_limits<test_t >::infinity()) == "inf" );
BOOST_CHECK(lexical_cast<std::string>( std::numeric_limits<test_t >::quiet_NaN()) == "nan" );
#if !defined(__ia64__) && !defined(_M_IA64)
BOOST_CHECK(lexical_cast<std::string>(
(boost::math::changesign)(std::numeric_limits<test_t >::quiet_NaN()))
== "-nan" );
#endif
#ifndef BOOST_LCAST_NO_WCHAR_T
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"inf") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"INF") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>(L"-inf") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>(L"-INF") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+inf") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+INF") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"infinity") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"INFINITY") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>(L"-infinity") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>(L"-INFINITY") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+infinity") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+INFINITY") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>(L"-infINIty") ) );
BOOST_CHECK( is_neg_inf( lexical_cast<test_t>(L"-INFiniTY") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+inFINIty") ) );
BOOST_CHECK( is_pos_inf( lexical_cast<test_t>(L"+INfinITY") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>(L"nan") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>(L"NAN") ) );
BOOST_CHECK( is_neg_nan( lexical_cast<test_t>(L"-nan") ) );
BOOST_CHECK( is_neg_nan( lexical_cast<test_t>(L"-NAN") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>(L"+nan") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>(L"+NAN") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>(L"nan()") ) );
BOOST_CHECK( is_pos_nan( lexical_cast<test_t>(L"NAN(some string)") ) );
BOOST_CHECK_THROW( lexical_cast<test_t>(L"NAN(some string"), bad_lexical_cast );
BOOST_CHECK(lexical_cast<std::wstring>( (boost::math::changesign)(std::numeric_limits<test_t >::infinity()))
== L"-inf" );
BOOST_CHECK(lexical_cast<std::wstring>( std::numeric_limits<test_t >::infinity()) == L"inf" );
BOOST_CHECK(lexical_cast<std::wstring>( std::numeric_limits<test_t >::quiet_NaN()) == L"nan" );
#if !defined(__ia64__) && !defined(_M_IA64)
BOOST_CHECK(lexical_cast<std::wstring>(
(boost::math::changesign)(std::numeric_limits<test_t >::quiet_NaN()))
== L"-nan" );
#endif
#endif
}
void test_inf_nan_float()
{
test_inf_nan_templated<float >();
}
void test_inf_nan_double()
{
test_inf_nan_templated<double >();
}
void test_inf_nan_long_double()
{
// We do not run tests on compilers with bugs
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
test_inf_nan_templated<long double >();
#endif
BOOST_CHECK(true);
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast inf anf nan parsing unit test");
suite->add(BOOST_TEST_CASE(&test_inf_nan_float));
suite->add(BOOST_TEST_CASE(&test_inf_nan_double));
suite->add(BOOST_TEST_CASE(&test_inf_nan_long_double));
return suite;
}
-627
View File
@@ -1,627 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Terje Sletteb and Kevlin Henney, 2005.
// Copyright Alexander Nasonov, 2006.
// Copyright Antony Polukhin, 2011-2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
//
// Note: The unit test no longer compile on MSVC 6, but lexical_cast itself works for it.
//
// We need this #define before any #includes: otherwise msvc will emit warnings
// deep within std::string, resulting from our (perfectly legal) use of basic_string
// with a custom traits class:
//
#define _SCL_SECURE_NO_WARNINGS
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
#include <boost/test/unit_test.hpp>
#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>
#if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \
&& !(defined(BOOST_MSVC) && BOOST_MSVC < 1300)
#define LCAST_TEST_LONGLONG
#endif
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
// Test all 65536 values if true:
bool const lcast_test_small_integral_types_completely = false;
// lcast_integral_test_counter: use when testing all values of an integral
// types is not possible. Max. portable value is 32767.
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();
void test_conversion_from_to_uint();
void test_conversion_from_to_long();
void test_conversion_from_to_ulong();
void test_conversion_from_to_intmax_t();
void test_conversion_from_to_uintmax_t();
#ifdef LCAST_TEST_LONGLONG
void test_conversion_from_to_longlong();
void test_conversion_from_to_ulonglong();
#endif
#ifdef BOOST_HAS_INT128
void test_conversion_from_to_int128();
void test_conversion_from_to_uint128();
#endif
void test_integral_conversions_on_min_max();
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast unit test on integral types");
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_short));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_ushort));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_int));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_uint));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_long));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_ulong));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_intmax_t));
suite->add(BOOST_TEST_CASE(&test_conversion_from_to_uintmax_t));
#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));
return suite;
}
template<class T, class CharT>
void test_conversion_from_integral_to_char(CharT zero)
{
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(0)) == zero + 0);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(1)) == zero + 1);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(2)) == zero + 2);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(3)) == zero + 3);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(4)) == zero + 4);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(5)) == zero + 5);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(6)) == zero + 6);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(7)) == zero + 7);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(8)) == zero + 8);
BOOST_CHECK(lexical_cast<CharT>(static_cast<T>(9)) == zero + 9);
BOOST_CHECK_THROW(lexical_cast<CharT>(static_cast<T>(10)), bad_lexical_cast);
T t = (std::numeric_limits<T>::max)();
BOOST_CHECK_THROW(lexical_cast<CharT>(t), bad_lexical_cast);
}
template<class T, class CharT>
void test_conversion_from_char_to_integral(CharT zero)
{
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 0)) == static_cast<T>(0) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 1)) == static_cast<T>(1) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 2)) == static_cast<T>(2) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 3)) == static_cast<T>(3) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 4)) == static_cast<T>(4) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 5)) == static_cast<T>(5) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 6)) == static_cast<T>(6) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 7)) == static_cast<T>(7) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 8)) == static_cast<T>(8) );
BOOST_CHECK(lexical_cast<T>( static_cast<CharT>(zero + 9)) == static_cast<T>(9) );
BOOST_CHECK_THROW(lexical_cast<T>( static_cast<CharT>(zero + 10)), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( static_cast<CharT>(zero - 1)), bad_lexical_cast);
}
template<class T>
void test_conversion_from_integral_to_integral()
{
T t = 0;
BOOST_CHECK(lexical_cast<T>(t) == t);
// Next two variables are used to supress warnings.
int st = 32767; unsigned int ut = st;
t = st;
BOOST_CHECK(lexical_cast<short>(t) == st);
BOOST_CHECK(lexical_cast<unsigned short>(t) == ut);
BOOST_CHECK(lexical_cast<int>(t) == st);
BOOST_CHECK(lexical_cast<unsigned int>(t) == ut);
BOOST_CHECK(lexical_cast<long>(t) == st);
BOOST_CHECK(lexical_cast<unsigned long>(t) == ut);
t = (std::numeric_limits<T>::max)();
BOOST_CHECK(lexical_cast<T>(t) == t);
t = (std::numeric_limits<T>::min)();
BOOST_CHECK(lexical_cast<T>(t) == t);
}
// Replace "-,999" with "-999".
template<class CharT>
std::basic_string<CharT> to_str_gcc_workaround(std::basic_string<CharT> str)
{
std::locale loc;
std::numpunct<CharT> const& np = BOOST_USE_FACET(std::numpunct<CharT>, loc);
std::ctype<CharT> const& ct = BOOST_USE_FACET(std::ctype<CharT>, loc);
if(np.grouping().empty())
return str;
CharT prefix[3] = { ct.widen('-'), np.thousands_sep(), CharT() };
if(str.find(prefix) != 0)
return str;
prefix[1] = CharT();
str.replace(0, 2, prefix);
return str;
}
template<class CharT, class T>
std::basic_string<CharT> to_str(T t)
{
std::basic_ostringstream<CharT> o;
o << t;
return to_str_gcc_workaround(o.str());
}
template<class T, class CharT>
void test_conversion_from_integral_to_string(CharT)
{
typedef std::numeric_limits<T> limits;
typedef std::basic_string<CharT> string_type;
T t;
t = (limits::min)();
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
t = (limits::max)();
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
if(limits::digits <= 16 && lcast_test_small_integral_types_completely)
// min and max have already been tested.
for(t = 1 + (limits::min)(); t != (limits::max)(); ++t)
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
else
{
T const min_val = (limits::min)();
T const max_val = (limits::max)();
T const half_max_val = max_val / 2;
T const cnt = lcast_integral_test_counter; // to supress warnings
unsigned int const counter = cnt < half_max_val ? cnt : half_max_val;
unsigned int i;
// Test values around min:
t = min_val;
for(i = 0; i < counter; ++i, ++t)
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
// Test values around max:
t = max_val;
for(i = 0; i < counter; ++i, --t)
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
// Test values around zero:
if(limits::is_signed)
for(t = static_cast<T>(-counter); t < static_cast<T>(counter); ++t)
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
// Test values around 100, 1000, 10000, ...
T ten_power = 100;
for(int e = 2; e < limits::digits10; ++e, ten_power *= 10)
{
// ten_power + 100 probably never overflows
for(t = ten_power - 100; t != ten_power + 100; ++t)
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
}
}
}
template<class T, class CharT>
void test_conversion_from_string_to_integral(CharT)
{
typedef std::numeric_limits<T> limits;
typedef std::basic_string<CharT> string_type;
string_type s;
string_type const zero = to_str<CharT>(0);
string_type const nine = to_str<CharT>(9);
T const min_val = (limits::min)();
T const max_val = (limits::max)();
s = to_str<CharT>(min_val);
BOOST_CHECK_EQUAL(lexical_cast<T>(s), min_val);
if(limits::is_signed)
{
BOOST_CHECK_THROW(lexical_cast<T>(s + zero), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>(s + nine), bad_lexical_cast);
}
s = to_str<CharT>(max_val);
BOOST_CHECK_EQUAL(lexical_cast<T>(s), max_val);
{
BOOST_CHECK_THROW(lexical_cast<T>(s + zero), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>(s + nine), bad_lexical_cast);
s = to_str<CharT>(max_val);
for (int i =1; i <=10; ++i) {
s[s.size()-1] += 1;
BOOST_CHECK_THROW(lexical_cast<T>( s ), bad_lexical_cast);
}
s = to_str<CharT>(max_val);
std::locale loc;
typedef std::numpunct<char> numpunct;
if ( BOOST_USE_FACET(numpunct, loc).grouping().empty() ) {
// Following tests work well for locale C
BOOST_CHECK_EQUAL(lexical_cast<T>(to_str<CharT>(0)+s), max_val);
BOOST_CHECK_EQUAL(lexical_cast<T>(to_str<CharT>(0)+to_str<CharT>(0)+s), max_val);
BOOST_CHECK_EQUAL(lexical_cast<T>(to_str<CharT>(0)+to_str<CharT>(0)+to_str<CharT>(0)+s), max_val);
}
for (int i =1; i <=256; ++i) {
BOOST_CHECK_THROW(lexical_cast<T>( to_str<CharT>(i)+s ), bad_lexical_cast);
}
typedef BOOST_DEDUCED_TYPENAME boost::integral_promotion<T>::type promoted;
if ( !(boost::is_same<T, promoted>::value) )
{
promoted prom = max_val;
s = to_str<CharT>(max_val);
for (int i =1; i <=256; ++i) {
BOOST_CHECK_THROW(lexical_cast<T>( to_str<CharT>(prom+i) ), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( to_str<CharT>(i)+s ), bad_lexical_cast);
}
}
}
if(limits::digits <= 16 && lcast_test_small_integral_types_completely)
// min and max have already been tested.
for(T t = 1 + min_val; t != max_val; ++t)
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
else
{
T const half_max_val = max_val / 2;
T const cnt = lcast_integral_test_counter; // to supress warnings
unsigned int const counter = cnt < half_max_val ? cnt : half_max_val;
T t;
unsigned int i;
// Test values around min:
t = min_val;
for(i = 0; i < counter; ++i, ++t)
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
// Test values around max:
t = max_val;
for(i = 0; i < counter; ++i, --t)
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
// Test values around zero:
if(limits::is_signed)
for(t = static_cast<T>(-counter); t < static_cast<T>(counter); ++t)
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
// Test values around 100, 1000, 10000, ...
T ten_power = 100;
for(int e = 2; e < limits::digits10; ++e, ten_power *= 10)
{
// ten_power + 100 probably never overflows
for(t = ten_power - 100; t != ten_power + 100; ++t)
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
}
}
}
template<class T>
void test_conversion_from_to_integral_for_locale()
{
std::locale current_locale;
typedef std::numpunct<char> numpunct;
numpunct const& np = BOOST_USE_FACET(numpunct, current_locale);
if ( !np.grouping().empty() )
{
BOOST_CHECK_THROW(
lexical_cast<T>( std::string("100") + np.thousands_sep() + np.thousands_sep() + "0" )
, bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( std::string("100") + np.thousands_sep() ), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( np.thousands_sep() + std::string("100") ), bad_lexical_cast);
// Exception must not be thrown, when we are using no separators at all
BOOST_CHECK( lexical_cast<T>("30000") == static_cast<T>(30000) );
}
test_conversion_from_integral_to_integral<T>();
test_conversion_from_integral_to_string<T>('0');
test_conversion_from_string_to_integral<T>('0');
#if !defined(BOOST_LCAST_NO_WCHAR_T)
test_conversion_from_integral_to_string<T>(L'0');
test_conversion_from_string_to_integral<T>(L'0');
#endif
}
struct restore_oldloc
{
std::locale oldloc;
~restore_oldloc() { std::locale::global(oldloc); }
};
template<class T>
void test_conversion_from_to_integral_minimal()
{
char const zero = '0';
signed char const szero = '0';
unsigned char const uzero = '0';
test_conversion_from_integral_to_char<T>(zero);
test_conversion_from_char_to_integral<T>(zero);
test_conversion_from_integral_to_char<T>(szero);
test_conversion_from_char_to_integral<T>(szero);
test_conversion_from_integral_to_char<T>(uzero);
test_conversion_from_char_to_integral<T>(uzero);
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
wchar_t const wzero = L'0';
test_conversion_from_integral_to_char<T>(wzero);
test_conversion_from_char_to_integral<T>(wzero);
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
char16_t const u16zero = u'0';
test_conversion_from_integral_to_char<T>(u16zero);
test_conversion_from_char_to_integral<T>(u16zero);
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION)
char32_t const u32zero = u'0';
test_conversion_from_integral_to_char<T>(u32zero);
test_conversion_from_char_to_integral<T>(u32zero);
#endif
BOOST_CHECK(lexical_cast<T>("-1") == static_cast<T>(-1));
BOOST_CHECK(lexical_cast<T>("-9") == static_cast<T>(-9));
BOOST_CHECK(lexical_cast<T>(-1) == static_cast<T>(-1));
BOOST_CHECK(lexical_cast<T>(-9) == static_cast<T>(-9));
BOOST_CHECK_THROW(lexical_cast<T>("-1.0"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>("-9.0"), bad_lexical_cast);
BOOST_CHECK(lexical_cast<T>(-1.0) == static_cast<T>(-1));
BOOST_CHECK(lexical_cast<T>(-9.0) == static_cast<T>(-9));
BOOST_CHECK(lexical_cast<T>(static_cast<T>(1)) == static_cast<T>(1));
BOOST_CHECK(lexical_cast<T>(static_cast<T>(9)) == static_cast<T>(9));
BOOST_CHECK_THROW(lexical_cast<T>(1.1f), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>(1.1), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>(1.1L), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>(1.0001f), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>(1.0001), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>(1.0001L), bad_lexical_cast);
BOOST_CHECK(lexical_cast<T>("+1") == static_cast<T>(1) );
BOOST_CHECK(lexical_cast<T>("+9") == static_cast<T>(9) );
BOOST_CHECK(lexical_cast<T>("+10") == static_cast<T>(10) );
BOOST_CHECK(lexical_cast<T>("+90") == static_cast<T>(90) );
BOOST_CHECK_THROW(lexical_cast<T>("++1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>("-+9"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>("--1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>("+-9"), bad_lexical_cast);
// test_conversion_from_to_integral_for_locale
// Overflow test case from David W. Birdsall
std::string must_owerflow_str = (sizeof(T) < 16 ? "160000000000000000000" : "1600000000000000000000000000000000000000");
std::string must_owerflow_negative_str = (sizeof(T) < 16 ? "-160000000000000000000" : "-1600000000000000000000000000000000000000");
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);
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;
std::locale const& oldloc = guard.oldloc;
std::string grouping1 = BOOST_USE_FACET(numpunct, oldloc).grouping();
std::string grouping2(grouping1);
test_conversion_from_to_integral_for_locale<T>();
try
{
std::locale newloc("");
std::locale::global(newloc);
grouping2 = BOOST_USE_FACET(numpunct, newloc).grouping();
}
catch(std::exception const& ex)
{
std::string msg("Failed to set system locale: ");
msg += ex.what();
BOOST_TEST_MESSAGE(msg);
}
if(grouping1 != grouping2)
test_conversion_from_to_integral_for_locale<T>();
if(grouping1.empty() && grouping2.empty())
BOOST_TEST_MESSAGE("Formatting with thousands_sep has not been tested");
}
void test_conversion_from_to_short()
{
test_conversion_from_to_integral<short>();
}
void test_conversion_from_to_ushort()
{
test_conversion_from_to_integral<unsigned short>();
}
void test_conversion_from_to_int()
{
test_conversion_from_to_integral<int>();
}
void test_conversion_from_to_uint()
{
test_conversion_from_to_integral<unsigned int>();
}
void test_conversion_from_to_long()
{
test_conversion_from_to_integral<long>();
}
void test_conversion_from_to_ulong()
{
test_conversion_from_to_integral<unsigned long>();
}
void test_conversion_from_to_intmax_t()
{
test_conversion_from_to_integral<boost::intmax_t>();
}
void test_conversion_from_to_uintmax_t()
{
test_conversion_from_to_integral<boost::uintmax_t>();
}
#if defined(BOOST_HAS_LONG_LONG)
void test_conversion_from_to_longlong()
{
test_conversion_from_to_integral<boost::long_long_type>();
}
void test_conversion_from_to_ulonglong()
{
test_conversion_from_to_integral<boost::ulong_long_type>();
}
#elif defined(BOOST_HAS_MS_INT64)
void test_conversion_from_to_longlong()
{
test_conversion_from_to_integral<__int64>();
}
void test_conversion_from_to_ulonglong()
{
test_conversion_from_to_integral<unsigned __int64>();
}
#endif
#ifdef BOOST_HAS_INT128
template <bool Specialized, class T>
struct test_if_specialized {
static void test() {}
};
template <class T>
struct test_if_specialized<true, T> {
static void test() {
test_conversion_from_to_integral_minimal<T>();
}
};
void test_conversion_from_to_int128()
{
test_if_specialized<
std::numeric_limits<boost::int128_type>::is_specialized,
boost::int128_type
>::test();
}
void test_conversion_from_to_uint128()
{
test_if_specialized<
std::numeric_limits<boost::int128_type>::is_specialized,
boost::uint128_type
>::test();
}
#endif
template <typename SignedT>
void test_integral_conversions_on_min_max_impl()
{
typedef SignedT signed_t;
typedef BOOST_DEDUCED_TYPENAME boost::make_unsigned<signed_t>::type unsigned_t;
typedef std::numeric_limits<signed_t> s_limits;
typedef std::numeric_limits<unsigned_t> uns_limits;
BOOST_CHECK_EQUAL(lexical_cast<unsigned_t>((uns_limits::max)()), (uns_limits::max)());
BOOST_CHECK_EQUAL(lexical_cast<unsigned_t>((uns_limits::min)()), (uns_limits::min)());
BOOST_CHECK_EQUAL(lexical_cast<signed_t>((s_limits::max)()), (s_limits::max)());
BOOST_CHECK_EQUAL(lexical_cast<signed_t>((uns_limits::min)()), static_cast<signed_t>((uns_limits::min)()));
BOOST_CHECK_EQUAL(lexical_cast<unsigned_t>((s_limits::max)()), static_cast<unsigned_t>((s_limits::max)()));
BOOST_CHECK_EQUAL(lexical_cast<unsigned_t>((s_limits::min)()), static_cast<unsigned_t>((s_limits::min)()));
}
void test_integral_conversions_on_min_max()
{
test_integral_conversions_on_min_max_impl<int>();
test_integral_conversions_on_min_max_impl<short>();
#ifdef _MSC_VER
test_integral_conversions_on_min_max_impl<long int>();
#if defined(BOOST_HAS_LONG_LONG)
test_integral_conversions_on_min_max_impl<boost::long_long_type>();
#elif defined(BOOST_HAS_MS_INT64)
test_integral_conversions_on_min_max_impl<__int64>();
#endif
#ifdef BOOST_HAS_INT128
test_integral_conversions_on_min_max_impl<boost::int128_type>();
#endif
#endif
}
-245
View File
@@ -1,245 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/range/iterator_range.hpp>
using namespace boost;
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#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;
operator int() const {
return i;
}
};
template <class CharT>
inline std::basic_istream<CharT>& operator >> (std::basic_istream<CharT>& istr, class_with_user_defined_sream_operators& rhs)
{
return istr >> rhs.i;
}
template <class RngT>
void do_test_iterator_range_impl(const RngT& rng)
{
BOOST_CHECK_EQUAL(lexical_cast<int>(rng), 1);
BOOST_CHECK_EQUAL(lexical_cast<int>(rng.begin(), rng.size()), 1);
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(rng), 1u);
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(rng.begin(), rng.size()), 1u);
BOOST_CHECK_EQUAL(lexical_cast<short>(rng), 1);
BOOST_CHECK_EQUAL(lexical_cast<short>(rng.begin(), rng.size()), 1);
BOOST_CHECK_EQUAL(lexical_cast<unsigned short>(rng), 1u);
BOOST_CHECK_EQUAL(lexical_cast<unsigned short>(rng.begin(), rng.size()), 1u);
BOOST_CHECK_EQUAL(lexical_cast<long int>(rng), 1);
BOOST_CHECK_EQUAL(lexical_cast<long int>(rng.begin(), rng.size()), 1);
BOOST_CHECK_EQUAL(lexical_cast<unsigned long int>(rng), 1u);
BOOST_CHECK_EQUAL(lexical_cast<unsigned long int>(rng.begin(), rng.size()), 1u);
#ifdef BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES
BOOST_CHECK_EQUAL(lexical_cast<float>(rng), 1.0f);
BOOST_CHECK_EQUAL(lexical_cast<float>(rng.begin(), rng.size()), 1.0f);
BOOST_CHECK_EQUAL(lexical_cast<double>(rng), 1.0);
BOOST_CHECK_EQUAL(lexical_cast<double>(rng.begin(), rng.size()), 1.0);
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
BOOST_CHECK_EQUAL(lexical_cast<long double>(rng), 1.0L);
BOOST_CHECK_EQUAL(lexical_cast<long double>(rng.begin(), rng.size()), 1.0L);
#endif
BOOST_CHECK_EQUAL(lexical_cast<class_with_user_defined_sream_operators>(rng), 1);
#endif
#if defined(BOOST_HAS_LONG_LONG)
BOOST_CHECK_EQUAL(lexical_cast<boost::ulong_long_type>(rng), 1u);
BOOST_CHECK_EQUAL(lexical_cast<boost::ulong_long_type>(rng.begin(), rng.size()), 1u);
BOOST_CHECK_EQUAL(lexical_cast<boost::long_long_type>(rng), 1);
BOOST_CHECK_EQUAL(lexical_cast<boost::long_long_type>(rng.begin(), rng.size()), 1);
#elif defined(BOOST_HAS_MS_INT64)
BOOST_CHECK_EQUAL(lexical_cast<unsigned __int64>(rng), 1u);
BOOST_CHECK_EQUAL(lexical_cast<unsigned __int64>(rng.begin(), rng.size()), 1u);
BOOST_CHECK_EQUAL(lexical_cast<__int64>(rng), 1);
BOOST_CHECK_EQUAL(lexical_cast<__int64>(rng.begin(), rng.size()), 1);
#endif
}
template <class CharT>
void test_it_range_using_any_chars(CharT* one, CharT* eleven)
{
typedef CharT test_char_type;
// Zero terminated
iterator_range<test_char_type*> rng1(one, one + 1);
do_test_iterator_range_impl(rng1);
iterator_range<const test_char_type*> crng1(one, one + 1);
do_test_iterator_range_impl(crng1);
// Non zero terminated
iterator_range<test_char_type*> rng2(eleven, eleven + 1);
do_test_iterator_range_impl(rng2);
iterator_range<const test_char_type*> crng2(eleven, eleven + 1);
do_test_iterator_range_impl(crng2);
}
template <class CharT>
void test_it_range_using_char(CharT* one, CharT* eleven)
{
typedef CharT test_char_type;
iterator_range<test_char_type*> rng1(one, one + 1);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(rng1), "1");
iterator_range<const test_char_type*> crng1(one, one + 1);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(crng1), "1");
iterator_range<test_char_type*> rng2(eleven, eleven + 1);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(rng2), "1");
iterator_range<const test_char_type*> crng2(eleven, eleven + 1);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(crng2), "1");
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
BOOST_CHECK(lexical_cast<std::wstring>(rng1) == L"1");
BOOST_CHECK(lexical_cast<std::wstring>(crng1) == L"1");
BOOST_CHECK(lexical_cast<std::wstring>(rng2) == L"1");
BOOST_CHECK(lexical_cast<std::wstring>(crng2) == L"1");
#endif
#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");
BOOST_CHECK(lexical_cast<my_char16_string>(rng2) == u"1");
BOOST_CHECK(lexical_cast<my_char16_string>(crng2) == u"1");
#endif
#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");
BOOST_CHECK(lexical_cast<my_char32_string>(rng2) == U"1");
BOOST_CHECK(lexical_cast<my_char32_string>(crng2) == U"1");
#endif
}
void test_char_iterator_ranges()
{
typedef char test_char_type;
test_char_type data1[] = "1";
test_char_type data2[] = "11";
test_it_range_using_any_chars(data1, data2);
test_it_range_using_char(data1, data2);
}
void test_unsigned_char_iterator_ranges()
{
typedef unsigned char test_char_type;
test_char_type data1[] = "1";
test_char_type data2[] = "11";
test_it_range_using_any_chars(data1, data2);
test_it_range_using_char(data1, data2);
}
void test_signed_char_iterator_ranges()
{
typedef signed char test_char_type;
test_char_type data1[] = "1";
test_char_type data2[] = "11";
test_it_range_using_any_chars(data1, data2);
test_it_range_using_char(data1, data2);
}
void test_wchar_iterator_ranges()
{
#ifndef BOOST_LCAST_NO_WCHAR_T
typedef wchar_t test_char_type;
test_char_type data1[] = L"1";
test_char_type data2[] = L"11";
test_it_range_using_any_chars(data1, data2);
#endif
BOOST_CHECK(true);
}
void test_char16_iterator_ranges()
{
#if defined(BOOST_LC_RUNU16)
typedef char16_t test_char_type;
test_char_type data1[] = u"1";
test_char_type data2[] = u"11";
test_it_range_using_any_chars(data1, data2);
#endif
BOOST_CHECK(true);
}
void test_char32_iterator_ranges()
{
#if defined(BOOST_LC_RUNU32)
typedef char32_t test_char_type;
test_char_type data1[] = U"1";
test_char_type data2[] = U"11";
test_it_range_using_any_chars(data1, data2);
#endif
BOOST_CHECK(true);
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite = BOOST_TEST_SUITE("lexical_cast. Testing conversions using iterator_range<>");
suite->add(BOOST_TEST_CASE(&test_char_iterator_ranges));
suite->add(BOOST_TEST_CASE(&test_unsigned_char_iterator_ranges));
suite->add(BOOST_TEST_CASE(&test_signed_char_iterator_ranges));
suite->add(BOOST_TEST_CASE(&test_wchar_iterator_ranges));
suite->add(BOOST_TEST_CASE(&test_char16_iterator_ranges));
suite->add(BOOST_TEST_CASE(&test_char32_iterator_ranges));
return suite;
}
-96
View File
@@ -1,96 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Alexander Nasonov, 2006.
//
// 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 round-tripping conversion FPT -> string -> FPT,
// where FPT is Floating Point Type.
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost;
void test_round_conversion_float();
void test_round_conversion_double();
void test_round_conversion_long_double();
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_round_conversion_float));
suite->add(BOOST_TEST_CASE(&test_round_conversion_double));
suite->add(BOOST_TEST_CASE(&test_round_conversion_long_double));
return suite;
}
template<class T>
void test_round_conversion()
{
T epsilon = std::numeric_limits<T>::epsilon();
std::string const epsilon_s = boost::lexical_cast<std::string>(epsilon);
BOOST_CHECK(epsilon == lexical_cast<T>(epsilon_s));
T max_ = (std::numeric_limits<T>::max)();
std::string const max_s = boost::lexical_cast<std::string>(max_);
BOOST_CHECK(max_ == lexical_cast<T>(max_s));
T min_ = (std::numeric_limits<T>::min)();
std::string const min_s = boost::lexical_cast<std::string>(min_);
BOOST_CHECK(min_ == lexical_cast<T>(min_s));
T max_div137 = max_ / 137;
std::string max_div137_s = boost::lexical_cast<std::string>(max_div137);
BOOST_CHECK(max_div137 == lexical_cast<T>(max_div137_s));
T epsilon_mult137 = epsilon * 137;
std::string epsilon_mult137_s(lexical_cast<std::string>(epsilon_mult137));
BOOST_CHECK(epsilon_mult137 == lexical_cast<T>(epsilon_mult137_s));
}
// See bug http://tinyurl.com/vhpvo
template<class T>
void test_msvc_magic_values()
{
T magic_msvc = 0.00010000433948393407;
std::string magic_msvc_s = boost::lexical_cast<std::string>(magic_msvc);
BOOST_CHECK(magic_msvc == lexical_cast<T>(magic_msvc_s));
}
void test_round_conversion_float()
{
test_round_conversion<float>();
}
void test_round_conversion_double()
{
test_round_conversion<double>();
test_msvc_magic_values<double>();
}
void test_round_conversion_long_double()
{
// We do not run tests on compilers with bugs
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
test_round_conversion<long double>();
test_msvc_magic_values<long double>();
#endif
BOOST_CHECK(true);
}
-95
View File
@@ -1,95 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/range/iterator_range.hpp>
#ifndef BOOST_NO_EXCEPTIONS
#error "This test must be compiled with -DBOOST_NO_EXCEPTIONS"
#endif
bool g_was_exception = false;
namespace boost {
void throw_exception(std::exception const & ) {
g_was_exception = true;
}
}
using namespace boost;
struct Escape
{
Escape(){}
Escape(const std::string& s)
: str_(s)
{}
std::string str_;
};
inline std::ostream& operator<< (std::ostream& o, const Escape& rhs)
{
return o << rhs.str_;
}
inline std::istream& operator>> (std::istream& i, Escape& rhs)
{
return i >> rhs.str_;
}
void test_exceptions_off()
{
Escape v("");
g_was_exception = false;
lexical_cast<char>(v);
BOOST_CHECK(g_was_exception);
g_was_exception = false;
lexical_cast<unsigned char>(v);
BOOST_CHECK(g_was_exception);
v = lexical_cast<Escape>(100);
BOOST_CHECK_EQUAL(lexical_cast<int>(v), 100);
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(v), 100u);
v = lexical_cast<Escape>(0.0);
BOOST_CHECK_EQUAL(lexical_cast<double>(v), 0.0);
BOOST_CHECK_EQUAL(lexical_cast<short>(100), 100);
BOOST_CHECK_EQUAL(lexical_cast<float>(0.0), 0.0);
g_was_exception = false;
lexical_cast<short>(700000);
BOOST_CHECK(g_was_exception);
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast. Testing with BOOST_NO_EXCEPTIONS");
suite->add(BOOST_TEST_CASE(&test_exceptions_off));
return suite;
}
-168
View File
@@ -1,168 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/range/iterator_range.hpp>
using namespace boost;
// Testing compilation and some basic usage with BOOST_NO_STD_LOCALE
// Tests are mainly copyied from lexical_cast_empty_input_test.cpp (something
// new added to test_empty_3)
#ifndef BOOST_NO_STD_LOCALE
#error "This test must be compiled with -DBOOST_NO_STD_LOCALE"
#endif
template <class T>
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)
BOOST_CHECK_THROW(lexical_cast<boost::ulong_long_type>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<boost::long_long_type>(v), bad_lexical_cast);
#elif defined(BOOST_HAS_MS_INT64)
BOOST_CHECK_THROW(lexical_cast<unsigned __int64>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<__int64>(v), bad_lexical_cast);
#endif
}
void test_empty_1()
{
boost::iterator_range<char*> v;
do_test_on_empty_input(v);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(v), std::string());
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
boost::iterator_range<const char*> cv;
do_test_on_empty_input(cv);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(cv), std::string());
BOOST_CHECK_THROW(lexical_cast<char>(cv), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(cv), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(cv), bad_lexical_cast);
const boost::iterator_range<const char*> ccv;
do_test_on_empty_input(ccv);
BOOST_CHECK_EQUAL(lexical_cast<std::string>(ccv), std::string());
BOOST_CHECK_THROW(lexical_cast<char>(ccv), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(ccv), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(ccv), bad_lexical_cast);
}
void test_empty_2()
{
std::string v;
do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
}
struct Escape
{
Escape(){}
Escape(const std::string& s)
: str_(s)
{}
std::string str_;
};
inline std::ostream& operator<< (std::ostream& o, const Escape& rhs)
{
return o << rhs.str_;
}
inline std::istream& operator>> (std::istream& i, Escape& rhs)
{
return i >> rhs.str_;
}
void test_empty_3()
{
Escape v("");
do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
v = lexical_cast<Escape>(100);
BOOST_CHECK_EQUAL(lexical_cast<int>(v), 100);
BOOST_CHECK_EQUAL(lexical_cast<unsigned int>(v), 100u);
v = lexical_cast<Escape>(0.0);
BOOST_CHECK_EQUAL(lexical_cast<double>(v), 0.0);
}
namespace std {
inline std::ostream & operator<<(std::ostream & out, const std::vector<long> & v)
{
std::ostream_iterator<long> it(out);
std::copy(v.begin(), v.end(), it);
assert(out);
return out;
}
}
void test_empty_4()
{
std::vector<long> v;
do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
}
struct my_string {
friend std::ostream &operator<<(std::ostream& sout, my_string const&/* st*/) {
return sout << "";
}
};
void test_empty_5()
{
my_string st;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(st), std::string());;
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast. Testing with BOOST_NO_STD_LOCALE");
suite->add(BOOST_TEST_CASE(&test_empty_1));
suite->add(BOOST_TEST_CASE(&test_empty_2));
suite->add(BOOST_TEST_CASE(&test_empty_3));
suite->add(BOOST_TEST_CASE(&test_empty_4));
suite->add(BOOST_TEST_CASE(&test_empty_5));
return suite;
}
-54
View File
@@ -1,54 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Alexander Nasonov, 2007.
//
// 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 that Source can be non-copyable.
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/noncopyable.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost;
void test_noncopyable();
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_noncopyable));
return suite;
}
class Noncopyable : private boost::noncopyable
{
public:
Noncopyable() {}
};
inline std::ostream &operator<<(std::ostream &out, const Noncopyable&)
{
return out << "Noncopyable";
}
void test_noncopyable()
{
Noncopyable x;
BOOST_CHECK(boost::lexical_cast<std::string>(x) == "Noncopyable");
}
-96
View File
@@ -1,96 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost;
#if defined(BOOST_NO_STRINGSTREAM)
typedef std::strstream ss_t;
#else
typedef std::stringstream ss_t;
#endif
void test_void_pointers_conversions()
{
void *p_to_null = NULL;
const void *cp_to_data = "Some data";
char nonconst_data[5];
void *p_to_data = nonconst_data;
ss_t ss;
ss << p_to_null;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(p_to_null), ss.str());
ss.str(std::string());
ss << cp_to_data;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(cp_to_data), ss.str());
ss.str(std::string());
ss << p_to_data;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(p_to_data), ss.str());
ss.str(std::string());
}
struct incomplete_type;
void test_incomplete_type_pointers_conversions()
{
incomplete_type *p_to_null = NULL;
const incomplete_type *cp_to_data = NULL;
char nonconst_data[5];
incomplete_type *p_to_data = reinterpret_cast<incomplete_type*>(nonconst_data);
ss_t ss;
ss << p_to_null;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(p_to_null), ss.str());
ss.str(std::string());
ss << cp_to_data;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(cp_to_data), ss.str());
ss.str(std::string());
ss << p_to_data;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(p_to_data), ss.str());
ss.str(std::string());
}
struct ble;
typedef struct ble *meh;
std::ostream& operator <<(std::ostream &o, meh) {
o << "yay";
return o;
}
void test_inomplete_type_with_overloaded_ostream_op() {
meh heh = NULL;
ss_t ss;
ss << heh;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(heh), ss.str());
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast pinters test");
suite->add(BOOST_TEST_CASE(&test_void_pointers_conversions));
suite->add(BOOST_TEST_CASE(&test_incomplete_type_pointers_conversions));
suite->add(BOOST_TEST_CASE(&test_inomplete_type_with_overloaded_ostream_op));
return suite;
}
-307
View File
@@ -1,307 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>
///////////////////////// char streamable classes ///////////////////////////////////////////
struct streamable_easy { enum ENU {value = 0}; };
std::ostream& operator << (std::ostream& ostr, const streamable_easy&) {
return ostr << streamable_easy::value;
}
std::istream& operator >> (std::istream& istr, const streamable_easy&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, streamable_easy::value);
return istr;
}
struct streamable_medium { enum ENU {value = 1}; };
template <class CharT>
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_ostream<CharT>&>::type
operator << (std::basic_ostream<CharT>& ostr, const streamable_medium&) {
return ostr << streamable_medium::value;
}
template <class CharT>
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_istream<CharT>&>::type
operator >> (std::basic_istream<CharT>& istr, const streamable_medium&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, streamable_medium::value);
return istr;
}
struct streamable_hard { enum ENU {value = 2}; };
template <class CharT, class TraitsT>
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_ostream<CharT, TraitsT>&>::type
operator << (std::basic_ostream<CharT, TraitsT>& ostr, const streamable_hard&) {
return ostr << streamable_hard::value;
}
template <class CharT, class TraitsT>
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_istream<CharT, TraitsT>&>::type
operator >> (std::basic_istream<CharT, TraitsT>& istr, const streamable_hard&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, streamable_hard::value);
return istr;
}
struct streamable_hard2 { enum ENU {value = 3}; };
template <class TraitsT>
std::basic_ostream<char, TraitsT>& operator << (std::basic_ostream<char, TraitsT>& ostr, const streamable_hard2&) {
return ostr << streamable_hard2::value;
}
template <class TraitsT>
std::basic_istream<char, TraitsT>& operator >> (std::basic_istream<char, TraitsT>& istr, const streamable_hard2&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, streamable_hard2::value);
return istr;
}
///////////////////////// wchar_t streamable classes ///////////////////////////////////////////
struct wstreamable_easy { enum ENU {value = 4}; };
std::wostream& operator << (std::wostream& ostr, const wstreamable_easy&) {
return ostr << wstreamable_easy::value;
}
std::wistream& operator >> (std::wistream& istr, const wstreamable_easy&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, wstreamable_easy::value);
return istr;
}
struct wstreamable_medium { enum ENU {value = 5}; };
template <class CharT>
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_ostream<CharT>& >::type
operator << (std::basic_ostream<CharT>& ostr, const wstreamable_medium&) {
return ostr << wstreamable_medium::value;
}
template <class CharT>
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_istream<CharT>& >::type
operator >> (std::basic_istream<CharT>& istr, const wstreamable_medium&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, wstreamable_medium::value);
return istr;
}
struct wstreamable_hard { enum ENU {value = 6}; };
template <class CharT, class TraitsT>
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_ostream<CharT, TraitsT>&>::type
operator << (std::basic_ostream<CharT, TraitsT>& ostr, const wstreamable_hard&) {
return ostr << wstreamable_hard::value;
}
template <class CharT, class TraitsT>
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_istream<CharT, TraitsT>&>::type
operator >> (std::basic_istream<CharT, TraitsT>& istr, const wstreamable_hard&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, wstreamable_hard::value);
return istr;
}
struct wstreamable_hard2 { enum ENU {value = 7}; };
template <class TraitsT>
std::basic_ostream<wchar_t, TraitsT>& operator << (std::basic_ostream<wchar_t, TraitsT>& ostr, const wstreamable_hard2&) {
return ostr << wstreamable_hard2::value;
}
template <class TraitsT>
std::basic_istream<wchar_t, TraitsT>& operator >> (std::basic_istream<wchar_t, TraitsT>& istr, const wstreamable_hard2&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, wstreamable_hard2::value);
return istr;
}
///////////////////////// char and wchar_t streamable classes ///////////////////////////////////////////
struct bistreamable_easy { enum ENU {value = 8}; };
std::ostream& operator << (std::ostream& ostr, const bistreamable_easy&) {
return ostr << bistreamable_easy::value;
}
std::istream& operator >> (std::istream& istr, const bistreamable_easy&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_easy::value);
return istr;
}
std::wostream& operator << (std::wostream& ostr, const bistreamable_easy&) {
return ostr << bistreamable_easy::value + 100;
}
std::wistream& operator >> (std::wistream& istr, const bistreamable_easy&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_easy::value + 100);
return istr;
}
struct bistreamable_medium { enum ENU {value = 9}; };
template <class CharT>
std::basic_ostream<CharT>& operator << (std::basic_ostream<CharT>& ostr, const bistreamable_medium&) {
return ostr << bistreamable_medium::value + (sizeof(CharT) == 1 ? 0 : 100);
}
template <class CharT>
std::basic_istream<CharT>& operator >> (std::basic_istream<CharT>& istr, const bistreamable_medium&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_medium::value + (sizeof(CharT) == 1 ? 0 : 100));
return istr;
}
struct bistreamable_hard { enum ENU {value = 10}; };
template <class CharT, class TraitsT>
std::basic_ostream<CharT, TraitsT>& operator << (std::basic_ostream<CharT, TraitsT>& ostr, const bistreamable_hard&) {
return ostr << bistreamable_hard::value + (sizeof(CharT) == 1 ? 0 : 100);
}
template <class CharT, class TraitsT>
std::basic_istream<CharT, TraitsT>& operator >> (std::basic_istream<CharT, TraitsT>& istr, const bistreamable_hard&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_hard::value + (sizeof(CharT) == 1 ? 0 : 100));
return istr;
}
struct bistreamable_hard2 { enum ENU {value = 11}; };
template <class TraitsT>
std::basic_ostream<char, TraitsT>& operator << (std::basic_ostream<char, TraitsT>& ostr, const bistreamable_hard2&) {
return ostr << bistreamable_hard2::value;
}
template <class TraitsT>
std::basic_istream<char, TraitsT>& operator >> (std::basic_istream<char, TraitsT>& istr, const bistreamable_hard2&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_hard2::value);
return istr;
}
template <class TraitsT>
std::basic_ostream<wchar_t, TraitsT>& operator << (std::basic_ostream<wchar_t, TraitsT>& ostr, const bistreamable_hard2&) {
return ostr << bistreamable_hard2::value + 100;
}
template <class TraitsT>
std::basic_istream<wchar_t, TraitsT>& operator >> (std::basic_istream<wchar_t, TraitsT>& istr, const bistreamable_hard2&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, bistreamable_hard2::value + 100);
return istr;
}
void test_ostream_character_detection();
void test_istream_character_detection();
void test_mixed_stream_character_detection();
boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
{
boost::unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast stream character detection");
suite->add(BOOST_TEST_CASE(&test_ostream_character_detection));
suite->add(BOOST_TEST_CASE(&test_istream_character_detection));
suite->add(BOOST_TEST_CASE(&test_mixed_stream_character_detection));
return suite;
}
template <class T>
static void test_ostr_impl() {
T streamable;
BOOST_CHECK_EQUAL(T::value, boost::lexical_cast<int>(streamable));
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(T::value), boost::lexical_cast<std::string>(streamable));
}
template <class T>
static void test_wostr_impl() {
T streamable;
BOOST_CHECK_EQUAL(T::value, boost::lexical_cast<int>(streamable));
// BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(T::value), boost::lexical_cast<std::string>(streamable)); // Shall not compile???
BOOST_CHECK(boost::lexical_cast<std::wstring>(T::value) == boost::lexical_cast<std::wstring>(streamable));
}
template <class T>
static void test_bistr_impl() {
T streamable;
BOOST_CHECK_EQUAL(T::value, boost::lexical_cast<int>(streamable));
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(T::value), boost::lexical_cast<std::string>(streamable));
BOOST_CHECK(boost::lexical_cast<std::wstring>(T::value + 100) == boost::lexical_cast<std::wstring>(streamable));
}
void test_ostream_character_detection() {
test_ostr_impl<streamable_easy>();
test_ostr_impl<streamable_medium>();
test_ostr_impl<streamable_hard>();
test_ostr_impl<streamable_hard2>();
test_wostr_impl<wstreamable_easy>();
test_wostr_impl<wstreamable_medium>();
test_wostr_impl<wstreamable_hard>();
test_wostr_impl<wstreamable_hard2>();
test_bistr_impl<bistreamable_easy>();
test_bistr_impl<bistreamable_medium>();
test_bistr_impl<bistreamable_hard>();
test_bistr_impl<bistreamable_hard2>();
}
template <class T>
static void test_istr_impl() {
boost::lexical_cast<T>(T::value);
boost::lexical_cast<T>(boost::lexical_cast<std::string>(T::value));
}
template <class T>
static void test_wistr_impl() {
boost::lexical_cast<T>(T::value);
//boost::lexical_cast<T>(boost::lexical_cast<std::string>(T::value)); // Shall not compile???
boost::lexical_cast<T>(boost::lexical_cast<std::wstring>(T::value));
}
template <class T>
static void test_bistr_instr_impl() {
boost::lexical_cast<T>(T::value);
boost::lexical_cast<T>(boost::lexical_cast<std::string>(T::value));
boost::lexical_cast<T>(boost::lexical_cast<std::wstring>(T::value + 100));
}
void test_istream_character_detection() {
test_istr_impl<streamable_easy>();
test_istr_impl<streamable_medium>();
test_istr_impl<streamable_hard>();
test_istr_impl<streamable_hard2>();
test_wistr_impl<wstreamable_easy>();
test_wistr_impl<wstreamable_medium>();
test_wistr_impl<wstreamable_hard>();
test_wistr_impl<wstreamable_hard2>();
test_bistr_instr_impl<bistreamable_easy>();
test_bistr_instr_impl<bistreamable_medium>();
test_bistr_instr_impl<bistreamable_hard>();
test_bistr_instr_impl<bistreamable_hard2>();
}
struct wistreamble_ostreamable { enum ENU {value = 200}; };
std::ostream& operator << (std::ostream& ostr, const wistreamble_ostreamable&) {
return ostr << wistreamble_ostreamable::value;
}
std::wistream& operator >> (std::wistream& istr, const wistreamble_ostreamable&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, wistreamble_ostreamable::value);
return istr;
}
struct istreamble_wostreamable { enum ENU {value = 201}; };
std::wostream& operator << (std::wostream& ostr, const istreamble_wostreamable&) {
return ostr << istreamble_wostreamable::value;
}
std::istream& operator >> (std::istream& istr, const istreamble_wostreamable&) {
int i; istr >> i; BOOST_CHECK_EQUAL(i, istreamble_wostreamable::value);
return istr;
}
void test_mixed_stream_character_detection() {
//boost::lexical_cast<std::wstring>(std::string("qwe")); // TODO: ALLOW IT AS EXTENSION!
boost::lexical_cast<wistreamble_ostreamable>(wistreamble_ostreamable::value);
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(wistreamble_ostreamable()), wistreamble_ostreamable::value);
boost::lexical_cast<istreamble_wostreamable>(istreamble_wostreamable::value);
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(istreamble_wostreamable()), istreamble_wostreamable::value);
}
-158
View File
@@ -1,158 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
template <class T>
static void test_optimized_types_to_string_const()
{
namespace de = boost::detail;
typedef de::lexical_cast_stream_traits<T, std::string> trait_1;
BOOST_CHECK(!trait_1::is_source_input_not_optimized_t::value);
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_1::src_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_1::target_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_1::char_type, char>::value));
BOOST_CHECK(!trait_1::is_string_widening_required_t::value);
BOOST_CHECK(!trait_1::is_source_input_not_optimized_t::value);
typedef de::lexical_cast_stream_traits<const T, std::string> trait_2;
BOOST_CHECK(!trait_2::is_source_input_not_optimized_t::value);
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_2::src_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_2::target_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_2::char_type, char>::value));
BOOST_CHECK(!trait_2::is_string_widening_required_t::value);
BOOST_CHECK(!trait_2::is_source_input_not_optimized_t::value);
typedef de::lexical_cast_stream_traits<T, std::wstring> trait_3;
BOOST_CHECK(!trait_3::is_source_input_not_optimized_t::value);
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_3::src_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_3::target_char_t, wchar_t>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_3::char_type, wchar_t>::value));
BOOST_CHECK((boost::detail::is_char_or_wchar<BOOST_DEDUCED_TYPENAME trait_3::no_cv_src>::value != trait_3::is_string_widening_required_t::value));
BOOST_CHECK(!trait_3::is_source_input_not_optimized_t::value);
}
template <class T>
static void test_optimized_types_to_string()
{
test_optimized_types_to_string_const<T>();
namespace de = boost::detail;
typedef de::lexical_cast_stream_traits<std::string, T> trait_4;
BOOST_CHECK(!trait_4::is_source_input_not_optimized_t::value);
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_4::src_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_4::target_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_4::char_type, char>::value));
BOOST_CHECK(!trait_4::is_string_widening_required_t::value);
BOOST_CHECK(!trait_4::is_source_input_not_optimized_t::value);
typedef de::lexical_cast_stream_traits<const std::string, T> trait_5;
BOOST_CHECK(!trait_5::is_source_input_not_optimized_t::value);
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_5::src_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_5::target_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_5::char_type, char>::value));
BOOST_CHECK(!trait_5::is_string_widening_required_t::value);
BOOST_CHECK(!trait_5::is_source_input_not_optimized_t::value);
typedef de::lexical_cast_stream_traits<const std::wstring, T> trait_6;
BOOST_CHECK(!trait_6::is_source_input_not_optimized_t::value);
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_6::src_char_t, wchar_t>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_6::target_char_t, char>::value));
BOOST_CHECK((boost::is_same<BOOST_DEDUCED_TYPENAME trait_6::char_type, wchar_t>::value));
BOOST_CHECK(!trait_6::is_string_widening_required_t::value);
}
void test_metafunctions()
{
test_optimized_types_to_string<bool>();
test_optimized_types_to_string<char>();
test_optimized_types_to_string<unsigned char>();
test_optimized_types_to_string<signed char>();
test_optimized_types_to_string<short>();
test_optimized_types_to_string<unsigned short>();
test_optimized_types_to_string<int>();
test_optimized_types_to_string<unsigned int>();
test_optimized_types_to_string<long>();
test_optimized_types_to_string<unsigned long>();
#if defined(BOOST_HAS_LONG_LONG)
test_optimized_types_to_string<boost::ulong_long_type>();
test_optimized_types_to_string<boost::long_long_type>();
#elif defined(BOOST_HAS_MS_INT64)
test_optimized_types_to_string<unsigned __int64>();
test_optimized_types_to_string<__int64>();
#endif
#if !defined(BOOST_NO_SWPRINTF) && !defined(__MINGW32__)
test_optimized_types_to_string<float>();
#endif
test_optimized_types_to_string<std::string>();
test_optimized_types_to_string<char*>();
//test_optimized_types_to_string<char[5]>();
//test_optimized_types_to_string<char[1]>();
test_optimized_types_to_string<unsigned char*>();
//test_optimized_types_to_string<unsigned char[5]>();
//test_optimized_types_to_string<unsigned char[1]>();
test_optimized_types_to_string<signed char*>();
//test_optimized_types_to_string<signed char[5]>();
//test_optimized_types_to_string<signed char[1]>();
test_optimized_types_to_string<boost::array<char, 1> >();
test_optimized_types_to_string<boost::array<char, 5> >();
test_optimized_types_to_string<boost::array<unsigned char, 1> >();
test_optimized_types_to_string<boost::array<unsigned char, 5> >();
test_optimized_types_to_string<boost::array<signed char, 1> >();
test_optimized_types_to_string<boost::array<signed char, 5> >();
test_optimized_types_to_string<boost::iterator_range<char*> >();
test_optimized_types_to_string<boost::iterator_range<unsigned char*> >();
test_optimized_types_to_string<boost::iterator_range<signed char*> >();
test_optimized_types_to_string_const<boost::array<const char, 1> >();
test_optimized_types_to_string_const<boost::array<const char, 5> >();
test_optimized_types_to_string_const<boost::array<const unsigned char, 1> >();
test_optimized_types_to_string_const<boost::array<const unsigned char, 5> >();
test_optimized_types_to_string_const<boost::array<const signed char, 1> >();
test_optimized_types_to_string_const<boost::array<const signed char, 5> >();
test_optimized_types_to_string_const<boost::iterator_range<const char*> >();
test_optimized_types_to_string_const<boost::iterator_range<const unsigned char*> >();
test_optimized_types_to_string_const<boost::iterator_range<const signed char*> >();
#ifndef BOOST_NO_CXX11_HDR_ARRAY
test_optimized_types_to_string<std::array<char, 1> >();
test_optimized_types_to_string<std::array<char, 5> >();
test_optimized_types_to_string<std::array<unsigned char, 1> >();
test_optimized_types_to_string<std::array<unsigned char, 5> >();
test_optimized_types_to_string<std::array<signed char, 1> >();
test_optimized_types_to_string<std::array<signed char, 5> >();
test_optimized_types_to_string_const<std::array<const char, 1> >();
test_optimized_types_to_string_const<std::array<const char, 5> >();
test_optimized_types_to_string_const<std::array<const unsigned char, 1> >();
test_optimized_types_to_string_const<std::array<const unsigned char, 5> >();
test_optimized_types_to_string_const<std::array<const signed char, 1> >();
test_optimized_types_to_string_const<std::array<const signed char, 5> >();
#endif
}
boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
{
boost::unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast traits tests");
suite->add(BOOST_TEST_CASE(&test_metafunctions));
return suite;
}
-23
View File
@@ -1,23 +0,0 @@
// // Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2013.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/lexical_cast.hpp>
#include <boost/type.hpp>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
int test_main(int, char*[])
{
boost::lexical_cast<char*>("Hello");
BOOST_CHECK(false); // suppressing warning about 'boost::unit_test::{anonymous}::unit_test_log' defined but not used
return 0;
}
@@ -1,40 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#include <boost/static_assert.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
void parseDate()
{
std::locale locale;
boost::date_time::format_date_parser<boost::gregorian::date, wchar_t> parser(L"", locale);
boost::date_time::special_values_parser<boost::gregorian::date, wchar_t> svp;
boost::gregorian::date date = parser.parse_date(L"", L"", svp);
(void)date;
}
int main()
{
#ifdef BOOST_MSVC
BOOST_STATIC_ASSERT((boost::is_same<wchar_t, unsigned short>::value));
#endif
parseDate();
return ::boost::lexical_cast<int>(L"1000") == 1000;
}
@@ -1,48 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost;
void test_typedefed_wchar_t_runtime()
{
#ifndef BOOST_LCAST_NO_WCHAR_T
#ifdef BOOST_MSVC
BOOST_STATIC_ASSERT((boost::is_same<wchar_t, unsigned short>::value));
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(L'A'), 65);
BOOST_CHECK_EQUAL(boost::lexical_cast<int>(L'B'), 66);
BOOST_CHECK_EQUAL(boost::lexical_cast<wchar_t>(L"65"), 65);
BOOST_CHECK_EQUAL(boost::lexical_cast<wchar_t>(L"66"), 66);
#endif
#endif
BOOST_CHECK(1);
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast typedefed wchar_t runtime test");
suite->add(BOOST_TEST_CASE(&test_typedefed_wchar_t_runtime));
return suite;
}
-67
View File
@@ -1,67 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Alexander Nasonov, 2007.
//
// 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).
//
// This tests now must pass on vc8, because lexical_cast
// implementation has changed and it does not use stringstream for casts
// to integral types
#include <boost/config.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
#include <boost/test/unit_test.hpp>
#include <string>
using namespace boost;
// See also test_conversion_from_string_to_integral(CharT)
// in libs/conversion/lexical_cast_test.cpp
template<class T, class CharT>
void test_too_long_number(CharT zero)
{
typedef std::numeric_limits<T> limits;
std::basic_string<CharT> s;
std::basic_ostringstream<CharT> o;
o << (limits::max)() << zero;
s = o.str();
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
s[s.size()-1] += static_cast<CharT>(9); // '0' -> '9'
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
if(limits::is_signed)
{
std::basic_ostringstream<CharT> o;
o << (limits::min)() << zero;
s = o.str();
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
s[s.size()-1] += static_cast<CharT>(9); // '0' -> '9'
BOOST_CHECK_THROW(lexical_cast<T>(s), bad_lexical_cast);
}
}
void test_vc8_bug()
{
test_too_long_number<boost::intmax_t>('0');
test_too_long_number<boost::uintmax_t>('0');
#if !defined(BOOST_LCAST_NO_WCHAR_T)
test_too_long_number<boost::intmax_t>(L'0');
test_too_long_number<boost::uintmax_t>(L'0');
#endif
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast vc8 bug unit test");
suite->add(BOOST_TEST_CASE(test_vc8_bug));
return suite;
}
-86
View File
@@ -1,86 +0,0 @@
// Unit test for boost::lexical_cast.
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2012.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/config.hpp>
#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost;
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
template <class CharT>
void test_impl(const CharT* wc_arr)
{
typedef CharT wide_char;
typedef std::basic_string<CharT> wide_string;
const char c_arr[] = "Test array of chars";
const unsigned char uc_arr[] = "Test array of chars";
const signed char sc_arr[] = "Test array of chars";
// Following tests depend on realization of std::locale
// and pass for popular compilers and STL realizations
BOOST_CHECK(boost::lexical_cast<wide_char>(c_arr[0]) == wc_arr[0]);
BOOST_CHECK(boost::lexical_cast<wide_string>(c_arr) == wide_string(wc_arr));
BOOST_CHECK(boost::lexical_cast<wide_string>(sc_arr) == wide_string(wc_arr) );
BOOST_CHECK(boost::lexical_cast<wide_string>(uc_arr) == wide_string(wc_arr) );
BOOST_CHECK_EQUAL(boost::lexical_cast<wide_char>(uc_arr[0]), wc_arr[0]);
BOOST_CHECK_EQUAL(boost::lexical_cast<wide_char>(sc_arr[0]), wc_arr[0]);
}
void test_char_types_conversions_wchar_t()
{
#ifndef BOOST_LCAST_NO_WCHAR_T
test_impl(L"Test array of chars");
#endif
BOOST_CHECK(true);
}
void test_char_types_conversions_char16_t()
{
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
test_impl(u"Test array of chars");
#endif
BOOST_CHECK(true);
}
void test_char_types_conversions_char32_t()
{
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
test_impl(U"Test array of chars");
#endif
BOOST_CHECK(true);
}
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
unit_test::test_suite *suite =
BOOST_TEST_SUITE("lexical_cast char => wide characters unit test (widening test)");
suite->add(BOOST_TEST_CASE(&test_char_types_conversions_wchar_t));
suite->add(BOOST_TEST_CASE(&test_char_types_conversions_char16_t));
suite->add(BOOST_TEST_CASE(&test_char_types_conversions_char32_t));
return suite;
}
+383
View File
@@ -0,0 +1,383 @@
//
// Test boost::polymorphic_cast, boost::polymorphic_downcast and
// boost::polymorphic_pointer_cast, boost::polymorphic_pointer_downcast
//
// Copyright 1999 Beman Dawes
// Copyright 1999 Dave Abrahams
// Copyright 2014 Peter Dimov
// Copyright 2014 Boris Rasin, Antony Polukhin
// Copyright 2023 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
//
#define BOOST_ENABLE_ASSERT_HANDLER
#include <boost/polymorphic_cast.hpp>
#include <boost/polymorphic_pointer_cast.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
#include <memory>
static bool expect_assertion = false;
static int assertion_failed_count = 0;
//assertion handler throws it to exit like assert, but to be able to catch it and stop
//usage: BOOST_TEST_THROWS( function_with_assert(), expected_assertion );
struct expected_assertion {};
// BOOST_ASSERT custom handler
void boost::assertion_failed( char const * expr, char const * function, char const * file, long line )
{
if( expect_assertion )
{
++assertion_failed_count;
throw expected_assertion();
}
else
{
BOOST_ERROR( "unexpected assertion" );
BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< file << "(" << line << "): assertion '" << expr << "' failed in function '"
<< function << "'" << std::endl;
}
}
//
struct Base : boost::intrusive_ref_counter<Base>
{
virtual ~Base() {}
virtual std::string kind() { return "Base"; }
};
struct Base2
{
virtual ~Base2() {}
virtual std::string kind2() { return "Base2"; }
};
struct Derived : public Base, Base2
{
virtual std::string kind() { return "Derived"; }
};
static void test_polymorphic_cast()
{
Base * base = new Derived;
Derived * derived;
try
{
derived = boost::polymorphic_cast<Derived*>( base );
BOOST_TEST( derived != 0 );
if( derived != 0 )
{
BOOST_TEST_EQ( derived->kind(), "Derived" );
}
}
catch( std::bad_cast const& )
{
BOOST_ERROR( "boost::polymorphic_cast<Derived*>( base ) threw std::bad_cast" );
}
Base2 * base2;
try
{
base2 = boost::polymorphic_cast<Base2*>( base ); // crosscast
BOOST_TEST( base2 != 0 );
if( base2 != 0 )
{
BOOST_TEST_EQ( base2->kind2(), "Base2" );
}
}
catch( std::bad_cast const& )
{
BOOST_ERROR( "boost::polymorphic_cast<Base2*>( base ) threw std::bad_cast" );
}
delete base;
}
static void test_polymorphic_pointer_cast()
{
Base * base = new Derived;
Derived * derived;
try
{
derived = boost::polymorphic_pointer_cast<Derived>( base );
BOOST_TEST( derived != 0 );
if( derived != 0 )
{
BOOST_TEST_EQ( derived->kind(), "Derived" );
}
}
catch( std::bad_cast const& )
{
BOOST_ERROR( "boost::polymorphic_pointer_cast<Derived>( base ) threw std::bad_cast" );
}
Base2 * base2;
try
{
base2 = boost::polymorphic_pointer_cast<Base2>( base ); // crosscast
BOOST_TEST( base2 != 0 );
if( base2 != 0 )
{
BOOST_TEST_EQ( base2->kind2(), "Base2" );
}
}
catch( std::bad_cast const& )
{
BOOST_ERROR( "boost::polymorphic_pointer_cast<Base2>( base ) threw std::bad_cast" );
}
boost::shared_ptr<Base> sp_base( base );
boost::shared_ptr<Base2> sp_base2;
try
{
sp_base2 = boost::polymorphic_pointer_cast<Base2>( sp_base ); // crosscast
BOOST_TEST( sp_base2 != 0 );
if( sp_base2 != 0 )
{
BOOST_TEST_EQ( sp_base2->kind2(), "Base2" );
}
}
catch( std::bad_cast const& )
{
BOOST_ERROR( "boost::polymorphic_pointer_cast<Base2>( sp_base ) threw std::bad_cast" );
}
// we do not `delete base;` because sahred_ptr is holding base
}
static void test_polymorphic_downcast()
{
Base *base_pointer = new Derived;
// test raw pointer cast
Derived *derived_pointer = boost::polymorphic_downcast<Derived *>(base_pointer);
BOOST_TEST(derived_pointer != 0);
if (derived_pointer != 0)
{
BOOST_TEST_EQ(derived_pointer->kind(), "Derived");
}
// test reference cast
Derived& derived_ref = boost::polymorphic_downcast<Derived&>(*base_pointer);
BOOST_TEST_EQ(derived_ref.kind(), "Derived");
delete base_pointer;
}
static void test_polymorphic_pointer_downcast_builtin()
{
Base * base = new Derived;
Derived * derived = boost::polymorphic_pointer_downcast<Derived>( base );
BOOST_TEST( derived != 0 );
if( derived != 0 )
{
BOOST_TEST_EQ( derived->kind(), "Derived" );
}
// polymorphic_pointer_downcast can't do crosscasts
delete base;
}
static void test_polymorphic_pointer_downcast_boost_shared()
{
boost::shared_ptr<Base> base (new Derived);
boost::shared_ptr<Derived> derived = boost::polymorphic_pointer_downcast<Derived>( base );
BOOST_TEST( derived != 0 );
if( derived != 0 )
{
BOOST_TEST_EQ( derived->kind(), "Derived" );
}
}
static void test_polymorphic_pointer_downcast_intrusive()
{
boost::intrusive_ptr<Base> base (new Derived);
boost::intrusive_ptr<Derived> derived = boost::polymorphic_pointer_downcast<Derived>( base );
BOOST_TEST( derived != 0 );
if( derived != 0 )
{
BOOST_TEST_EQ( derived->kind(), "Derived" );
}
}
static void test_polymorphic_pointer_downcast_std_shared()
{
std::shared_ptr<Base> base (new Derived);
std::shared_ptr<Derived> derived = boost::polymorphic_pointer_downcast<Derived>( base );
BOOST_TEST( derived != 0 );
if( derived != 0 )
{
BOOST_TEST_EQ( derived->kind(), "Derived" );
}
}
static void test_polymorphic_cast_fail()
{
Base * base = new Base;
BOOST_TEST_THROWS( boost::polymorphic_cast<Derived*>( base ), std::bad_cast );
delete base;
}
static void test_polymorphic_pointer_cast_fail()
{
Base * base = new Base;
BOOST_TEST_THROWS( boost::polymorphic_pointer_cast<Derived>( base ), std::bad_cast );
delete base;
BOOST_TEST_THROWS( boost::polymorphic_pointer_cast<Derived>( boost::shared_ptr<Base>(new Base) ), std::bad_cast );
BOOST_TEST_THROWS( boost::polymorphic_pointer_cast<Derived>( std::shared_ptr<Base>(new Base) ), std::bad_cast );
BOOST_TEST_THROWS( boost::polymorphic_pointer_cast<Derived>( boost::intrusive_ptr<Base>(new Base) ), std::bad_cast );
}
static void test_polymorphic_downcast_fail()
{
Base * base_pointer = new Base;
{
// test raw pointer cast
int old_count = assertion_failed_count;
expect_assertion = true;
BOOST_TEST_THROWS(boost::polymorphic_downcast<Derived *>(base_pointer), expected_assertion); // should assert
BOOST_TEST_EQ(assertion_failed_count, old_count + 1);
expect_assertion = false;
}
{
// test reference cast
int old_count = assertion_failed_count;
expect_assertion = true;
BOOST_TEST_THROWS(boost::polymorphic_downcast<Derived &>(*base_pointer), expected_assertion); // should assert
BOOST_TEST_EQ(assertion_failed_count, old_count + 1);
expect_assertion = false;
}
delete base_pointer;
}
static void test_polymorphic_pointer_downcast_builtin_fail()
{
Base * base = new Base;
int old_count = assertion_failed_count;
expect_assertion = true;
BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast<Derived>( base ), expected_assertion ); // should assert
BOOST_TEST_EQ( assertion_failed_count, old_count + 1 );
expect_assertion = false;
delete base;
}
static void test_polymorphic_pointer_downcast_boost_shared_fail()
{
boost::shared_ptr<Base> base (new Base);
int old_count = assertion_failed_count;
expect_assertion = true;
BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast<Derived>( base ), expected_assertion ); // should assert
BOOST_TEST_EQ( assertion_failed_count, old_count + 1 );
expect_assertion = false;
}
static void test_polymorphic_pointer_downcast_std_shared_fail()
{
std::shared_ptr<Base> base (new Base);
int old_count = assertion_failed_count;
expect_assertion = true;
BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast<Derived>( base ), expected_assertion ); // should assert
BOOST_TEST_EQ( assertion_failed_count, old_count + 1 );
expect_assertion = false;
}
static void test_polymorphic_pointer_downcast_intrusive_fail()
{
boost::intrusive_ptr<Base> base (new Base);
int old_count = assertion_failed_count;
expect_assertion = true;
BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast<Derived>( base ), expected_assertion); // should assert
BOOST_TEST_EQ( assertion_failed_count, old_count + 1 );
expect_assertion = false;
}
int main()
{
test_polymorphic_cast();
test_polymorphic_pointer_cast();
test_polymorphic_downcast();
test_polymorphic_pointer_downcast_builtin();
test_polymorphic_pointer_downcast_boost_shared();
test_polymorphic_pointer_downcast_intrusive();
test_polymorphic_cast_fail();
test_polymorphic_pointer_cast_fail();
test_polymorphic_downcast_fail();
test_polymorphic_pointer_downcast_builtin_fail();
test_polymorphic_pointer_downcast_boost_shared_fail();
test_polymorphic_pointer_downcast_intrusive_fail();
test_polymorphic_pointer_downcast_std_shared();
test_polymorphic_pointer_downcast_std_shared_fail();
return boost::report_errors();
}