Compare commits

...

99 Commits

Author SHA1 Message Date
Peter Dimov 50a1eae942 Change mpl::integral_c to boost::integral_constant to avoid Clang 16 errors when constructing out of range enums (refs #24, https://github.com/boostorg/mpl/issues/69) 2022-11-16 10:43:31 +02:00
Peter Dimov 7c846ddf63 Add missing include 2022-11-16 02:55:31 +02:00
Peter Dimov 902588b6bd Hardcode LIBRARY in ci.yml 2022-11-16 02:44:49 +02:00
Peter Dimov 95c9f7f918 Add .github/workflows/ci.yml 2022-11-16 02:30:35 +02:00
Glen Fernandes db44689f4f Switch from deprecated test to Lightweight Test 2021-06-09 17:48:22 -04:00
Peter Dimov 1bc71b7971 Add CMakeLists.txt 2021-03-18 17:39:55 +02:00
Brandon Kohn f9397e9cba Merge pull request #23 from eldiener/develop
[skip ci] Add "cxxstd" json field
2021-02-17 09:04:32 -05:00
Edward Diener ccb153a506 [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-20 23:00:18 -05:00
Peter Dimov 07d5e56494 Merge branch 'master' into develop 2020-11-03 00:50:13 +02:00
Brandon Kohn 8c30716176 Merge pull request #21 from EugeneZelenko/use-boost-override
Use BOOST_OVERRIDE
2020-06-15 13:53:48 -04:00
Eugene Zelenko 6c83ad8c57 Use BOOST_OVERRIDE to fix GCC -Wsuggest-override and Clang-tidy modernize-use-override warnings.
Alphabetical order of STL headers.
2020-05-24 16:10:39 -07:00
Brandon Kohn aab2ea1fed Merge pull request #19 from eldiener/develop
Changes for Embarcadero C++ clang-based compilers, targeting Boost 1.74. Change __BORLANDC__ to BOOST_BORLANDC, which is defined in Boost conf…
2020-04-22 11:12:58 -04:00
Edward Diener 1d856f673f Change __BORLANDC__ to BOOST_BORLANDC, which is defined in Boost config for the Embarcadero non-clang-based compilers. 2020-03-31 11:58:06 -04:00
Nikita Kniazev de92292140 Tests: Fix C1128 error on msvc-14.1+
traits_test fails on msvc-14.1+ in 64bit debug mode with C1128 error

Fixes #15
2019-04-18 12:43:43 -04:00
Romain Geissler 53de752e1f Use BOOST_NOEXCEPT_OR_NOTHROW in public headers to prepare for C++20 2019-04-18 12:43:28 -04:00
Brandon Kohn a83247065b Merge pull request #16 from Kojoley/patch-1
Tests: Fix C1128 error on msvc-14.1+
2019-04-18 11:52:42 -04:00
Nikita Kniazev a4d54f8f89 Tests: Fix C1128 error on msvc-14.1+
traits_test fails on msvc-14.1+ in 64bit debug mode with C1128 error

Fixes #15
2019-03-31 20:12:53 +03:00
Brandon Kohn a8467a8723 Merge pull request #14 from Romain-Geissler-1A/noexcept
Use BOOST_NOEXCEPT_OR_NOTHROW in public headers to prepare for C++20
2018-11-19 09:16:26 -05:00
Romain Geissler 721dc89e7f Use BOOST_NOEXCEPT_OR_NOTHROW in public headers to prepare for C++20 2018-11-13 23:39:51 +00:00
Fernando Cacciola 36f969a4c5 Merge pull request #12 from boostorg/develop
Merged latest fixes
2018-03-07 16:59:38 -03:00
Fernando Cacciola b900379a74 Merge pull request #11 from boostorg/revert-7-fix-compiling
Revert "Fix compilation on lastest MSVC"
2018-03-06 15:35:32 -03:00
Fernando Cacciola 8ad516370a Revert "Fix compilation on lastest MSVC" 2018-03-06 15:34:11 -03:00
Fernando Cacciola c993894676 Merge pull request #10 from boostorg/danieljames-patch-1
Link to latest version of documentation
2018-03-05 15:27:04 -03:00
Daniel James 1da5d0d8fe Link to latest version of documentation
Putting 'release' instead of the version number will redirect to the latest documentation.
2018-03-05 18:23:34 +00:00
Fernando Cacciola 5a45a8d824 Merge pull request #9 from lakshayg/readme
add a short description and link to official docs
2018-02-27 18:14:45 -03:00
Lakshay Garg 3ae7d59e7a add a short description and link to official docs 2017-10-30 02:40:01 +05:30
Fernando Cacciola 54d571dde2 Merge pull request #7 from BlowaXD/fix-compiling
Fix compilation on lastest MSVC
2017-10-25 20:53:44 +02:00
Unknown 4505bc3808 Fix compilation on lastest MSVC
std::unary_function has been removed from C++ 17 standard so it does not compile anymore on MSVC
2017-09-27 12:39:34 +02:00
Brandon Kohn 7f3a74cb74 Merge pull request #6 from eldiener/develop
Removed executable attribute from file.
2017-09-23 18:42:25 -04:00
Edward Diener 278025d9c6 Removed executable attribute from file. 2017-09-17 10:46:51 -04:00
Brandon Kohn 7436ca7113 Merge-commit for hotfix/remove_std_unary_function. 2017-08-22 14:00:49 -04:00
Brandon Kohn ebfded1d7d Remove the deprecated uses of std::unary_function (again). 2017-08-22 13:39:34 -04:00
Brandon Kohn c9d7a49b4a Removed redundant typedefs for argument_type and result_type 2016-07-06 07:10:36 -04:00
Brandon Kohn 2009f0d4fc Revert "removed deprecated std::unary_function from various conversion functors"
This reverts commit 593aafab5a.
2016-07-06 06:58:20 -04:00
Brandon Kohn 736745061d Merge branch 'hotfix/remove_std_unary_function' into develop 2016-07-05 21:40:31 -04:00
Brandon Kohn 593aafab5a removed deprecated std::unary_function from various conversion functors 2016-07-05 21:39:44 -04:00
Brandon Kohn a6681748be Merged Jamfile.v2 test changes to conform to requirements. 2016-06-17 14:30:58 -04:00
Brandon Kohn d6ec138927 Changed test Jamfile.v2 to conform to requirements. 2016-06-17 14:22:19 -04:00
Brandon Kohn 30d2e6d9f6 Revert "Modified Jamfile.v2 to conform to boost test requirements."
This reverts commit d76eb6fa72.
2016-06-17 14:20:27 -04:00
Brandon Kohn d76eb6fa72 Modified Jamfile.v2 to conform to boost test requirements. 2016-06-17 14:04:13 -04:00
brandon-kohn c90517da96 Merge pull request #3 from danieljames/metadata
Create metadata file.
2014-08-18 11:52:55 -04:00
Daniel James 907ae79790 Add metadata file. 2014-08-18 15:08:01 +01:00
Antony Polukhin f4c6bd9711 Moved cast.hpp file from Conversion library. It was decided that this file must be in NumericCast library to reduce dependencies 2014-06-10 21:58:06 +03:00
Peter Dimov 86f8af551c Merge pull request #2 from apolukhin/develop
Moved cast.hpp file from Conversion library. It was decided that this fi...
2014-06-10 21:52:01 +03:00
Antony Polukhin cda4506afe Moved cast.hpp file from Conversion library. It was decided that this file must be in NumericCast library to reduce dependencies 2014-06-09 13:27:11 +04:00
brandon-kohn 718767f1e6 Merge pull request #1 from danieljames/develop
Remove old Visual C++ 6 workaround
2014-06-05 06:23:46 -04:00
Daniel James 26218a6e86 Rebuild documentation.
Rebuilding documentation on develop and master to avoid unnecessary
differences.
2014-06-02 10:13:11 +01:00
Daniel James 69a46fea8a Remove old Visual C++ 6 workaround
From 41473987e5 - it was never released,
and Visual C++6 isn't supported anymore.
2014-06-02 10:11:42 +01:00
Daniel James 056045e503 Rebuild documentation.
Rebuilding documentation on develop and master to avoid unnecessary
differences.
2014-06-02 10:05:00 +01:00
Stephen Kelly d4a8c7049a Numeric: Remove obsolete MSVC version checks.
[SVN r86053]
2013-09-30 11:23:20 +00:00
Antony Polukhin e6fa2c4b6d Merge from trunk
* Much more tests
* Now numeric_cast (and lexical_cast) can be compiled with disabled exceptions
* Supress warning described in #6645 (implicit conversion shortens 64-bit value into a 32-bit value)
* Fixed compilation of lexical_cast with BOOST_NO_STD_LOCALE defined
* Documentation updates
* Case insensitive "NaN" and "Inf" parsing 
* Performance tests commit

[SVN r77288]
2012-03-10 07:31:36 +00:00
Antony Polukhin 0fc4c240b9 Fixes #5731, fixes #5076, fixes #5393, fixes #5800
Now numeric_cast (and lexical_cast) can be compiled with disabled exceptions

[SVN r77234]
2012-03-05 17:11:20 +00:00
Brandon Kohn de94a311a3 Merged numeric cast trait fixes for fundamental type specializations.
[SVN r76836]
2012-02-02 01:42:52 +00:00
Brandon Kohn c9e3ffd511 Changed long long and unsigned long long to use the boost::(u)long_long_type typedefs in the numeric_cast_traits base specializations.
[SVN r76808]
2012-01-31 14:27:10 +00:00
Brandon Kohn e7b5847b5a Fixes for https://svn.boost.org/trac/boost/ticket/6158 numeric_cast_traits.
[SVN r76765]
2012-01-28 19:59:35 +00:00
Brandon Kohn fcb73eb616 Missed imports to numeric_cast_traits docs.
[SVN r75596]
2011-11-21 16:46:56 +00:00
Brandon Kohn 238b6ab769 Merge of numeric_cast_traits in numeric conversion library.
[SVN r74762]
2011-10-06 17:27:17 +00:00
Brandon Kohn 0ab23addef Replaced special copyright character with (c) in numeric cast traits files.
[SVN r74356]
2011-09-12 14:35:29 +00:00
Brandon Kohn 5d344f7463 Simplified custom numeric type in numeric_cast_traits_test.cpp to reduce template depth.
[SVN r73701]
2011-08-12 13:09:15 +00:00
Brandon Kohn 6bd888475f Changed numeric_cast_traits_test.cpp to explicitly use the boost namespace.
[SVN r73700]
2011-08-12 12:46:00 +00:00
Daniel James 4c8e454bbb Conversion: Fix preprocessor iteration.
Some preprocessors process all the 'elif' clauses even if it's known
that they're not going to be used which was resulting in errors.

[SVN r73691]
2011-08-12 06:55:07 +00:00
Brandon Kohn 507d157d10 Added numeric_cast_traits to the numeric conversion library. Tested on msvc-10.0 and gcc-4.3.4/cygwin.
[SVN r73675]
2011-08-11 19:08:08 +00:00
Antony Polukhin 41473987e5 Fixes #5707. Fixes some trivial bugs for VC++6
[SVN r73201]
2011-07-17 19:36:06 +00:00
Steven Watanabe 8312050b36 Revert [67111] (addition of boost/detail/iomanip.hpp) and all the commits that depend on it. ([68137], [68140], [68141], [68154], and [68165]).
[SVN r68168]
2011-01-15 08:11:51 +00:00
Bryce Adelstein-Lelbach 3526c08afc Replacing the use of <iomanip> with <boost/detail/iomanip.hpp> across Boost.
On Linux, GNU's libstdc++, which is the default stdlib for icc and clang,
cannot parse the <iomanip> header in version 4.5+ (which thankfully neither
compiler advises the use of yet), as it's original C++98-friendly
implementation has been replaced with a gnu++0x implementation.
<boost/detail/iomanip.hpp> is a portable implementation of <iomanip>, providing
boost::detail::setfill, boost::detail::setbase, boost::detail::setw,
boost::detail::setprecision, boost::detail::setiosflags and
boost::detail::resetiosflags. 



[SVN r68140]
2011-01-14 02:35:58 +00:00
Daniel James 7e74dc080e Merge documentation changes.
[SVN r64186]
2010-07-19 23:29:09 +00:00
Daniel James ca4de5c31d Fix doc build for 2 libraries which use own css.
I changed the default to use doc/src/boostbook.css. So add an explicit
location to libraries which use their own stylesheet.

[SVN r64170]
2010-07-19 20:17:58 +00:00
Daniel James 3d44e92088 Merge documentation fixes.
* Use `doc/src/*.css` instead of `doc/html/*.css`.
* Remove wiki and people directories.
* Some documentation fixes.
* Left out `minimal.css` changes and boostbook changes because of clashes.


[SVN r63347]
2010-06-26 12:30:09 +00:00
Daniel James fe862ee762 Update various libraries' documentation build.
Mostly to use the images and css files under doc/src instead of
doc/html, usually be deleting the settings in order to use the defaults.
Also add 'boost.root' to some builds in order to fix links which rely on
it.

[SVN r63146]
2010-06-20 18:00:48 +00:00
Daniel James 947af90dbf Merge [57807]: rebuild numeric/conversion documentation.
[SVN r57809]
2009-11-20 10:05:09 +00:00
Daniel James d434655b08 Rebuild numeric/conversion documentation.
[SVN r57807]
2009-11-20 10:02:01 +00:00
Troy D. Straszheim 5a345e2993 rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
Troy D. Straszheim 0047a2d734 rm cmake from the release branch before it goes out broken. Policy dictates that you never commit to release, you commit to trunk and merge to release.
[SVN r56941]
2009-10-17 01:10:45 +00:00
Troy D. Straszheim 00311d7276 Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
Troy D. Straszheim 8a0a8727b9 Add basic copyright/license to keep cmake out of the inspection report
[SVN r55095]
2009-07-22 21:51:01 +00:00
John Maddock a05ae1dc97 Merge PDF build changes from Trunk.
[SVN r51417]
2009-02-23 18:39:32 +00:00
John Maddock dce3963075 Add PDF generation options to fix external links to point to the web site.
Added a few more Boostbook based libs that were missed first time around.
Fixed PDF naming issues.

[SVN r51284]
2009-02-17 10:05:58 +00:00
John Maddock 20de9917e6 Fix the optional and numeric/conversion docs so they generate valid Docbook XML that can be transformed into PDF's.
Regenerated HTML versions of the docs.

[SVN r51218]
2009-02-12 14:01:48 +00:00
Troy D. Straszheim e0eee93fa5 merge of cmake build files from trunk per beman
[SVN r50756]
2009-01-24 18:57:20 +00:00
Michael A. Jackson 3c72670b7f Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
Michael A. Jackson d6e932c038 Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
John Maddock 5963a9cb67 Merge fixes from Trunk.
Fixes #2392.

Change includes of <cmath> to <boost/config/no_tr1/config.hpp>.

Previously if Boost.TR1 was in the include path then including <cmath> pulls in all the new TR1 math functions, which in turn also requires linking to an external library. With auto-linking support this requires that library to have been built and be present in the library search path, even if the actual library under use is header only. 

[SVN r49314]
2008-10-13 09:00:03 +00:00
Daniel James 79760962d1 Rebuild the numeric/conversion and optional documentation. Which should fix a few links.
[SVN r49259]
2008-10-10 21:35:16 +00:00
John Maddock 67e2ca29bc Change includes of <cmath> to <boost/config/no_tr1/config.hpp>.
Previously if Boost.TR1 was in the include path then including <cmath> pulls in all the new TR1 math functions, which in turn also requires linking to an external library.  With auto-linking support this requires that library to have been built and be present in the library search path, even if the actual library under use is header only.

Fixes #2392.


[SVN r49254]
2008-10-10 16:10:00 +00:00
Beman Dawes 225b672e44 Merge trunk
[SVN r47717]
2008-07-23 15:15:27 +00:00
Daniel James abb1d17829 Add minor documentation fixes to the release branch.
(I left out the changes to the hash library).

Merged via svnmerge from 
https://svn.boost.org/svn/boost/trunk

................
  r44807 | danieljames | 2008-04-27 08:39:49 +0100 (Sun, 27 Apr 2008) | 78 lines
  
  Merge in documentation fixes.  Apart from the change to optional's documenation
  Jamfile, which I included by mistake.
  
  I wrote about this at:
  
  http://lists.boost.org/Archives/boost/2008/04/136405.php
  
  Merged revisions 44585-44806 via svnmerge from 
  https://svn.boost.org/svn/boost/branches/doc
  
  ........
    r44585 | danieljames | 2008-04-19 16:25:27 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix broken link to vacpp in bjam docs.
  ........
    r44586 | danieljames | 2008-04-19 16:27:36 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix broken link to bcpp in bjam docs.
  ........
    r44587 | danieljames | 2008-04-19 16:33:58 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    DateTime documentation - Fix a link to the serialization library.
  ........
    r44588 | danieljames | 2008-04-19 16:35:36 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix some links in interprocess & intrusive.
  ........
    r44589 | danieljames | 2008-04-19 16:37:39 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix some links in the python docs.
  ........
    r44590 | danieljames | 2008-04-19 16:38:29 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Work around a quickbook bug which is affecting the python docs.
  ........
    r44591 | danieljames | 2008-04-19 16:39:34 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix a broken link in the numeric conversion docs.
  ........
    r44592 | danieljames | 2008-04-19 16:40:45 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix some links in the optional docs.
  ........
    r44593 | danieljames | 2008-04-19 16:42:09 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix link to the hash documentation from bimap.
  ........
    r44599 | danieljames | 2008-04-19 18:07:33 +0100 (Sat, 19 Apr 2008) | 2 lines
    
    Fix a typo in the format library.
  ........
    r44600 | danieljames | 2008-04-19 19:20:59 +0100 (Sat, 19 Apr 2008) | 1 line
    
    Initialise svnmerge.
  ........
    r44641 | danieljames | 2008-04-20 18:59:47 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Fix the lincense url in shared container iterator documentation.
  ........
    r44642 | danieljames | 2008-04-20 19:00:00 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Fix image link in the mpi documentation.
  ........
    r44643 | danieljames | 2008-04-20 19:00:11 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Fix a typo in the spirit docs.
  ........
    r44644 | danieljames | 2008-04-20 19:00:23 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Escape the slash so that quickbook doesn't think it the start of an italic section, and mess up the link. Refs #1844
  ........
    r44647 | danieljames | 2008-04-20 19:39:47 +0100 (Sun, 20 Apr 2008) | 2 lines
    
    Fix another typo in spirit docs.
  ........
................
  r45232 | danieljames | 2008-05-08 22:50:19 +0100 (Thu, 08 May 2008) | 1 line
  
  Fix some invalid xml by replacing ampersands with character entities.
................
  r45576 | danieljames | 2008-05-20 16:39:25 +0100 (Tue, 20 May 2008) | 20 lines
  
  Merge some small documentation fixes from the doc branch, and mark some
  previously merged changes as merged.
  
  Merged revisions 44811,45129,45142,45154,45281-45282,45365 via svnmerge from 
  https://svn.boost.org/svn/boost/branches/doc
  
  ........
    r45129 | danieljames | 2008-05-05 12:36:50 +0100 (Mon, 05 May 2008) | 2 lines
    
    Update navbar links in boostbook.
  ........
    r45282 | danieljames | 2008-05-11 14:15:31 +0100 (Sun, 11 May 2008) | 2 lines
    
    Group functions in the hash header - requires Frank's free-function-group fix.
    (not included in release branch).
  ........
    r45365 | danieljames | 2008-05-14 21:39:00 +0100 (Wed, 14 May 2008) | 2 lines
    
    Add boost.root to standalone hash documentation.
    (not included in release branch).
  ........
................


[SVN r45622]
2008-05-21 20:57:05 +00:00
Daniel James daadef8d1a Rebuild a lot of documentation.
[SVN r43650]
2008-03-16 11:38:32 +00:00
John Maddock ccffeecc40 Merged fixes for inspection report failures from the main Trunk.
[SVN r43616]
2008-03-15 09:36:05 +00:00
Matias Capeletto 7435918580 numeric/conversion docs new version
[SVN r43258]
2008-02-14 19:38:40 +00:00
Beman Dawes 1ed1b2090e Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
2007-11-25 18:38:02 +00:00
Beman Dawes 5fb09c0c83 Starting point for releases
[SVN r39706]
2007-10-05 14:25:06 +00:00
nobody 0f0a2cecd4 This commit was manufactured by cvs2svn to create tag
'Version_1_34_1'.

[SVN r38286]
2007-07-24 19:28:14 +00:00
Fernando Cacciola b4dff23f4a none_t/none reimplemented to avoid precompiled header issues (thanks to Joe Gottam)
optional<T> now has direct relational operator
optional<T>::operator-> fixed for reference types


[SVN r37126]
2007-03-01 23:08:33 +00:00
Daniel James 8d28027378 Fix a broken link.
[SVN r36655]
2007-01-07 22:55:23 +00:00
Beman Dawes 864ea51c46 Merged copyright and license addition
[SVN r35907]
2006-11-07 19:27:00 +00:00
Rene Rivera f14990c43c Remove obsolete Boost.Build v1 files.
[SVN r35880]
2006-11-06 17:10:46 +00:00
Gennaro Prota a647a48fe5 fixed line-endings (Inspect tool)
[SVN r34781]
2006-07-29 20:42:19 +00:00
Nicola Musatti 4755739313 Updated Borland workaround
[SVN r33857]
2006-04-29 06:44:35 +00:00
nobody dd8e44c999 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r33417]
2006-03-21 02:26:31 +00:00
49 changed files with 5127 additions and 1621 deletions
+235
View File
@@ -0,0 +1,235 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- feature/**
env:
UBSAN_OPTIONS: print_stacktrace=1
LIBRARY: numeric/conversion
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-latest
container: ubuntu:18.04
install: g++-4.8-multilib
address-model: 32,64
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-latest
container: ubuntu:18.04
install: g++-5-multilib
address-model: 32,64
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-latest
container: ubuntu:18.04
install: g++-6-multilib
address-model: 32,64
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-latest
container: ubuntu:18.04
install: g++-7-multilib
address-model: 32,64
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-8-multilib
address-model: 32,64
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-9-multilib
address-model: 32,64
- toolset: gcc-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-10-multilib
address-model: 32,64
- toolset: gcc-11
cxxstd: "03,11,14,17,20"
os: ubuntu-20.04
install: g++-11-multilib
address-model: 32,64
- toolset: gcc-12
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: g++-12-multilib
address-model: 32,64
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-latest
container: ubuntu:18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-latest
container: ubuntu:18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-latest
container: ubuntu:18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-7
- toolset: clang
compiler: clang++-8
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-8
- toolset: clang
compiler: clang++-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-9
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,20"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-14
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-11
runs-on: ${{matrix.os}}
container: ${{matrix.container}}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python git g++
- name: Install packages
if: matrix.install
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
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 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
- name: Create user-config.jam
if: matrix.compiler
run: |
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
- name: Run tests
run: |
cd ../boost-root
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} ${ADDRMD:+address-model=$ADDRMD} variant=debug,release
windows:
strategy:
fail-fast: false
matrix:
include:
- toolset: msvc-14.0
cxxstd: 14,latest
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.2
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.3
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2022
- toolset: clang-win
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2022
- toolset: gcc
cxxstd: "03,11,14,17,2a"
addrmd: 64
os: windows-2019
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
run: |
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 1 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 --git_args "--jobs 3" %LIBRARY%
cmd /c bootstrap
b2 -d0 headers
- 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 embed-manifest-via=linker
+31
View File
@@ -0,0 +1,31 @@
# Generated by `boostdep --cmake numeric~conversion`
# Copyright 2020 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
project(boost_numeric_conversion VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
add_library(boost_numeric_conversion INTERFACE)
add_library(Boost::numeric_conversion ALIAS boost_numeric_conversion)
target_include_directories(boost_numeric_conversion INTERFACE include)
target_link_libraries(boost_numeric_conversion
INTERFACE
Boost::config
Boost::conversion
Boost::core
Boost::mpl
Boost::preprocessor
Boost::throw_exception
Boost::type_traits
)
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()
+8
View File
@@ -0,0 +1,8 @@
# Boost.NumericConversion
The Boost Numeric Conversion library is a collection of tools to describe and perform conversions between values of different [numeric types][1].
The documentation for the library can be found [here][2]
[1]: http://www.boost.org/doc/libs/release/libs/numeric/conversion/doc/html/boost_numericconversion/definitions.html#boost_numericconversion.definitions.numeric_types
[2]: http://www.boost.org/doc/libs/release/libs/numeric/conversion/doc/html/index.html#numeric_conversion.overview
+7 -1
View File
@@ -12,6 +12,9 @@
import quickbook ;
path-constant images : html ;
xml conversion
:
conversion.qbk
@@ -22,9 +25,12 @@ boostbook standalone
conversion
:
<xsl:param>boost.root=../../../../..
<xsl:param>boost.libraries=../../../../libraries.htm
<xsl:param>html.stylesheet=boostbook.css
<xsl:param>toc.max.depth=2
<xsl:param>toc.section.depth=2
<xsl:param>chunk.section.depth=1
<format>pdf:<xsl:param>img.src.path=$(images)/
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/numeric/conversion/doc/html
;
-2
View File
@@ -8,8 +8,6 @@
http://www.boost.org/LICENSE_1_0.txt)
]
[#numeric_conversion_bounds]
[section bounds<> traits class]
[section Introduction]
+12 -12
View File
@@ -46,32 +46,32 @@ Distributed under the Boost Software License, Version 1.0.
The Boost Numeric Conversion library is a collection of tools to describe and
perform conversions between values of different
[link numeric_conversion_definitions_numeric_types numeric types].
[link boost_numericconversion.definitions.numeric_types numeric types].
The library includes a special alternative for a subset of `std::numeric_limits<>`,
the [link numeric_conversion_bounds bounds<>] traits class, which provides
a consistent way to obtain the [link numeric_conversion_definitions_range boundary]
values for the [link numeric_conversion_definitions_range range] of a numeric type.
the [link boost_numericconversion.bounds___traits_class bounds<>] traits class, which provides
a consistent way to obtain the [link boost_numericconversion.definitions.range_and_precision boundary]
values for the [link boost_numericconversion.definitions.range_and_precision range] of a numeric type.
It also includes a set of [link numeric_conversion_traits trait classes]
It also includes a set of [link boost_numericconversion.conversion_traits___traits_class trait classes]
which describes the compile-time
properties of a conversion from a source to a target numeric type.
Both [link numeric_conversion_cpp_arithmetic_types arithmetic] and
[link numeric_conversion_definitions_numeric_types user-defined numeric types] can be used.
Both [link boost_numericconversion.definitions.c___arithmetic_types arithmetic] and
[link boost_numericconversion.definitions.numeric_types user-defined numeric types] can be used.
A policy-based [link numeric_conversion_converter converter] object which
A policy-based [link boost_numericconversion.converter___function_object converter] object which
uses `conversion_traits` to select
an optimized implementation is supplied. Such implementation uses an optimal
range checking code suitable for the source/target combination.
* The converter's out-of-range behavior can be customized via an
[link numeric_conversion_policy_overflow_handler OverflowHandler] policy.
[link boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler OverflowHandler] policy.
* For floating-point to integral conversions, the rounding mode can be selected via the
[link numeric_conversion_policy_float_to_int_rounder Float2IntRounder] policy.
[link boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder Float2IntRounder] policy.
* A custom low-level conversion routine (for UDTs for instance) can be passed via a
[link numeric_conversion_policy_raw_converter RawConverter] policy.
[link boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter RawConverter] policy.
* The optimized automatic range-checking logic can be overridden via a
[link numeric_conversion_policy_user_range_checker UserRangeChecker] policy.
[link boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker UserRangeChecker] policy.
[endsect]
+11 -27
View File
@@ -8,14 +8,10 @@
http://www.boost.org/LICENSE_1_0.txt)
]
[#numeric_conversion_traits]
[section conversion_traits<> traits class]
[section Types]
[#numeric_conversion_traits_int_float_mixture_enum]
[section enumeration int_float_mixture_enum]
namespace boost { namespace numeric {
@@ -32,8 +28,6 @@
[endsect]
[#numeric_conversion_traits_sign_mixture_enum]
[section enumeration sign_mixture_enum]
namespace boost { namespace numeric {
@@ -50,8 +44,6 @@
[endsect]
[#numeric_conversion_traits_udt_builtin_mixture_enum]
[section enumeration udt_builtin_mixture_enum]
namespace boost { namespace numeric {
@@ -68,8 +60,6 @@
[endsect]
[#numeric_conversion_traits_class_int_float_mixture]
[section template class int_float_mixture<>]
namespace boost { namespace numeric {
@@ -83,12 +73,10 @@ Classifying `S` and `T` as either integral or float, this __MPL_INTEGRAL_CONSTAN
indicates the combination of these attributes.
Its `::value` is of enumeration type
[link numeric_conversion_traits_int_float_mixture_enum `boost::numeric::int_float_mixture_enum`]
[link boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum `boost::numeric::int_float_mixture_enum`]
[endsect]
[#numeric_conversion_traits_class_sign_mixture]
[section template class sign_mixture<>]
namespace boost { namespace numeric {
@@ -102,12 +90,10 @@ Classifying `S` and `T` as either signed or unsigned, this __MPL_INTEGRAL_CONSTA
indicates the combination of these attributes.
Its `::value` is of enumeration type
[link numeric_conversion_traits_sign_mixture_enum `boost::numeric::sign_mixture_enum`]
[link boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum `boost::numeric::sign_mixture_enum`]
[endsect]
[#numeric_conversion_traits_class_udt_builtin_mixture]
[section template class udt_builtin_mixture<>]
namespace boost { namespace numeric {
@@ -121,12 +107,10 @@ Classifying `S` and `T` as either user-defined or builtin, this __MPL_INTEGRAL_C
indicates the combination of these attributes.
Its `::value` is of enumeration type
[link numeric_conversion_traits_udt_builtin_mixture_enum `boost::numeric::udt_builtin_mixture_enum`]
[link boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum `boost::numeric::udt_builtin_mixture_enum`]
[endsect]
[#numeric_conversion_traits_is_subranged]
[section template class is_subranged<>]
namespace boost { namespace numeric {
@@ -176,7 +160,7 @@ source values are representable as Target type.
This traits class indicates some properties of a ['numeric conversion] direction:
from a source type `S` to a target type `T`. It does not indicate the properties
of a ['specific] conversion, but of the conversion direction. See
[link numeric_conversion_definitions_subranged Definitions] for details.
[link boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype Definitions] for details.
The traits class provides the following __MPL_INTEGRAL_CONSTANT__\s of enumeration
type. They express the combination of certain attributes of the Source and
@@ -186,26 +170,26 @@ Target types (thus they are call mixture):
[[ ][ ]]
[[[*int_float_mixture ]][
Same as given by the traits class
[link numeric_conversion_traits_class_int_float_mixture int_float_mixture]
[link boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__ int_float_mixture]
]]
[[[*sign_mixture ]][
Same as given by the traits class
[link numeric_conversion_traits_class_sign_mixture sign_mixture]
[link boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__ sign_mixture]
]]
[[[*udt_builtin_mixture ]]
[Same as given by the traits class
[link numeric_conversion_traits_class_udt_builtin_mixture udt_builtin_mixture]
[link boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__ udt_builtin_mixture]
]]
]
The traits class provides the following __MPL_INTEGRAL_CONSTANT__\s of boolean type
which indicates indirectly the relation between the Source and Target ranges
(see [link numeric_conversion_definitions_range Definitions] for details).
(see [link boost_numericconversion.definitions.range_and_precision Definitions] for details).
[table
[[ ][ ]]
[[subranged ][
Same as given by [link numeric_conversion_traits_is_subranged is_subranged]
Same as given by [link boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__ is_subranged]
]]
[[trivial][
Indicates if both Source and Target, [_without cv-qualifications], are the same type.
@@ -230,7 +214,7 @@ The template parameter `S` without cv-qualifications
This type is either source_type or `source_type const&`.
It represents the optimal argument type for the
[link numeric_conversion_converter converter] member functions.
[link boost_numericconversion.converter___function_object converter] member functions.
If S is a built-in type, this is `source_type`, otherwise, this is `source_type const&`.
]]
@@ -238,7 +222,7 @@ If S is a built-in type, this is `source_type`, otherwise, this is `source_type
This type is either target_type or target_type const&
It represents the return type of the
[link numeric_conversion_converter converter] member functions.
[link boost_numericconversion.converter___function_object converter] member functions.
If `T==S`, it is `target_type const&`, otherwise, it is `target_type`.
]]
+12 -16
View File
@@ -8,8 +8,6 @@
http://www.boost.org/LICENSE_1_0.txt)
]
[#numeric_conversion_converter]
[section converter<> function object]
[section Synopsis]
@@ -52,7 +50,7 @@
`boost::numeric::converter<>` is a __SGI_UNARY_FUNCTION__ encapsulating
the code to perform a numeric conversion with the direction and
properties specified by the Traits template parameter. It can optionally
take some [link numeric_coversion_converter_policies policies] which can be used to customize its behavior. The
take some [link boost_numericconversion.numeric_converter_policy_classes policies] which can be used to customize its behavior. The
`Traits` parameter is not a policy but the parameter that defines
the conversion.
@@ -63,16 +61,16 @@ the conversion.
[table
[[ ][ ]]
[[`T`][
The [link numeric_conversion_definitions_numeric_types Numeric Type]
The [link boost_numericconversion.definitions.numeric_types Numeric Type]
which is the ['Target] of the conversion.
]]
[[`S`][
The [link numeric_conversion_definitions_numeric_types Numeric Type]
The [link boost_numericconversion.definitions.numeric_types Numeric Type]
which is the ['Source] of the conversion.
]]
[[`Traits`][
This must be a conversion traits class with the interface of
[link numeric_conversion_traits `boost::numeric::conversion_traits`]
[link boost_numericconversion.conversion_traits___traits_class `boost::numeric::conversion_traits`]
]]
[[`OverflowHandler`][
[*Stateless Policy] called to administrate the result of the range checking.
@@ -143,19 +141,19 @@ represented by the target type without overflow.
It does not determine if the conversion is ['exact]; that is, it does not detect
['inexact] conversions, only ['out-of-range] conversions (see the
[link numeric_conversion_definitions_roundoff Definitions] for further details).
[link boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations Definitions] for further details).
The return value is of enum type
[link numeric_conversion_converter_policies_range_check_result `boost::numeric::range_check_result`]
[link boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result `boost::numeric::range_check_result`]
The actual code for the range checking logic is optimized for the combined
properties of the source and target types. For example, a non-subranged
conversion (i.e: `int`->`float`), requires no range checking, so `out_of_range()`
returns `cInRange` directly. See the following
[link numeric_conversion_converter_range_checking_logic table] for more details.
[link boost_numericconversion.converter___function_object.range_checking_logic table] for more details.
If the user supplied a
[link numeric_conversion_policy_user_range_checker UserRangeChecker] policy,
[link boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker UserRangeChecker] policy,
is this policy which implements this function, so the implementation is user
defined, although it is expected to perform the same conceptual check and
return the appropriate result.
@@ -167,14 +165,14 @@ __SPACE__
This [link numeric_conversion_converter_internal internal] static member function
calls out_of_range(s), and passes the
result to the [link numeric_conversion_policy_overflow_handler OverflowHandler]
result to the [link boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler OverflowHandler]
policy class.
For those Target/Source combinations which don't require range checking, this
is an empty inline function.
If the user supplied a
[link numeric_conversion_policy_user_range_checker UserRangeChecker] policy,
[link boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker UserRangeChecker] policy,
is this policy which implements this function, so the implementation is user
defined, although it is expected to perform the same action as the default.
In particular, it is expected to pass the result of the check to the overflow handler.
@@ -187,7 +185,7 @@ This [link numeric_conversion_converter_internal internal] static member functio
performs the actual conversion.
This function is externally supplied by the
[link numeric_conversion_policy_raw_converter RawConverter] policy class.
[link boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter RawConverter] policy class.
__SPACE__
@@ -199,7 +197,7 @@ which is [_only used] for
type]] according to some rounding direction.
This function is externally supplied by the
[link numeric_conversion_policy_float_to_int_rounder Float2IntRounder] policy class
[link boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder Float2IntRounder] policy class
which encapsulates the specific rounding mode.
__SPACE__
@@ -214,8 +212,6 @@ them infernally, but they can be called separately for specific needs.
[endsect]
[#numeric_conversion_converter_range_checking_logic]
[section Range Checking Logic]
The following table summarizes the internal range checking logic performed for
+1 -13
View File
@@ -8,13 +8,9 @@
http://www.boost.org/LICENSE_1_0.txt)
]
[#numeric_coversion_converter_policies]
[section Numeric Converter Policy Classes]
[#numeric_conversion_converter_policies_range_check_result]
[section enum range_check_result]
namespace boost { namespace numeric {
@@ -32,8 +28,6 @@ Defines the values returned by `boost::numeric::converter<>::out_of_range()`
[endsect]
[#numeric_conversion_policy_overflow_handler]
[section Policy OverflowHandler]
This ['stateless] non-template policy class must be a ['function object] and is
@@ -128,8 +122,6 @@ the old code is wider than for the new code).
[endsect]
[#numeric_conversion_policy_float_to_int_rounder]
[section Policy Float2IntRounder]
This ['stateless] template policy class specifies the rounding mode used
@@ -227,13 +219,11 @@ use a fully qualified call.
This technique allows the default rounder policies to be used directly with
user defined types. The user only requires that suitable overloads of `floor()` and `ceil()`
be visible. See also [link numeric_conversion_requirements User Defined Numeric Types]
be visible. See also [link boost_numericconversion.type_requirements_and_user_defined_types_support User Defined Numeric Types]
support.
[endsect]
[#numeric_conversion_policy_raw_converter]
[section Policy RawConverter]
This ['stateless] template policy class is used to perform the
@@ -275,8 +265,6 @@ This is the only raw converter policy class provided by the library:
[endsect]
[#numeric_conversion_policy_user_range_checker]
[section Policy UserRangeChecker]
This ['stateless] template policy class is used [_only if supplied]
+2 -12
View File
@@ -85,8 +85,6 @@ rest of this document.
[endsect]
[#numeric_conversion_cpp_arithmetic_types]
[section C++ Arithmetic Types]
The C++ language defines [_fundamental types] (§3.9.1). The following subsets of
@@ -144,8 +142,6 @@ positive values only (you can do this with signed types as well).
[endsect]
[#numeric_conversion_definitions_numeric_types]
[section Numeric Types]
This section introduces the following definitions intended to integrate
@@ -161,8 +157,8 @@ A type is [*numeric] if:
* It is a user-defined type which
* Represents numeric abstract values (i.e. numbers).
* Can be converted (either implicitly or explicitly) to/from at least one arithmetic type.
* Has [link numeric_conversion_definitions_range range] (possibly unbounded)
and [link numeric_conversion_definitions_range precision] (possibly dynamic or
* Has [link boost_numericconversion.definitions.range_and_precision range] (possibly unbounded)
and [link boost_numericconversion.definitions.range_and_precision precision] (possibly dynamic or
unlimited).
* Provides an specialization of `std::numeric_limits`.
@@ -216,8 +212,6 @@ types (and values):
[endsect]
[#numeric_conversion_definitions_range]
[section Range and Precision]
Given a number set `N`, some of its elements are representable in a numeric type `T`.
@@ -318,8 +312,6 @@ while the higher the number of mantissa bits, the higher the precision.
[endsect]
[#numeric_conversion_definitions_roundoff]
[section Exact, Correctly Rounded and Out-Of-Range Representations]
Given an abstract value `V` and a type `T` with its corresponding range `[abt(l),abt(h)]`:
@@ -454,8 +446,6 @@ that is, the conversion is required to be correctly rounded.
[endsect]
[#numeric_conversion_definitions_subranged]
[section Subranged Conversion Direction, Subtype and Supertype]
Given a source type `S` and a destination type `T`, there is a
@@ -1,45 +1,41 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>bounds&lt;&gt;
traits class</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>bounds&lt;&gt; traits class</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="prev" href="type_requirements_and_user_defined_types_support.html" title="Type
Requirements and User-defined-types support">
<link rel="next" href="conversion_traits___traits_class.html" title="conversion_traits&lt;&gt;
traits class">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="type_requirements_and_user_defined_types_support.html" title="Type Requirements and User-defined-types support">
<link rel="next" href="conversion_traits___traits_class.html" title="conversion_traits&lt;&gt; traits class">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="type_requirements_and_user_defined_types_support.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="conversion_traits___traits_class.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="type_requirements_and_user_defined_types_support.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="conversion_traits___traits_class.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_numericconversion.bounds___traits_class"></a><a href="bounds___traits_class.html" title="bounds&lt;&gt;
traits class">bounds&lt;&gt;
<a name="boost_numericconversion.bounds___traits_class"></a><a class="link" href="bounds___traits_class.html" title="bounds&lt;&gt; traits class">bounds&lt;&gt;
traits class</a>
</h2></div></div></div>
<div class="toc"><dl>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.traits_class_bounds_n_">traits
class bounds&lt;N&gt;</a></span></dt>
<dt><span class="section"><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.examples">Examples</a></span></dt>
</dl></div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.bounds___traits_class.introduction"></a><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.introduction" title="Introduction">Introduction</a>
<a name="boost_numericconversion.bounds___traits_class.introduction"></a><a class="link" href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
To determine the ranges of numeric types with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>
@@ -57,14 +53,12 @@
at compile time, so there is no runtime overhead.
</p>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.bounds___traits_class.traits_class_bounds_n_"></a><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.traits_class_bounds_n_" title="traits
class bounds&lt;N&gt;">traits
<a name="boost_numericconversion.bounds___traits_class.traits_class_bounds_n_"></a><a class="link" href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.traits_class_bounds_n_" title="traits class bounds&lt;N&gt;">traits
class bounds&lt;N&gt;</a>
</h3></div></div></div>
<pre class="programlisting">
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">N</span><span class="special">&gt;</span>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">N</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">bounds</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">N</span> <span class="identifier">lowest</span> <span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">implementation_defined</span><span class="special">;</span> <span class="special">}</span>
@@ -72,60 +66,41 @@
<span class="keyword">static</span> <span class="identifier">N</span> <span class="identifier">smallest</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">implementation_defined</span><span class="special">;</span> <span class="special">}</span>
<span class="special">};</span>
</pre>
<a name="boost_numericconversion.bounds___traits_class.traits_class_bounds_n_.members"></a><h5>
<a name="id2626382"></a>
<a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.traits_class_bounds_n_.members">Members</a>
<h5>
<a name="boost_numericconversion.bounds___traits_class.traits_class_bounds_n_.h0"></a>
<span class="phrase"><a name="boost_numericconversion.bounds___traits_class.traits_class_bounds_n_.members"></a></span><a class="link" href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.traits_class_bounds_n_.members">Members</a>
</h5>
<div class="blockquote"><blockquote class="blockquote">
<p>
</p>
<p>
<code class="computeroutput"><span class="identifier">lowest</span><span class="special">()</span></code>
</p>
<p>
</p>
</blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="identifier">lowest</span><span class="special">()</span></code>
</p></blockquote></div>
<p>
Returns the minimum finite value, equivalent to <code class="computeroutput"><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">min</span><span class="special">()</span></code> when
<code class="computeroutput"><span class="identifier">T</span></code> is an integral type, and
to <code class="computeroutput"><span class="special">-</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">max</span><span class="special">()</span></code> when
<code class="computeroutput"><span class="identifier">T</span></code> is a floating point type.
</p>
<div class="blockquote"><blockquote class="blockquote">
<p>
</p>
<p>
<code class="computeroutput"><span class="identifier">highest</span><span class="special">()</span></code>
</p>
<p>
</p>
</blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="identifier">highest</span><span class="special">()</span></code>
</p></blockquote></div>
<p>
Returns the maximum finite value, equivalent to <code class="computeroutput"><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">max</span><span class="special">()</span></code>.
</p>
<div class="blockquote"><blockquote class="blockquote">
<p>
</p>
<p>
<code class="computeroutput"><span class="identifier">smallest</span><span class="special">()</span></code>
</p>
<p>
</p>
</blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="identifier">smallest</span><span class="special">()</span></code>
</p></blockquote></div>
<p>
Returns the smallest positive normalized value for floating point types with
denormalization, or returns 0 for integral types.
</p>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.bounds___traits_class.examples"></a><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.examples" title="Examples">Examples</a>
<a name="boost_numericconversion.bounds___traits_class.examples"></a><a class="link" href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
The following example demonstrates the use of <code class="computeroutput"><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">bounds</span><span class="special">&lt;&gt;</span></code> and the equivalent code using <code class="computeroutput"><span class="identifier">numeric_limits</span></code>:
</p>
<pre class="programlisting">
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">numeric</span><span class="special">/</span><span class="identifier">conversion</span><span class="special">/</span><span class="identifier">bounds</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">limits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
@@ -153,7 +128,8 @@
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -161,7 +137,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="type_requirements_and_user_defined_types_support.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="conversion_traits___traits_class.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="type_requirements_and_user_defined_types_support.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="conversion_traits___traits_class.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -1,45 +1,41 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>conversion_traits&lt;&gt;
traits class</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>conversion_traits&lt;&gt; traits class</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="prev" href="bounds___traits_class.html" title="bounds&lt;&gt;
traits class">
<link rel="next" href="numeric_converter_policy_classes.html" title="Numeric
Converter Policy Classes">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="bounds___traits_class.html" title="bounds&lt;&gt; traits class">
<link rel="next" href="numeric_converter_policy_classes.html" title="Numeric Converter Policy Classes">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="bounds___traits_class.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="numeric_converter_policy_classes.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="bounds___traits_class.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="numeric_converter_policy_classes.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_numericconversion.conversion_traits___traits_class"></a><a href="conversion_traits___traits_class.html" title="conversion_traits&lt;&gt;
traits class">conversion_traits&lt;&gt;
<a name="boost_numericconversion.conversion_traits___traits_class"></a><a class="link" href="conversion_traits___traits_class.html" title="conversion_traits&lt;&gt; traits class">conversion_traits&lt;&gt;
traits class</a>
</h2></div></div></div>
<div class="toc"><dl>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types">Types</a></span></dt>
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.examples">Examples</a></span></dt>
</dl></div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types" title="Types">Types</a>
<a name="boost_numericconversion.conversion_traits___traits_class.types"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types" title="Types">Types</a>
</h3></div></div></div>
<div class="toc"><dl>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum">enumeration
int_float_mixture_enum</a></span></dt>
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum">enumeration
@@ -57,16 +53,12 @@
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_conversion_traits__">template
class conversion_traits&lt;&gt;</a></span></dt>
</dl></div>
<a name="numeric_conversion_traits_int_float_mixture_enum"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum" title="enumeration
int_float_mixture_enum">enumeration
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum" title="enumeration int_float_mixture_enum">enumeration
int_float_mixture_enum</a>
</h4></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">enum</span> <span class="identifier">int_float_mixture_enum</span>
<span class="special">{</span>
@@ -76,19 +68,15 @@
<span class="special">,</span><span class="identifier">float_to_float</span>
<span class="special">}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric
</span></pre>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
</pre>
</div>
<a name="numeric_conversion_traits_sign_mixture_enum"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum" title="enumeration
sign_mixture_enum">enumeration
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum" title="enumeration sign_mixture_enum">enumeration
sign_mixture_enum</a>
</h4></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">enum</span> <span class="identifier">sign_mixture_enum</span>
<span class="special">{</span>
@@ -98,19 +86,15 @@
<span class="special">,</span><span class="identifier">unsigned_to_signed</span>
<span class="special">}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric
</span></pre>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
</pre>
</div>
<a name="numeric_conversion_traits_udt_builtin_mixture_enum"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum" title="enumeration
udt_builtin_mixture_enum">enumeration
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum" title="enumeration udt_builtin_mixture_enum">enumeration
udt_builtin_mixture_enum</a>
</h4></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">enum</span> <span class="identifier">udt_builtin_mixture_enum</span>
<span class="special">{</span>
@@ -120,103 +104,87 @@
<span class="special">,</span><span class="identifier">udt_to_udt</span>
<span class="special">}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric
</span></pre>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
</pre>
</div>
<a name="numeric_conversion_traits_class_int_float_mixture"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__" title="template
class int_float_mixture&lt;&gt;">template
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__" title="template class int_float_mixture&lt;&gt;">template
class int_float_mixture&lt;&gt;</a>
</h4></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">int_float_mixture</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special">&lt;</span><span class="identifier">int_float_mixture_enum</span><span class="special">,</span> <span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">&gt;</span> <span class="special">{}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric
</span></pre>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
</pre>
<p>
Classifying <code class="computeroutput"><span class="identifier">S</span></code> and <code class="computeroutput"><span class="identifier">T</span></code> as either integral or float, this
<a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's Integral
Constant</a> indicates the combination of these attributes.
</p>
<p>
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
is of enumeration type <a href="conversion_traits___traits_class.html#numeric_conversion_traits_int_float_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">int_float_mixture_enum</span></code></a>
</p>
</div>
<a name="numeric_conversion_traits_class_sign_mixture"></a><p>
</p>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__" title="template
class sign_mixture&lt;&gt;">template
class sign_mixture&lt;&gt;</a>
</h4></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">sign_mixture</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special">&lt;</span><span class="identifier">sign_mixture_enum</span><span class="special">,</span> <span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">&gt;</span> <span class="special">{}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric
</span></pre>
<p>
Classifying <code class="computeroutput"><span class="identifier">S</span></code> and <code class="computeroutput"><span class="identifier">T</span></code> as either signed or unsigned, this
<a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's Integral
Constant</a> indicates the combination of these attributes.
</p>
<p>
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
is of enumeration type <a href="conversion_traits___traits_class.html#numeric_conversion_traits_sign_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">sign_mixture_enum</span></code></a>
</p>
</div>
<a name="numeric_conversion_traits_class_udt_builtin_mixture"></a><p>
</p>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__" title="template
class udt_builtin_mixture&lt;&gt;">template
class udt_builtin_mixture&lt;&gt;</a>
</h4></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">udt_builtin_mixture</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special">&lt;</span><span class="identifier">udt_builtin__mixture_enum</span><span class="special">,</span> <span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">&gt;</span> <span class="special">{}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric
</span></pre>
<p>
Classifying <code class="computeroutput"><span class="identifier">S</span></code> and <code class="computeroutput"><span class="identifier">T</span></code> as either user-defined or builtin,
this <a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's
<a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
Integral Constant</a> indicates the combination of these attributes.
</p>
<p>
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
is of enumeration type <a href="conversion_traits___traits_class.html#numeric_conversion_traits_udt_builtin_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">udt_builtin_mixture_enum</span></code></a>
is of enumeration type <a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum" title="enumeration int_float_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">int_float_mixture_enum</span></code></a>
</p>
</div>
<a name="numeric_conversion_traits_is_subranged"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__" title="template
class is_subranged&lt;&gt;">template
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__" title="template class sign_mixture&lt;&gt;">template
class sign_mixture&lt;&gt;</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">sign_mixture</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special">&lt;</span><span class="identifier">sign_mixture_enum</span><span class="special">,</span> <span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">&gt;</span> <span class="special">{}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
</pre>
<p>
Classifying <code class="computeroutput"><span class="identifier">S</span></code> and <code class="computeroutput"><span class="identifier">T</span></code> as either signed or unsigned, this
<a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
Integral Constant</a> indicates the combination of these attributes.
</p>
<p>
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
is of enumeration type <a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum" title="enumeration sign_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">sign_mixture_enum</span></code></a>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__" title="template class udt_builtin_mixture&lt;&gt;">template
class udt_builtin_mixture&lt;&gt;</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">udt_builtin_mixture</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special">&lt;</span><span class="identifier">udt_builtin__mixture_enum</span><span class="special">,</span> <span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">&gt;</span> <span class="special">{}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
</pre>
<p>
Classifying <code class="computeroutput"><span class="identifier">S</span></code> and <code class="computeroutput"><span class="identifier">T</span></code> as either user-defined or builtin,
this <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
Integral Constant</a> indicates the combination of these attributes.
</p>
<p>
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
is of enumeration type <a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum" title="enumeration udt_builtin_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">udt_builtin_mixture_enum</span></code></a>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__" title="template class is_subranged&lt;&gt;">template
class is_subranged&lt;&gt;</a>
</h4></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">is_subranged</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">bool_</span><span class="special">&lt;</span><span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">&gt;</span> <span class="special">{}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric
</span></pre>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
</pre>
<p>
Indicates if the range of the target type <code class="computeroutput"><span class="identifier">T</span></code>
is a subset of the range of the source type <code class="computeroutput"><span class="identifier">S</span></code>.
@@ -224,7 +192,7 @@
range.
</p>
<p>
It is a boolean <a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's
It is a boolean <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
Integral Constant</a> .
</p>
<p>
@@ -233,14 +201,12 @@
the source values are representable as Target type.
</p>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_conversion_traits__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_conversion_traits__" title="template
class conversion_traits&lt;&gt;">template
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_conversion_traits__"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_conversion_traits__" title="template class conversion_traits&lt;&gt;">template
class conversion_traits&lt;&gt;</a>
</h4></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">conversion_traits</span>
@@ -260,18 +226,18 @@
<span class="keyword">typedef</span> <span class="special">...</span> <span class="identifier">subtype</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, namespace boost
</span></pre>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, namespace boost</span>
</pre>
<p>
This traits class indicates some properties of a <span class="emphasis"><em>numeric conversion</em></span>
direction: from a source type <code class="computeroutput"><span class="identifier">S</span></code>
to a target type <code class="computeroutput"><span class="identifier">T</span></code>. It
does not indicate the properties of a <span class="emphasis"><em>specific</em></span> conversion,
but of the conversion direction. See <a href="definitions.html#numeric_conversion_definitions_subranged">Definitions</a>
but of the conversion direction. See <a class="link" href="definitions.html#boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype" title="Subranged Conversion Direction, Subtype and Supertype">Definitions</a>
for details.
</p>
<p>
The traits class provides the following <a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's
The traits class provides the following <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
Integral Constant</a> \s of enumeration type. They express the combination
of certain attributes of the Source and Target types (thus they are call
mixture):
@@ -283,57 +249,53 @@
</colgroup>
<thead><tr>
<th>
<p>
</p>
</th>
<th>
<p>
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<span class="bold"><strong>int_float_mixture </strong></span>
</p>
<p>
<span class="bold"><strong>int_float_mixture </strong></span>
</p>
</td>
<td>
<p>
Same as given by the traits class <a href="conversion_traits___traits_class.html#numeric_conversion_traits_class_int_float_mixture">int_float_mixture</a>
</p>
<p>
Same as given by the traits class <a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__" title="template class int_float_mixture&lt;&gt;">int_float_mixture</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="bold"><strong>sign_mixture </strong></span>
</p>
<p>
<span class="bold"><strong>sign_mixture </strong></span>
</p>
</td>
<td>
<p>
Same as given by the traits class <a href="conversion_traits___traits_class.html#numeric_conversion_traits_class_sign_mixture">sign_mixture</a>
</p>
<p>
Same as given by the traits class <a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__" title="template class sign_mixture&lt;&gt;">sign_mixture</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="bold"><strong>udt_builtin_mixture </strong></span>
</p>
<p>
<span class="bold"><strong>udt_builtin_mixture </strong></span>
</p>
</td>
<td>
<p>
Same as given by the traits class <a href="conversion_traits___traits_class.html#numeric_conversion_traits_class_udt_builtin_mixture">udt_builtin_mixture</a>
</p>
<p>
Same as given by the traits class <a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__" title="template class udt_builtin_mixture&lt;&gt;">udt_builtin_mixture</a>
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
The traits class provides the following <a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's
The traits class provides the following <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
Integral Constant</a> \s of boolean type which indicates indirectly
the relation between the Source and Target ranges (see <a href="definitions.html#numeric_conversion_definitions_range">Definitions</a>
the relation between the Source and Target ranges (see <a class="link" href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">Definitions</a>
for details).
</p>
<div class="informaltable"><table class="table">
@@ -343,42 +305,38 @@
</colgroup>
<thead><tr>
<th>
<p>
</p>
</th>
<th>
<p>
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
subranged
</p>
<p>
subranged
</p>
</td>
<td>
<p>
Same as given by <a href="conversion_traits___traits_class.html#numeric_conversion_traits_is_subranged">is_subranged</a>
</p>
<p>
Same as given by <a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__" title="template class is_subranged&lt;&gt;">is_subranged</a>
</p>
</td>
</tr>
<tr>
<td>
<p>
trivial
</p>
<p>
trivial
</p>
</td>
<td>
<p>
Indicates if both Source and Target, <span class="underline">without
cv-qualifications</span>, are the same type.
</p>
<p>
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
is of boolean type.
</p>
<p>
Indicates if both Source and Target, <span class="underline">without
cv-qualifications</span>, are the same type.
</p>
<p>
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
is of boolean type.
</p>
</td>
</tr>
</tbody>
@@ -394,140 +352,135 @@
</colgroup>
<thead><tr>
<th>
<p>
</p>
</th>
<th>
<p>
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<span class="bold"><strong>target_type</strong></span>
</p>
<p>
<span class="bold"><strong>target_type</strong></span>
</p>
</td>
<td>
<p>
The template parameter <code class="computeroutput"><span class="identifier">T</span></code>
without cv-qualifications
</p>
<p>
The template parameter <code class="computeroutput"><span class="identifier">T</span></code>
without cv-qualifications
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="bold"><strong>source_type</strong></span>
</p>
<p>
<span class="bold"><strong>source_type</strong></span>
</p>
</td>
<td>
<p>
The template parameter <code class="computeroutput"><span class="identifier">S</span></code>
without cv-qualifications
</p>
<p>
The template parameter <code class="computeroutput"><span class="identifier">S</span></code>
without cv-qualifications
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="bold"><strong>argument_type</strong></span>
</p>
<p>
<span class="bold"><strong>argument_type</strong></span>
</p>
</td>
<td>
<p>
This type is either source_type or <code class="computeroutput"><span class="identifier">source_type</span>
<span class="keyword">const</span><span class="special">&amp;</span></code>.
</p>
<p>
It represents the optimal argument type for the <a href="../index.html#numeric_conversion_converter">converter</a>
member functions.
</p>
<p>
If S is a built-in type, this is <code class="computeroutput"><span class="identifier">source_type</span></code>,
otherwise, this is <code class="computeroutput"><span class="identifier">source_type</span>
<span class="keyword">const</span><span class="special">&amp;</span></code>.
</p>
<p>
This type is either source_type or <code class="computeroutput"><span class="identifier">source_type</span>
<span class="keyword">const</span><span class="special">&amp;</span></code>.
</p>
<p>
It represents the optimal argument type for the <a class="link" href="converter___function_object.html" title="converter&lt;&gt; function object">converter</a>
member functions.
</p>
<p>
If S is a built-in type, this is <code class="computeroutput"><span class="identifier">source_type</span></code>,
otherwise, this is <code class="computeroutput"><span class="identifier">source_type</span>
<span class="keyword">const</span><span class="special">&amp;</span></code>.
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="bold"><strong>result_type</strong></span>
</p>
<p>
<span class="bold"><strong>result_type</strong></span>
</p>
</td>
<td>
<p>
This type is either target_type or target_type const&amp;
</p>
<p>
It represents the return type of the <a href="../index.html#numeric_conversion_converter">converter</a>
member functions.
</p>
<p>
If <code class="computeroutput"><span class="identifier">T</span><span class="special">==</span><span class="identifier">S</span></code>, it is <code class="computeroutput"><span class="identifier">target_type</span>
<span class="keyword">const</span><span class="special">&amp;</span></code>,
otherwise, it is <code class="computeroutput"><span class="identifier">target_type</span></code>.
</p>
<p>
This type is either target_type or target_type const&amp;
</p>
<p>
It represents the return type of the <a class="link" href="converter___function_object.html" title="converter&lt;&gt; function object">converter</a>
member functions.
</p>
<p>
If <code class="computeroutput"><span class="identifier">T</span><span class="special">==</span><span class="identifier">S</span></code>, it is <code class="computeroutput"><span class="identifier">target_type</span>
<span class="keyword">const</span><span class="special">&amp;</span></code>,
otherwise, it is <code class="computeroutput"><span class="identifier">target_type</span></code>.
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="bold"><strong>supertype</strong></span>
</p>
<p>
<span class="bold"><strong>supertype</strong></span>
</p>
</td>
<td>
<p>
If the conversion is subranged, it is <code class="computeroutput"><span class="identifier">source_type</span></code>,
otherwise, it is <code class="computeroutput"><span class="identifier">target_type</span></code>
</p>
<p>
If the conversion is subranged, it is <code class="computeroutput"><span class="identifier">source_type</span></code>,
otherwise, it is <code class="computeroutput"><span class="identifier">target_type</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="bold"><strong>subtype</strong></span>
</p>
<p>
<span class="bold"><strong>subtype</strong></span>
</p>
</td>
<td>
<p>
If the conversion is subranged, it is <code class="computeroutput"><span class="identifier">target_type</span></code>,
otherwise, it is <code class="computeroutput"><span class="identifier">source_type</span></code>
</p>
<p>
If the conversion is subranged, it is <code class="computeroutput"><span class="identifier">target_type</span></code>,
otherwise, it is <code class="computeroutput"><span class="identifier">source_type</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.conversion_traits___traits_class.examples"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.examples" title="Examples">Examples</a>
<a name="boost_numericconversion.conversion_traits___traits_class.examples"></a><a class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.examples" title="Examples">Examples</a>
</h3></div></div></div>
<pre class="programlisting">
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cassert</span><span class="special">&gt;</span>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cassert</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">typeinfo</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">numeric</span><span class="special">/</span><span class="identifier">conversion</span><span class="special">/</span><span class="identifier">conversion_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
<span class="comment">// A trivial conversion.
</span> <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="keyword">short</span><span class="special">,</span><span class="keyword">short</span><span class="special">&gt;</span> <span class="identifier">Short2Short_Traits</span> <span class="special">;</span>
<span class="comment">// A trivial conversion.</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="keyword">short</span><span class="special">,</span><span class="keyword">short</span><span class="special">&gt;</span> <span class="identifier">Short2Short_Traits</span> <span class="special">;</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">Short2Short_Traits</span><span class="special">::</span><span class="identifier">trivial</span><span class="special">::</span><span class="identifier">value</span> <span class="special">)</span> <span class="special">;</span>
<span class="comment">// A subranged conversion.
</span> <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">UInt2Double_Traits</span> <span class="special">;</span>
<span class="comment">// A subranged conversion.</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">UInt2Double_Traits</span> <span class="special">;</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">UInt2Double_Traits</span><span class="special">::</span><span class="identifier">int_float_mixture</span><span class="special">::</span><span class="identifier">value</span> <span class="special">==</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">integral_to_float</span> <span class="special">)</span> <span class="special">;</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">UInt2Double_Traits</span><span class="special">::</span><span class="identifier">sign_mixture</span><span class="special">::</span><span class="identifier">value</span> <span class="special">==</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">unsigned_to_signed</span> <span class="special">)</span> <span class="special">;</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!</span><span class="identifier">UInt2Double_Traits</span><span class="special">::</span><span class="identifier">subranged</span><span class="special">::</span><span class="identifier">value</span> <span class="special">)</span> <span class="special">;</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="keyword">typeid</span><span class="special">(</span><span class="identifier">UInt2Double_Traits</span><span class="special">::</span><span class="identifier">supertype</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">typeid</span><span class="special">(</span><span class="keyword">double</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="keyword">typeid</span><span class="special">(</span><span class="identifier">UInt2Double_Traits</span><span class="special">::</span><span class="identifier">subtype</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">typeid</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
<span class="comment">// A doubly subranged conversion.
</span> <span class="identifier">assert</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="keyword">short</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">short</span><span class="special">&gt;::</span><span class="identifier">subranged</span><span class="special">::</span><span class="identifier">value</span><span class="special">)</span> <span class="special">);</span>
<span class="comment">// A doubly subranged conversion.</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="keyword">short</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">short</span><span class="special">&gt;::</span><span class="identifier">subranged</span><span class="special">::</span><span class="identifier">value</span><span class="special">)</span> <span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">short</span><span class="special">,</span> <span class="keyword">short</span><span class="special">&gt;::</span><span class="identifier">subranged</span><span class="special">::</span><span class="identifier">value</span><span class="special">)</span> <span class="special">);</span>
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
@@ -537,7 +490,8 @@
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -545,7 +499,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="bounds___traits_class.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="numeric_converter_policy_classes.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="bounds___traits_class.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="numeric_converter_policy_classes.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -1,36 +1,33 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>converter&lt;&gt;
function object</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>converter&lt;&gt; function object</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="definitions.html" title="Definitions">
<link rel="next" href="type_requirements_and_user_defined_types_support.html" title="Type
Requirements and User-defined-types support">
<link rel="next" href="type_requirements_and_user_defined_types_support.html" title="Type Requirements and User-defined-types support">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="definitions.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="type_requirements_and_user_defined_types_support.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="definitions.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="type_requirements_and_user_defined_types_support.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_numericconversion.converter___function_object"></a><a href="converter___function_object.html" title="converter&lt;&gt;
function object">converter&lt;&gt;
<a name="boost_numericconversion.converter___function_object"></a><a class="link" href="converter___function_object.html" title="converter&lt;&gt; function object">converter&lt;&gt;
function object</a>
</h2></div></div></div>
<div class="toc"><dl>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="converter___function_object.html#boost_numericconversion.converter___function_object.synopsis">Synopsis</a></span></dt>
<dt><span class="section"><a href="converter___function_object.html#boost_numericconversion.converter___function_object.template_parameters">Template
parameters</a></span></dt>
@@ -40,12 +37,11 @@
Checking Logic</a></span></dt>
<dt><span class="section"><a href="converter___function_object.html#boost_numericconversion.converter___function_object.examples">Examples</a></span></dt>
</dl></div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.converter___function_object.synopsis"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.synopsis" title="Synopsis">Synopsis</a>
<a name="boost_numericconversion.converter___function_object.synopsis"></a><a class="link" href="converter___function_object.html#boost_numericconversion.converter___function_object.synopsis" title="Synopsis">Synopsis</a>
</h3></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span>
@@ -68,8 +64,8 @@
<span class="identifier">result_type</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span> <span class="keyword">const</span> <span class="special">;</span>
<span class="comment">// Internal member functions:
</span>
<span class="comment">// Internal member functions:</span>
<span class="keyword">static</span> <span class="identifier">range_check_result</span> <span class="identifier">out_of_range</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span> <span class="special">;</span>
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">validate_range</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span> <span class="special">;</span>
<span class="keyword">static</span> <span class="identifier">result_type</span> <span class="identifier">low_level_convert</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span> <span class="special">;</span>
@@ -77,22 +73,21 @@
<span class="special">}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, boost
</span></pre>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, boost</span>
</pre>
<p>
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">converter</span><span class="special">&lt;&gt;</span></code>
is a <a href="http://www.sgi.com/tech/stl/UnaryFunction.html" target="_top">Unary Function
Object</a> encapsulating the code to perform a numeric conversion with
the direction and properties specified by the Traits template parameter.
It can optionally take some <a href="../index.html#numeric_coversion_converter_policies">policies</a>
It can optionally take some <a class="link" href="numeric_converter_policy_classes.html" title="Numeric Converter Policy Classes">policies</a>
which can be used to customize its behavior. The <code class="computeroutput"><span class="identifier">Traits</span></code>
parameter is not a policy but the parameter that defines the conversion.
</p>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.converter___function_object.template_parameters"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.template_parameters" title="Template
parameters">Template
<a name="boost_numericconversion.converter___function_object.template_parameters"></a><a class="link" href="converter___function_object.html#boost_numericconversion.converter___function_object.template_parameters" title="Template parameters">Template
parameters</a>
</h3></div></div></div>
<div class="informaltable"><table class="table">
@@ -102,145 +97,132 @@
</colgroup>
<thead><tr>
<th>
<p>
</p>
</th>
<th>
<p>
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">T</span></code>
</p>
<p>
<code class="computeroutput"><span class="identifier">T</span></code>
</p>
</td>
<td>
<p>
The <a href="definitions.html#numeric_conversion_definitions_numeric_types">Numeric
Type</a> which is the <span class="emphasis"><em>Target</em></span> of the conversion.
</p>
<p>
The <a class="link" href="definitions.html#boost_numericconversion.definitions.numeric_types" title="Numeric Types">Numeric
Type</a> which is the <span class="emphasis"><em>Target</em></span> of the conversion.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">S</span></code>
</p>
<p>
<code class="computeroutput"><span class="identifier">S</span></code>
</p>
</td>
<td>
<p>
The <a href="definitions.html#numeric_conversion_definitions_numeric_types">Numeric
Type</a> which is the <span class="emphasis"><em>Source</em></span> of the conversion.
</p>
<p>
The <a class="link" href="definitions.html#boost_numericconversion.definitions.numeric_types" title="Numeric Types">Numeric
Type</a> which is the <span class="emphasis"><em>Source</em></span> of the conversion.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">Traits</span></code>
</p>
<p>
<code class="computeroutput"><span class="identifier">Traits</span></code>
</p>
</td>
<td>
<p>
This must be a conversion traits class with the interface of <a href="../index.html#numeric_conversion_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span></code></a>
</p>
<p>
This must be a conversion traits class with the interface of <a class="link" href="conversion_traits___traits_class.html" title="conversion_traits&lt;&gt; traits class"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span></code></a>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">OverflowHandler</span></code>
</p>
<p>
<code class="computeroutput"><span class="identifier">OverflowHandler</span></code>
</p>
</td>
<td>
<p>
<span class="bold"><strong>Stateless Policy</strong></span> called to administrate
the result of the range checking.
</p>
<p>
It is a <span class="bold"><strong>Function Object</strong></span> which receives
the result of <code class="computeroutput"><span class="identifier">out_of_range</span><span class="special">()</span></code> and is called inside the <code class="computeroutput"><span class="identifier">validate_range</span><span class="special">()</span></code>
static member function exposed by the converter.
</p>
<p>
<span class="bold"><strong>Stateless Policy</strong></span> called to administrate
the result of the range checking.
</p>
<p>
It is a <span class="bold"><strong>Function Object</strong></span> which
receives the result of <code class="computeroutput"><span class="identifier">out_of_range</span><span class="special">()</span></code> and is called inside the <code class="computeroutput"><span class="identifier">validate_range</span><span class="special">()</span></code>
static member function exposed by the converter.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">Float2IntRounder</span></code>
</p>
<p>
<code class="computeroutput"><span class="identifier">Float2IntRounder</span></code>
</p>
</td>
<td>
<p>
<span class="bold"><strong>Stateless Policy</strong></span> which specifies
the rounding mode used for float to integral conversions.
</p>
<p>
It supplies the <code class="computeroutput"><span class="identifier">nearbyint</span><span class="special">()</span></code> static member function exposed
by the converter.
</p>
<p>
<span class="bold"><strong>Stateless Policy</strong></span> which specifies
the rounding mode used for float to integral conversions.
</p>
<p>
It supplies the <code class="computeroutput"><span class="identifier">nearbyint</span><span class="special">()</span></code> static member function exposed
by the converter.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">RawConverter</span></code>
</p>
<p>
<code class="computeroutput"><span class="identifier">RawConverter</span></code>
</p>
</td>
<td>
<p>
<span class="bold"><strong>Stateless Policy</strong></span> which is used to
perform the actual conversion.
</p>
<p>
It supplies the <code class="computeroutput"><span class="identifier">low_level_convert</span><span class="special">()</span></code> static member function exposed
by the converter.
</p>
<p>
<span class="bold"><strong>Stateless Policy</strong></span> which is used
to perform the actual conversion.
</p>
<p>
It supplies the <code class="computeroutput"><span class="identifier">low_level_convert</span><span class="special">()</span></code> static member function exposed
by the converter.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">UserRangeChecker</span></code>
</p>
<p>
<code class="computeroutput"><span class="identifier">UserRangeChecker</span></code>
</p>
</td>
<td>
<p>
<span class="emphasis"><em>Special and Optional</em></span> <span class="bold"><strong>Stateless
Policy</strong></span> which can be used to override the internal range
checking logic.
</p>
<p>
If given, supplies alternative code for the <code class="computeroutput"><span class="identifier">out_of_range</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">validate_range</span><span class="special">()</span></code> static member functions exposed
by the converter.
</p>
<p>
<span class="emphasis"><em>Special and Optional</em></span> <span class="bold"><strong>Stateless
Policy</strong></span> which can be used to override the internal range
checking logic.
</p>
<p>
If given, supplies alternative code for the <code class="computeroutput"><span class="identifier">out_of_range</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">validate_range</span><span class="special">()</span></code> static member functions exposed
by the converter.
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.converter___function_object.member_functions"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.member_functions" title="Member
functions">Member
<a name="boost_numericconversion.converter___function_object.member_functions"></a><a class="link" href="converter___function_object.html#boost_numericconversion.converter___function_object.member_functions" title="Member functions">Member
functions</a>
</h3></div></div></div>
<div class="blockquote"><blockquote class="blockquote">
<p>
</p>
<p>
<code class="computeroutput"><span class="keyword">static</span> <span class="identifier">result_type</span>
<span class="identifier">converter</span><span class="special">&lt;&gt;::</span><span class="identifier">convert</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span>
<span class="comment">// throw </span></code>
</p>
<p>
</p>
</blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="keyword">static</span> <span class="identifier">result_type</span>
<span class="identifier">converter</span><span class="special">&lt;&gt;::</span><span class="identifier">convert</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span> <span class="comment">// throw</span> </code>
</p></blockquote></div>
<p>
This static member function converts an rvalue of type <code class="computeroutput"><span class="identifier">source_type</span></code>
to an rvalue of type <code class="computeroutput"><span class="identifier">target_type</span></code>.
@@ -254,18 +236,17 @@
The implementation of this function is actually built from the policies and
is basically as follows:
</p>
<pre class="programlisting">
<span class="identifier">result_type</span> <span class="identifier">converter</span><span class="special">&lt;&gt;::</span><span class="identifier">convert</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<pre class="programlisting"><span class="identifier">result_type</span> <span class="identifier">converter</span><span class="special">&lt;&gt;::</span><span class="identifier">convert</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">validate_range</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span> <span class="comment">// Implemented by the internal range checking logic
</span> <span class="comment">// (which also calls the OverflowHandler policy)
</span> <span class="comment">// or externally supplied by the UserRangeChecker policy.
</span>
<span class="identifier">s</span> <span class="special">=</span> <span class="identifier">nearbyint</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span> <span class="comment">// Externally supplied by the Float2IntRounder policy.
</span> <span class="comment">// NOTE: This is actually called only for float to int conversions.
</span>
<span class="keyword">return</span> <span class="identifier">low_level_convert</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span> <span class="comment">// Externally supplied by the RawConverter policy.
</span><span class="special">}</span>
<span class="identifier">validate_range</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span> <span class="comment">// Implemented by the internal range checking logic</span>
<span class="comment">// (which also calls the OverflowHandler policy)</span>
<span class="comment">// or externally supplied by the UserRangeChecker policy.</span>
<span class="identifier">s</span> <span class="special">=</span> <span class="identifier">nearbyint</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span> <span class="comment">// Externally supplied by the Float2IntRounder policy.</span>
<span class="comment">// NOTE: This is actually called only for float to int conversions.</span>
<span class="keyword">return</span> <span class="identifier">low_level_convert</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span> <span class="comment">// Externally supplied by the RawConverter policy.</span>
<span class="special">}</span>
</pre>
<p>
<code class="computeroutput"><span class="identifier">converter</span><span class="special">&lt;&gt;::</span><span class="keyword">operator</span><span class="special">()</span> <span class="keyword">const</span></code> just calls <code class="computeroutput"><span class="identifier">convert</span><span class="special">()</span></code>
@@ -273,42 +254,36 @@
<p>
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
</p>
<div class="blockquote"><blockquote class="blockquote">
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="keyword">static</span> <span class="identifier">range_check_result</span>
<span class="identifier">numeric_converter</span><span class="special">&lt;&gt;::</span><span class="identifier">out_of_range</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span></code>
</p></blockquote></div>
<p>
</p>
<p>
<code class="computeroutput"><span class="keyword">static</span> <span class="identifier">range_check_result</span>
<span class="identifier">numeric_converter</span><span class="special">&lt;&gt;::</span><span class="identifier">out_of_range</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span></code>
</p>
<p>
</p>
</blockquote></div>
<p>
This <a href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
static member function determines if the value <code class="computeroutput"><span class="identifier">s</span></code>
can be represented by the target type without overflow.
</p>
<p>
It does not determine if the conversion is <span class="emphasis"><em>exact</em></span>; that
is, it does not detect <span class="emphasis"><em>inexact</em></span> conversions, only <span class="emphasis"><em>out-of-range</em></span>
conversions (see the <a href="definitions.html#numeric_conversion_definitions_roundoff">Definitions</a>
conversions (see the <a class="link" href="definitions.html#boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations" title="Exact, Correctly Rounded and Out-Of-Range Representations">Definitions</a>
for further details).
</p>
<p>
The return value is of enum type <a href="numeric_converter_policy_classes.html#numeric_conversion_converter_policies_range_check_result"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">range_check_result</span></code></a>
The return value is of enum type <a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result" title="enum range_check_result"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">range_check_result</span></code></a>
</p>
<p>
The actual code for the range checking logic is optimized for the combined
properties of the source and target types. For example, a non-subranged conversion
(i.e: <code class="computeroutput"><span class="keyword">int</span></code>-&gt;<code class="computeroutput"><span class="keyword">float</span></code>), requires no range checking, so <code class="computeroutput"><span class="identifier">out_of_range</span><span class="special">()</span></code>
returns <code class="computeroutput"><span class="identifier">cInRange</span></code> directly.
See the following <a href="converter___function_object.html#numeric_conversion_converter_range_checking_logic">table</a>
See the following <a class="link" href="converter___function_object.html#boost_numericconversion.converter___function_object.range_checking_logic" title="Range Checking Logic">table</a>
for more details.
</p>
<p>
If the user supplied a <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
If the user supplied a <a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker" title="Policy UserRangeChecker">UserRangeChecker</a>
policy, is this policy which implements this function, so the implementation
is user defined, although it is expected to perform the same conceptual check
and return the appropriate result.
@@ -316,23 +291,16 @@
<p>
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
</p>
<div class="blockquote"><blockquote class="blockquote">
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">numeric_converter</span><span class="special">&lt;&gt;::</span><span class="identifier">validate_range</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span> <span class="comment">// no throw</span> </code>
</p></blockquote></div>
<p>
</p>
<p>
<code class="computeroutput"><span class="keyword">static</span> <span class="keyword">void</span>
<span class="identifier">numeric_converter</span><span class="special">&lt;&gt;::</span><span class="identifier">validate_range</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span>
<span class="comment">// no throw </span></code>
</p>
<p>
</p>
</blockquote></div>
<p>
This <a href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
static member function calls out_of_range(s), and passes the result to the
<a href="numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler">OverflowHandler</a>
<a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler" title="Policy OverflowHandler">OverflowHandler</a>
policy class.
</p>
<p>
@@ -340,7 +308,7 @@
this is an empty inline function.
</p>
<p>
If the user supplied a <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
If the user supplied a <a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker" title="Policy UserRangeChecker">UserRangeChecker</a>
policy, is this policy which implements this function, so the implementation
is user defined, although it is expected to perform the same action as the
default. In particular, it is expected to pass the result of the check to
@@ -349,60 +317,46 @@
<p>
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
</p>
<div class="blockquote"><blockquote class="blockquote">
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="keyword">static</span> <span class="identifier">result_type</span>
<span class="identifier">numeric_converter</span><span class="special">&lt;&gt;::</span><span class="identifier">low_level_convert</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span></code>
</p></blockquote></div>
<p>
</p>
<p>
<code class="computeroutput"><span class="keyword">static</span> <span class="identifier">result_type</span>
<span class="identifier">numeric_converter</span><span class="special">&lt;&gt;::</span><span class="identifier">low_level_convert</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span></code>
</p>
<p>
</p>
</blockquote></div>
<p>
This <a href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
static member function performs the actual conversion.
</p>
<p>
This function is externally supplied by the <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_raw_converter">RawConverter</a>
This function is externally supplied by the <a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter" title="Policy RawConverter">RawConverter</a>
policy class.
</p>
<p>
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
</p>
<div class="blockquote"><blockquote class="blockquote">
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="keyword">static</span> <span class="identifier">source_type</span>
<span class="identifier">converter</span><span class="special">&lt;&gt;::</span><span class="identifier">nearbyint</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span></code>
</p></blockquote></div>
<p>
</p>
<p>
<code class="computeroutput"><span class="keyword">static</span> <span class="identifier">source_type</span>
<span class="identifier">converter</span><span class="special">&lt;&gt;::</span><span class="identifier">nearbyint</span> <span class="special">(</span>
<span class="identifier">argument_type</span> <span class="identifier">s</span>
<span class="special">)</span> <span class="special">;</span></code>
</p>
<p>
</p>
</blockquote></div>
<p>
This <a href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
static member function, which is <span class="underline">only used</span>
for <code class="computeroutput"><span class="keyword">float</span></code> to <code class="computeroutput"><span class="keyword">int</span></code>
conversions, returns an <span class="emphasis"><em>integer</em></span> value of <span class="emphasis"><em><span class="underline">floating-point type</span></em></span> according to some
rounding direction.
</p>
<p>
This function is externally supplied by the <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_float_to_int_rounder">Float2IntRounder</a>
This function is externally supplied by the <a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder" title="Policy Float2IntRounder">Float2IntRounder</a>
policy class which encapsulates the specific rounding mode.
</p>
<p>
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
</p>
<a name="numeric_conversion_converter_internal"></a><p>
</p>
<a name="boost_numericconversion.converter___function_object.member_functions.internal_member_functions"></a><h5>
<a name="id2624118"></a>
<a href="converter___function_object.html#boost_numericconversion.converter___function_object.member_functions.internal_member_functions">Internal
<a name="numeric_conversion_converter_internal"></a><h5>
<a name="boost_numericconversion.converter___function_object.member_functions.h0"></a>
<span class="phrase"><a name="boost_numericconversion.converter___function_object.member_functions.internal_member_functions"></a></span><a class="link" href="converter___function_object.html#boost_numericconversion.converter___function_object.member_functions.internal_member_functions">Internal
Member Functions</a>
</h5>
<p>
@@ -411,12 +365,9 @@
called separately for specific needs.
</p>
</div>
<a name="numeric_conversion_converter_range_checking_logic"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.converter___function_object.range_checking_logic"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.range_checking_logic" title="Range
Checking Logic">Range
<a name="boost_numericconversion.converter___function_object.range_checking_logic"></a><a class="link" href="converter___function_object.html#boost_numericconversion.converter___function_object.range_checking_logic" title="Range Checking Logic">Range
Checking Logic</a>
</h3></div></div></div>
<p>
@@ -463,12 +414,11 @@ float_to_float |--&gt; subranged |--&gt; ( s &gt;= S(LowestT) ) &amp;&amp; (
</code>
</pre>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.converter___function_object.examples"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.examples" title="Examples">Examples</a>
<a name="boost_numericconversion.converter___function_object.examples"></a><a class="link" href="converter___function_object.html#boost_numericconversion.converter___function_object.examples" title="Examples">Examples</a>
</h3></div></div></div>
<pre class="programlisting">
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cassert</span><span class="special">&gt;</span>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cassert</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">numeric</span><span class="special">/</span><span class="identifier">conversion</span><span class="special">/</span><span class="identifier">converter</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> <span class="special">{</span>
@@ -478,14 +428,14 @@ float_to_float |--&gt; subranged |--&gt; ( s &gt;= S(LowestT) ) &amp;&amp; (
<span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">Double2Int</span><span class="special">::</span><span class="identifier">convert</span><span class="special">(</span><span class="number">2.0</span><span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">x</span> <span class="special">==</span> <span class="number">2</span> <span class="special">);</span>
<span class="keyword">int</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">Double2Int</span><span class="special">()(</span><span class="number">3.14</span><span class="special">);</span> <span class="comment">// As a function object.
</span> <span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">y</span> <span class="special">==</span> <span class="number">3</span> <span class="special">)</span> <span class="special">;</span> <span class="comment">// The default rounding is trunc.
</span>
<span class="keyword">int</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">Double2Int</span><span class="special">()(</span><span class="number">3.14</span><span class="special">);</span> <span class="comment">// As a function object.</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">y</span> <span class="special">==</span> <span class="number">3</span> <span class="special">)</span> <span class="special">;</span> <span class="comment">// The default rounding is trunc.</span>
<span class="keyword">try</span>
<span class="special">{</span>
<span class="keyword">double</span> <span class="identifier">m</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">bounds</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;::</span><span class="identifier">highest</span><span class="special">();</span>
<span class="keyword">int</span> <span class="identifier">z</span> <span class="special">=</span> <span class="identifier">Double2Int</span><span class="special">::</span><span class="identifier">convert</span><span class="special">(</span><span class="identifier">m</span><span class="special">);</span> <span class="comment">// By default throws positive_overflow()
</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">z</span> <span class="special">=</span> <span class="identifier">Double2Int</span><span class="special">::</span><span class="identifier">convert</span><span class="special">(</span><span class="identifier">m</span><span class="special">);</span> <span class="comment">// By default throws positive_overflow()</span>
<span class="special">}</span>
<span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">positive_overflow</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="special">)</span>
<span class="special">{</span>
<span class="special">}</span>
@@ -497,7 +447,8 @@ float_to_float |--&gt; subranged |--&gt; ( s &gt;= S(LowestT) ) &amp;&amp; (
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -505,7 +456,7 @@ float_to_float |--&gt; subranged |--&gt; ( s &gt;= S(LowestT) ) &amp;&amp; (
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="definitions.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="type_requirements_and_user_defined_types_support.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="definitions.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="type_requirements_and_user_defined_types_support.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
+315 -355
View File
@@ -1,33 +1,32 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Definitions</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="prev" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="next" href="converter___function_object.html" title="converter&lt;&gt;
function object">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="next" href="converter___function_object.html" title="converter&lt;&gt; function object">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../index.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="converter___function_object.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="../index.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="converter___function_object.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_numericconversion.definitions"></a><a href="definitions.html" title="Definitions">Definitions</a>
<a name="boost_numericconversion.definitions"></a><a class="link" href="definitions.html" title="Definitions">Definitions</a>
</h2></div></div></div>
<div class="toc"><dl>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="definitions.html#boost_numericconversion.definitions.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="definitions.html#boost_numericconversion.definitions.types_and_values">Types
and Values</a></span></dt>
@@ -44,15 +43,16 @@
<dt><span class="section"><a href="definitions.html#boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype">Subranged
Conversion Direction, Subtype and Supertype</a></span></dt>
</dl></div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.definitions.introduction"></a><a href="definitions.html#boost_numericconversion.definitions.introduction" title="Introduction">Introduction</a>
<a name="boost_numericconversion.definitions.introduction"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
This section provides definitions of terms used in the Numeric Conversion
library.
</p>
<div class="sidebar">
<div class="titlepage"></div>
<p>
<span class="bold"><strong>Notation</strong></span> <span class="underline">underlined
text</span> denotes terms defined in the C++ standard.
@@ -63,21 +63,20 @@
</p>
</div>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.definitions.types_and_values"></a><a href="definitions.html#boost_numericconversion.definitions.types_and_values" title="Types
and Values">Types
<a name="boost_numericconversion.definitions.types_and_values"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.types_and_values" title="Types and Values">Types
and Values</a>
</h3></div></div></div>
<p>
As defined by the <span class="underline">C++ Object Model</span>
(§1.7) the <span class="underline">storage</span> or memory on which
(&#167;1.7) the <span class="underline">storage</span> or memory on which
a C++ program runs is a contiguous sequence of <span class="underline">bytes</span>
where each byte is a contiguous sequence of bits.
</p>
<p>
An <span class="underline">object</span> is a region of storage (§1.8)
and has a type (§3.9).
An <span class="underline">object</span> is a region of storage (&#167;1.8)
and has a type (&#167;3.9).
</p>
<p>
A <span class="underline">type</span> is a discrete set of values.
@@ -85,13 +84,13 @@
<p>
An object of type <code class="computeroutput"><span class="identifier">T</span></code> has an
<span class="underline">object representation</span> which is the
sequence of bytes stored in the object (§3.9/4)
sequence of bytes stored in the object (&#167;3.9/4)
</p>
<p>
An object of type <code class="computeroutput"><span class="identifier">T</span></code> has a
<span class="underline">value representation</span> which is the set
of bits that determine the <span class="emphasis"><em>value</em></span> of an object of that
type (§3.9/4). For <span class="underline">POD</span> types (§3.9/10),
type (&#167;3.9/4). For <span class="underline">POD</span> types (&#167;3.9/10),
this bitset is given by the object representation, but not all the bits in
the storage need to participate in the value representation (except for character
types): for example, some bits might be used for padding or there may be
@@ -161,60 +160,53 @@
of this document.
</p>
</div>
<a name="numeric_conversion_cpp_arithmetic_types"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.definitions.c___arithmetic_types"></a><a href="definitions.html#boost_numericconversion.definitions.c___arithmetic_types" title="C++
Arithmetic Types">C++
<a name="boost_numericconversion.definitions.c___arithmetic_types"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.c___arithmetic_types" title="C++ Arithmetic Types">C++
Arithmetic Types</a>
</h3></div></div></div>
<p>
The C++ language defines <span class="underline">fundamental types</span>
(§3.9.1). The following subsets of the fundamental types are intended to
(&#167;3.9.1). The following subsets of the fundamental types are intended to
represent <span class="emphasis"><em>numbers</em></span>:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term"><span class="underline">signed integer
types</span> (§3.9.1/2):</span></dt>
<dl class="variablelist">
<dt><span class="term"><span class="underline">signed integer types</span> (&#167;3.9.1/2):</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">{</span><span class="keyword">signed</span>
<span class="keyword">char</span><span class="special">,</span>
<span class="keyword">signed</span> <span class="keyword">short</span>
<span class="keyword">int</span><span class="special">,</span>
<span class="keyword">signed</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">signed</span> <span class="keyword">long</span> <span class="keyword">int</span><span class="special">}</span></code> Can be used to represent general integer
numbers (both negative and positive).
</p></dd>
<dt><span class="term"><span class="underline">unsigned integer
types</span> (§3.9.1/3):</span></dt>
<code class="computeroutput"><span class="special">{</span><span class="keyword">signed</span>
<span class="keyword">char</span><span class="special">,</span>
<span class="keyword">signed</span> <span class="keyword">short</span>
<span class="keyword">int</span><span class="special">,</span>
<span class="keyword">signed</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">signed</span> <span class="keyword">long</span> <span class="keyword">int</span><span class="special">}</span></code> Can be used to represent general integer
numbers (both negative and positive).
</p></dd>
<dt><span class="term"><span class="underline">unsigned integer types</span> (&#167;3.9.1/3):</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">{</span><span class="keyword">unsigned</span>
<span class="keyword">char</span><span class="special">,</span>
<span class="keyword">unsigned</span> <span class="keyword">short</span>
<span class="keyword">int</span><span class="special">,</span>
<span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">int</span><span class="special">}</span></code> Can be used to represent positive integer
numbers with modulo-arithmetic.
</p></dd>
<dt><span class="term"><span class="underline">floating-point
types</span> (§3.9.1/8):</span></dt>
<code class="computeroutput"><span class="special">{</span><span class="keyword">unsigned</span>
<span class="keyword">char</span><span class="special">,</span>
<span class="keyword">unsigned</span> <span class="keyword">short</span>
<span class="keyword">int</span><span class="special">,</span>
<span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">unsigned</span>
<span class="keyword">long</span> <span class="keyword">int</span><span class="special">}</span></code> Can be used to represent positive
integer numbers with modulo-arithmetic.
</p></dd>
<dt><span class="term"><span class="underline">floating-point types</span> (&#167;3.9.1/8):</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">{</span><span class="keyword">float</span><span class="special">,</span><span class="keyword">double</span><span class="special">,</span><span class="keyword">long</span> <span class="keyword">double</span><span class="special">}</span></code>
Can be used to represent real numbers.
</p></dd>
<dt><span class="term"><span class="underline">integral or
integer types</span> (§3.9.1/7):</span></dt>
<code class="computeroutput"><span class="special">{</span><span class="keyword">float</span><span class="special">,</span><span class="keyword">double</span><span class="special">,</span><span class="keyword">long</span> <span class="keyword">double</span><span class="special">}</span></code>
Can be used to represent real numbers.
</p></dd>
<dt><span class="term"><span class="underline">integral or integer types</span> (&#167;3.9.1/7):</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">{{</span><span class="keyword">signed</span>
<span class="identifier">integers</span><span class="special">},{</span><span class="keyword">unsigned</span> <span class="identifier">integers</span><span class="special">},</span> <span class="keyword">bool</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">and</span> <span class="keyword">wchar_t</span><span class="special">}</span></code>
</p></dd>
<dt><span class="term"><span class="underline">arithmetic
types</span> (§3.9.1/8):</span></dt>
<code class="computeroutput"><span class="special">{{</span><span class="keyword">signed</span>
<span class="identifier">integers</span><span class="special">},{</span><span class="keyword">unsigned</span> <span class="identifier">integers</span><span class="special">},</span> <span class="keyword">bool</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">and</span> <span class="keyword">wchar_t</span><span class="special">}</span></code>
</p></dd>
<dt><span class="term"><span class="underline">arithmetic types</span> (&#167;3.9.1/8):</span></dt>
<dd><p>
<code class="computeroutput"><span class="special">{{</span><span class="identifier">integer</span>
<span class="identifier">types</span><span class="special">},{</span><span class="identifier">floating</span> <span class="identifier">types</span><span class="special">}}</span></code>
</p></dd>
<code class="computeroutput"><span class="special">{{</span><span class="identifier">integer</span>
<span class="identifier">types</span><span class="special">},{</span><span class="identifier">floating</span> <span class="identifier">types</span><span class="special">}}</span></code>
</p></dd>
</dl>
</div>
<p>
@@ -226,10 +218,9 @@
or <code class="computeroutput"><span class="keyword">long</span></code>) are required to have
the same value representation, that is:
</p>
<pre class="programlisting">
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">-</span><span class="number">3</span> <span class="special">;</span> <span class="comment">// suppose value representation is: 10011 (sign bit + 4 magnitude bits)
</span><span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">u</span> <span class="special">=</span> <span class="identifier">i</span> <span class="special">;</span> <span class="comment">// u is required to have the same 10011 as its value representation.
</span></pre>
<pre class="programlisting"> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">-</span><span class="number">3</span> <span class="special">;</span> <span class="comment">// suppose value representation is: 10011 (sign bit + 4 magnitude bits)</span>
<span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">u</span> <span class="special">=</span> <span class="identifier">i</span> <span class="special">;</span> <span class="comment">// u is required to have the same 10011 as its value representation.</span>
</pre>
<p>
In other words, the integer types signed/unsigned X use the same value representation
but a different <span class="emphasis"><em>interpretation</em></span> of it; that is, their
@@ -237,11 +228,11 @@
</p>
<p>
Another consequence of this is that the range for signed X is always a smaller
subset of the range of unsigned X, as required by §3.9.1/3.
subset of the range of unsigned X, as required by &#167;3.9.1/3.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/html/images/note.png"></td>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
@@ -262,12 +253,9 @@
</td></tr>
</table></div>
</div>
<a name="numeric_conversion_definitions_numeric_types"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.definitions.numeric_types"></a><a href="definitions.html#boost_numericconversion.definitions.numeric_types" title="Numeric
Types">Numeric
<a name="boost_numericconversion.definitions.numeric_types"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.numeric_types" title="Numeric Types">Numeric
Types</a>
</h3></div></div></div>
<p>
@@ -283,30 +271,30 @@
<p>
A type is <span class="bold"><strong>numeric</strong></span> if:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
It is an arithmetic type, or,
</li>
<li>
It is a user-defined type which
<div class="itemizedlist"><ul type="circle">
<li>
Represents numeric abstract values (i.e. numbers).
</li>
<li>
Can be converted (either implicitly or explicitly) to/from at least
one arithmetic type.
</li>
<li>
Has <a href="definitions.html#numeric_conversion_definitions_range">range</a>
(possibly unbounded) and <a href="definitions.html#numeric_conversion_definitions_range">precision</a>
(possibly dynamic or unlimited).
</li>
<li>
Provides an specialization of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
It is an arithmetic type, or,
</li>
<li class="listitem">
It is a user-defined type which
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
Represents numeric abstract values (i.e. numbers).
</li>
<li class="listitem">
Can be converted (either implicitly or explicitly) to/from at least
one arithmetic type.
</li>
<li class="listitem">
Has <a class="link" href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">range</a>
(possibly unbounded) and <a class="link" href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">precision</a>
(possibly dynamic or unlimited).
</li>
<li class="listitem">
Provides an specialization of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>.
</li>
</ul></div>
</li>
</li>
</ul></div>
<p>
A numeric type is <span class="bold"><strong>signed</strong></span> if the abstract
@@ -346,10 +334,9 @@
The following examples clarify the differences between arithmetic and numeric
types (and values):
</p>
<pre class="programlisting">
<span class="comment">// A numeric type which is not an arithmetic type (is user-defined)
</span><span class="comment">// and which is intended to represent integer numbers (i.e., an 'integer' numeric type)
</span><span class="keyword">class</span> <span class="identifier">MyInt</span>
<pre class="programlisting"><span class="comment">// A numeric type which is not an arithmetic type (is user-defined)</span>
<span class="comment">// and which is intended to represent integer numbers (i.e., an 'integer' numeric type)</span>
<span class="keyword">class</span> <span class="identifier">MyInt</span>
<span class="special">{</span>
<span class="identifier">MyInt</span> <span class="special">(</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">v</span> <span class="special">)</span> <span class="special">;</span>
<span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">to_builtin</span><span class="special">();</span>
@@ -358,26 +345,23 @@
<span class="keyword">template</span><span class="special">&lt;&gt;</span> <span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">MyInt</span><span class="special">&gt;</span> <span class="special">{</span> <span class="special">...</span> <span class="special">}</span> <span class="special">;</span>
<span class="special">}</span>
<span class="comment">// A 'floating' numeric type (double) which is also an arithmetic type (built-in),
</span><span class="comment">// with a float numeric value.
</span><span class="keyword">double</span> <span class="identifier">pi</span> <span class="special">=</span> <span class="identifier">M_PI</span> <span class="special">;</span>
<span class="comment">// A 'floating' numeric type (double) which is also an arithmetic type (built-in),</span>
<span class="comment">// with a float numeric value.</span>
<span class="keyword">double</span> <span class="identifier">pi</span> <span class="special">=</span> <span class="identifier">M_PI</span> <span class="special">;</span>
<span class="comment">// A 'floating' numeric type with a whole numeric value.
</span><span class="comment">// NOTE: numeric values are typed valued, hence, they are, for instance,
</span><span class="comment">// integer or floating, despite the value itself being whole or including
</span><span class="comment">// a fractional part.
</span><span class="keyword">double</span> <span class="identifier">two</span> <span class="special">=</span> <span class="number">2.0</span> <span class="special">;</span>
<span class="comment">// A 'floating' numeric type with a whole numeric value.</span>
<span class="comment">// NOTE: numeric values are typed valued, hence, they are, for instance,</span>
<span class="comment">// integer or floating, despite the value itself being whole or including</span>
<span class="comment">// a fractional part.</span>
<span class="keyword">double</span> <span class="identifier">two</span> <span class="special">=</span> <span class="number">2.0</span> <span class="special">;</span>
<span class="comment">// An integer numeric type with an integer numeric value.
</span><span class="identifier">MyInt</span> <span class="identifier">i</span><span class="special">(</span><span class="number">1234</span><span class="special">);</span>
<span class="comment">// An integer numeric type with an integer numeric value.</span>
<span class="identifier">MyInt</span> <span class="identifier">i</span><span class="special">(</span><span class="number">1234</span><span class="special">);</span>
</pre>
</div>
<a name="numeric_conversion_definitions_range"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.definitions.range_and_precision"></a><a href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range
and Precision">Range
<a name="boost_numericconversion.definitions.range_and_precision"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">Range
and Precision</a>
</h3></div></div></div>
<p>
@@ -439,8 +423,7 @@
of numeric values (of type <code class="computeroutput"><span class="identifier">T</span></code>)
of the form:
</p>
<pre class="programlisting">
<span class="identifier">REP</span><span class="special">(</span><span class="identifier">T</span><span class="special">)={</span><span class="identifier">l</span><span class="special">,</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">l</span><span class="special">),</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">l</span><span class="special">)),...,</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">h</span><span class="special">)),</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">h</span><span class="special">),</span><span class="identifier">h</span><span class="special">}</span>
<pre class="programlisting"><span class="identifier">REP</span><span class="special">(</span><span class="identifier">T</span><span class="special">)={</span><span class="identifier">l</span><span class="special">,</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">l</span><span class="special">),</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">l</span><span class="special">)),...,</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">h</span><span class="special">)),</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">h</span><span class="special">),</span><span class="identifier">h</span><span class="special">}</span>
</pre>
<p>
where <code class="computeroutput"><span class="identifier">l</span></code> and <code class="computeroutput"><span class="identifier">h</span></code> are respectively the lowest and highest
@@ -495,15 +478,15 @@
<p>
This definition was chosen because:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
<span class="bold"><strong>(a)</strong></span> The discrete set of numeric values
is already given by the numeric set.
</li>
<li>
<span class="bold"><strong>(b)</strong></span> Abstract intervals are easier to compare
and overlap since only boundary values need to be considered.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<span class="bold"><strong>(a)</strong></span> The discrete set of numeric values
is already given by the numeric set.
</li>
<li class="listitem">
<span class="bold"><strong>(b)</strong></span> Abstract intervals are easier to
compare and overlap since only boundary values need to be considered.
</li>
</ul></div>
<p>
This definition allows for a concise definition of <code class="computeroutput"><span class="identifier">subranged</span></code>
@@ -536,12 +519,9 @@
of mantissa bits, the higher the precision.
</p>
</div>
<a name="numeric_conversion_definitions_roundoff"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations"></a><a href="definitions.html#boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations" title="Exact,
Correctly Rounded and Out-Of-Range Representations">Exact,
<a name="boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations" title="Exact, Correctly Rounded and Out-Of-Range Representations">Exact,
Correctly Rounded and Out-Of-Range Representations</a>
</h3></div></div></div>
<p>
@@ -558,17 +538,17 @@
or, equivalently, it's representation in the type <code class="computeroutput"><span class="identifier">T</span></code>
is <span class="bold"><strong>out of range</strong></span>, or <span class="bold"><strong>overflows</strong></span>.
</p>
<div class="itemizedlist"><ul type="disc">
<li>
If <code class="computeroutput"><span class="identifier">V</span> <span class="special">&lt;</span>
<span class="identifier">abt</span><span class="special">(</span><span class="identifier">l</span><span class="special">)</span></code>, the
<span class="bold"><strong>overflow is negative</strong></span>.
</li>
<li>
If <code class="computeroutput"><span class="identifier">V</span> <span class="special">&gt;</span>
<span class="identifier">abt</span><span class="special">(</span><span class="identifier">h</span><span class="special">)</span></code>, the
<span class="bold"><strong>overflow is positive</strong></span>.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
If <code class="computeroutput"><span class="identifier">V</span> <span class="special">&lt;</span>
<span class="identifier">abt</span><span class="special">(</span><span class="identifier">l</span><span class="special">)</span></code>,
the <span class="bold"><strong>overflow is negative</strong></span>.
</li>
<li class="listitem">
If <code class="computeroutput"><span class="identifier">V</span> <span class="special">&gt;</span>
<span class="identifier">abt</span><span class="special">(</span><span class="identifier">h</span><span class="special">)</span></code>,
the <span class="bold"><strong>overflow is positive</strong></span>.
</li>
</ul></div>
<p>
If <code class="computeroutput"><span class="identifier">V</span> <span class="special">&gt;=</span>
@@ -599,17 +579,17 @@
the roundoff error corresponds to the representation operation and not to
the numeric value itself (i.e. numeric values do not have any error themselves)
</p>
<div class="itemizedlist"><ul type="disc">
<li>
If the roundoff is 0, the representation is <span class="bold"><strong>exact</strong></span>,
and <code class="computeroutput"><span class="identifier">V</span></code> is exactly representable
in the type <code class="computeroutput"><span class="identifier">T</span></code>.
</li>
<li>
If the roundoff is not 0, the representation is <span class="bold"><strong>inexact</strong></span>,
and <code class="computeroutput"><span class="identifier">V</span></code> is inexactly representable
in the type <code class="computeroutput"><span class="identifier">T</span></code>.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
If the roundoff is 0, the representation is <span class="bold"><strong>exact</strong></span>,
and <code class="computeroutput"><span class="identifier">V</span></code> is exactly representable
in the type <code class="computeroutput"><span class="identifier">T</span></code>.
</li>
<li class="listitem">
If the roundoff is not 0, the representation is <span class="bold"><strong>inexact</strong></span>,
and <code class="computeroutput"><span class="identifier">V</span></code> is inexactly representable
in the type <code class="computeroutput"><span class="identifier">T</span></code>.
</li>
</ul></div>
<p>
If a representation <code class="computeroutput"><span class="identifier">v</span></code> in
@@ -639,85 +619,85 @@
<p>
The following examples summarize the given definitions. Consider:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
A numeric type <code class="computeroutput"><span class="identifier">Int</span></code> representing
integer numbers with a <span class="emphasis"><em>numeric set</em></span>: <code class="computeroutput"><span class="special">{-</span><span class="number">2</span><span class="special">,-</span><span class="number">1</span><span class="special">,</span><span class="number">0</span><span class="special">,</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">}</span></code> and <span class="emphasis"><em>range</em></span>:
<code class="computeroutput"><span class="special">[-</span><span class="number">2</span><span class="special">,</span><span class="number">2</span><span class="special">]</span></code>
</li>
<li>
A numeric type <code class="computeroutput"><span class="identifier">Cardinal</span></code>
representing integer numbers with a <span class="emphasis"><em>numeric set</em></span>:
<code class="computeroutput"><span class="special">{</span><span class="number">0</span><span class="special">,</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">,</span><span class="number">4</span><span class="special">,</span><span class="number">5</span><span class="special">,</span><span class="number">6</span><span class="special">,</span><span class="number">7</span><span class="special">,</span><span class="number">8</span><span class="special">,</span><span class="number">9</span><span class="special">}</span></code> and <span class="emphasis"><em>range</em></span>: <code class="computeroutput"><span class="special">[</span><span class="number">0</span><span class="special">,</span><span class="number">9</span><span class="special">]</span></code> (no modulo-arithmetic
here)
</li>
<li>
A numeric type <code class="computeroutput"><span class="identifier">Real</span></code> representing
real numbers with a <span class="emphasis"><em>numeric set</em></span>: <code class="computeroutput"><span class="special">{-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.5</span><span class="special">,-</span><span class="number">1.0</span><span class="special">,-</span><span class="number">0.5</span><span class="special">,-</span><span class="number">0.0</span><span class="special">,+</span><span class="number">0.0</span><span class="special">,+</span><span class="number">0.5</span><span class="special">,+</span><span class="number">1.0</span><span class="special">,+</span><span class="number">1.5</span><span class="special">,+</span><span class="number">2.0</span><span class="special">}</span></code> and
<span class="emphasis"><em>range</em></span>: <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">]</span></code>
</li>
<li>
A numeric type <code class="computeroutput"><span class="identifier">Whole</span></code> representing
real numbers with a <span class="emphasis"><em>numeric set</em></span>: <code class="computeroutput"><span class="special">{-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.0</span><span class="special">,</span><span class="number">0.0</span><span class="special">,+</span><span class="number">1.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">}</span></code> and <span class="emphasis"><em>range</em></span>: <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">]</span></code>
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
A numeric type <code class="computeroutput"><span class="identifier">Int</span></code> representing
integer numbers with a <span class="emphasis"><em>numeric set</em></span>: <code class="computeroutput"><span class="special">{-</span><span class="number">2</span><span class="special">,-</span><span class="number">1</span><span class="special">,</span><span class="number">0</span><span class="special">,</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">}</span></code> and
<span class="emphasis"><em>range</em></span>: <code class="computeroutput"><span class="special">[-</span><span class="number">2</span><span class="special">,</span><span class="number">2</span><span class="special">]</span></code>
</li>
<li class="listitem">
A numeric type <code class="computeroutput"><span class="identifier">Cardinal</span></code>
representing integer numbers with a <span class="emphasis"><em>numeric set</em></span>:
<code class="computeroutput"><span class="special">{</span><span class="number">0</span><span class="special">,</span><span class="number">1</span><span class="special">,</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">,</span><span class="number">4</span><span class="special">,</span><span class="number">5</span><span class="special">,</span><span class="number">6</span><span class="special">,</span><span class="number">7</span><span class="special">,</span><span class="number">8</span><span class="special">,</span><span class="number">9</span><span class="special">}</span></code> and <span class="emphasis"><em>range</em></span>: <code class="computeroutput"><span class="special">[</span><span class="number">0</span><span class="special">,</span><span class="number">9</span><span class="special">]</span></code> (no
modulo-arithmetic here)
</li>
<li class="listitem">
A numeric type <code class="computeroutput"><span class="identifier">Real</span></code> representing
real numbers with a <span class="emphasis"><em>numeric set</em></span>: <code class="computeroutput"><span class="special">{-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.5</span><span class="special">,-</span><span class="number">1.0</span><span class="special">,-</span><span class="number">0.5</span><span class="special">,-</span><span class="number">0.0</span><span class="special">,+</span><span class="number">0.0</span><span class="special">,+</span><span class="number">0.5</span><span class="special">,+</span><span class="number">1.0</span><span class="special">,+</span><span class="number">1.5</span><span class="special">,+</span><span class="number">2.0</span><span class="special">}</span></code> and
<span class="emphasis"><em>range</em></span>: <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">]</span></code>
</li>
<li class="listitem">
A numeric type <code class="computeroutput"><span class="identifier">Whole</span></code>
representing real numbers with a <span class="emphasis"><em>numeric set</em></span>: <code class="computeroutput"><span class="special">{-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.0</span><span class="special">,</span><span class="number">0.0</span><span class="special">,+</span><span class="number">1.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">}</span></code> and
<span class="emphasis"><em>range</em></span>: <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">]</span></code>
</li>
</ul></div>
<p>
First, notice that the types <code class="computeroutput"><span class="identifier">Real</span></code>
and <code class="computeroutput"><span class="identifier">Whole</span></code> both represent
real numbers, have the same range, but different precision.
</p>
<div class="itemizedlist"><ul type="disc">
<li>
The integer number <code class="computeroutput"><span class="number">1</span></code> (an abstract
value) can be exactly represented in any of these types.
</li>
<li>
The integer number <code class="computeroutput"><span class="special">-</span><span class="number">1</span></code>
can be exactly represented in <code class="computeroutput"><span class="identifier">Int</span></code>,
<code class="computeroutput"><span class="identifier">Real</span></code> and <code class="computeroutput"><span class="identifier">Whole</span></code>, but cannot be represented in
<code class="computeroutput"><span class="identifier">Cardinal</span></code>, yielding negative
overflow.
</li>
<li>
The real number <code class="computeroutput"><span class="number">1.5</span></code> can be
exactly represented in <code class="computeroutput"><span class="identifier">Real</span></code>,
and inexactly represented in the other types.
</li>
<li>
If <code class="computeroutput"><span class="number">1.5</span></code> is represented as either
<code class="computeroutput"><span class="number">1</span></code> or <code class="computeroutput"><span class="number">2</span></code>
in any of the types (except <code class="computeroutput"><span class="identifier">Real</span></code>),
the representation is correctly rounded.
</li>
<li>
If <code class="computeroutput"><span class="number">0.5</span></code> is represented as <code class="computeroutput"><span class="special">+</span><span class="number">1.5</span></code> in the
type <code class="computeroutput"><span class="identifier">Real</span></code>, it is incorrectly
rounded.
</li>
<li>
<code class="computeroutput"><span class="special">(-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.5</span><span class="special">)</span></code>
are the <code class="computeroutput"><span class="identifier">Real</span></code> adjacents
of any real number in the interval <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.5</span><span class="special">]</span></code>, yet there are no <code class="computeroutput"><span class="identifier">Real</span></code>
adjacents for <code class="computeroutput"><span class="identifier">x</span> <span class="special">&lt;</span>
<span class="special">-</span><span class="number">2.0</span></code>,
nor for <code class="computeroutput"><span class="identifier">x</span> <span class="special">&gt;</span>
<span class="special">+</span><span class="number">2.0</span></code>.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
The integer number <code class="computeroutput"><span class="number">1</span></code> (an
abstract value) can be exactly represented in any of these types.
</li>
<li class="listitem">
The integer number <code class="computeroutput"><span class="special">-</span><span class="number">1</span></code>
can be exactly represented in <code class="computeroutput"><span class="identifier">Int</span></code>,
<code class="computeroutput"><span class="identifier">Real</span></code> and <code class="computeroutput"><span class="identifier">Whole</span></code>, but cannot be represented in
<code class="computeroutput"><span class="identifier">Cardinal</span></code>, yielding negative
overflow.
</li>
<li class="listitem">
The real number <code class="computeroutput"><span class="number">1.5</span></code> can be
exactly represented in <code class="computeroutput"><span class="identifier">Real</span></code>,
and inexactly represented in the other types.
</li>
<li class="listitem">
If <code class="computeroutput"><span class="number">1.5</span></code> is represented as
either <code class="computeroutput"><span class="number">1</span></code> or <code class="computeroutput"><span class="number">2</span></code> in any of the types (except <code class="computeroutput"><span class="identifier">Real</span></code>), the representation is correctly
rounded.
</li>
<li class="listitem">
If <code class="computeroutput"><span class="number">0.5</span></code> is represented as
<code class="computeroutput"><span class="special">+</span><span class="number">1.5</span></code>
in the type <code class="computeroutput"><span class="identifier">Real</span></code>, it
is incorrectly rounded.
</li>
<li class="listitem">
<code class="computeroutput"><span class="special">(-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.5</span><span class="special">)</span></code>
are the <code class="computeroutput"><span class="identifier">Real</span></code> adjacents
of any real number in the interval <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.5</span><span class="special">]</span></code>, yet there are no <code class="computeroutput"><span class="identifier">Real</span></code>
adjacents for <code class="computeroutput"><span class="identifier">x</span> <span class="special">&lt;</span>
<span class="special">-</span><span class="number">2.0</span></code>,
nor for <code class="computeroutput"><span class="identifier">x</span> <span class="special">&gt;</span>
<span class="special">+</span><span class="number">2.0</span></code>.
</li>
</ul></div>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.definitions.standard__numeric__conversions"></a><a href="definitions.html#boost_numericconversion.definitions.standard__numeric__conversions" title="Standard
(numeric) Conversions">Standard
<a name="boost_numericconversion.definitions.standard__numeric__conversions"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.standard__numeric__conversions" title="Standard (numeric) Conversions">Standard
(numeric) Conversions</a>
</h3></div></div></div>
<p>
The C++ language defines <span class="underline">Standard Conversions</span>
(§4) some of which are conversions between arithmetic types.
(&#167;4) some of which are conversions between arithmetic types.
</p>
<p>
These are <span class="underline">Integral promotions</span> (§4.5),
<span class="underline">Integral conversions</span> (§4.7), <span class="underline">Floating point promotions</span> (§4.6), <span class="underline">Floating point conversions</span> (§4.8) and <span class="underline">Floating-integral conversions</span> (§4.9).
These are <span class="underline">Integral promotions</span> (&#167;4.5),
<span class="underline">Integral conversions</span> (&#167;4.7), <span class="underline">Floating point promotions</span> (&#167;4.6), <span class="underline">Floating point conversions</span> (&#167;4.8) and <span class="underline">Floating-integral conversions</span> (&#167;4.9).
</p>
<p>
In the sequel, integral and floating point promotions are called <span class="bold"><strong>arithmetic promotions</strong></span>, and these plus integral, floating-point
@@ -738,42 +718,38 @@
<p>
Integer to integer conversions are always defined:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
If <code class="computeroutput"><span class="identifier">T</span></code> is unsigned, the abstract
value which is effectively represented is not <code class="computeroutput"><span class="identifier">N</span></code>
but <code class="computeroutput"><span class="identifier">M</span><span class="special">=[</span>
<span class="identifier">N</span> <span class="special">%</span>
<span class="special">(</span> <span class="identifier">abt</span><span class="special">(</span><span class="identifier">h</span><span class="special">)</span>
<span class="special">+</span> <span class="number">1</span> <span class="special">)</span> <span class="special">]</span></code>, where
<code class="computeroutput"><span class="identifier">h</span></code> is the highest unsigned
typed value of type <code class="computeroutput"><span class="identifier">T</span></code>.
</li>
<li>
If <code class="computeroutput"><span class="identifier">T</span></code> is signed and <code class="computeroutput"><span class="identifier">N</span></code> is not directly representable, the
result <code class="computeroutput"><span class="identifier">t</span></code> is <span class="underline">implementation-defined</span>,
which means that the C++ implementation is required to produce a value
<code class="computeroutput"><span class="identifier">t</span></code> even if it is totally
unrelated to <code class="computeroutput"><span class="identifier">s</span></code>.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
If <code class="computeroutput"><span class="identifier">T</span></code> is unsigned, the
abstract value which is effectively represented is not <code class="computeroutput"><span class="identifier">N</span></code> but <code class="computeroutput"><span class="identifier">M</span><span class="special">=[</span> <span class="identifier">N</span> <span class="special">%</span> <span class="special">(</span> <span class="identifier">abt</span><span class="special">(</span><span class="identifier">h</span><span class="special">)</span> <span class="special">+</span> <span class="number">1</span>
<span class="special">)</span> <span class="special">]</span></code>,
where <code class="computeroutput"><span class="identifier">h</span></code> is the highest
unsigned typed value of type <code class="computeroutput"><span class="identifier">T</span></code>.
</li>
<li class="listitem">
If <code class="computeroutput"><span class="identifier">T</span></code> is signed and <code class="computeroutput"><span class="identifier">N</span></code> is not directly representable, the
result <code class="computeroutput"><span class="identifier">t</span></code> is <span class="underline">implementation-defined</span>, which means that
the C++ implementation is required to produce a value <code class="computeroutput"><span class="identifier">t</span></code>
even if it is totally unrelated to <code class="computeroutput"><span class="identifier">s</span></code>.
</li>
</ul></div>
<p>
Floating to Floating conversions are defined only if <code class="computeroutput"><span class="identifier">N</span></code>
is representable; if it is not, the conversion has <span class="underline">undefined
behavior</span>.
</p>
<div class="itemizedlist"><ul type="disc">
<li>
If <code class="computeroutput"><span class="identifier">N</span></code> is exactly representable,
<code class="computeroutput"><span class="identifier">t</span></code> is required to be the
exact representation.
</li>
<li>
If <code class="computeroutput"><span class="identifier">N</span></code> is inexactly representable,
<code class="computeroutput"><span class="identifier">t</span></code> is required to be one
of the two adjacents, with an implementation-defined choice of rounding
direction; that is, the conversion is required to be correctly rounded.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
If <code class="computeroutput"><span class="identifier">N</span></code> is exactly representable,
<code class="computeroutput"><span class="identifier">t</span></code> is required to be the
exact representation.
</li>
<li class="listitem">
If <code class="computeroutput"><span class="identifier">N</span></code> is inexactly representable,
<code class="computeroutput"><span class="identifier">t</span></code> is required to be one
of the two adjacents, with an implementation-defined choice of rounding
direction; that is, the conversion is required to be correctly rounded.
</li>
</ul></div>
<p>
Floating to Integer conversions represent not <code class="computeroutput"><span class="identifier">N</span></code>
@@ -781,35 +757,33 @@
<code class="computeroutput"><span class="identifier">trunc</span><span class="special">()</span></code>
is to truncate: i.e. to remove the fractional part, if any.
</p>
<div class="itemizedlist"><ul type="disc"><li>
If <code class="computeroutput"><span class="identifier">M</span></code> is not representable
in <code class="computeroutput"><span class="identifier">T</span></code>, the conversion has
<span class="underline">undefined behavior</span> (unless <code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="keyword">bool</span></code>,
see §4.12).
</li></ul></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
If <code class="computeroutput"><span class="identifier">M</span></code> is not representable
in <code class="computeroutput"><span class="identifier">T</span></code>, the conversion
has <span class="underline">undefined behavior</span> (unless
<code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="keyword">bool</span></code>,
see &#167;4.12).
</li></ul></div>
<p>
Integer to Floating conversions are always defined.
</p>
<div class="itemizedlist"><ul type="disc">
<li>
If <code class="computeroutput"><span class="identifier">N</span></code> is exactly representable,
<code class="computeroutput"><span class="identifier">t</span></code> is required to be the
exact representation.
</li>
<li>
If <code class="computeroutput"><span class="identifier">N</span></code> is inexactly representable,
<code class="computeroutput"><span class="identifier">t</span></code> is required to be one
of the two adjacents, with an implementation-defined choice of rounding
direction; that is, the conversion is required to be correctly rounded.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
If <code class="computeroutput"><span class="identifier">N</span></code> is exactly representable,
<code class="computeroutput"><span class="identifier">t</span></code> is required to be the
exact representation.
</li>
<li class="listitem">
If <code class="computeroutput"><span class="identifier">N</span></code> is inexactly representable,
<code class="computeroutput"><span class="identifier">t</span></code> is required to be one
of the two adjacents, with an implementation-defined choice of rounding
direction; that is, the conversion is required to be correctly rounded.
</li>
</ul></div>
</div>
<a name="numeric_conversion_definitions_subranged"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype"></a><a href="definitions.html#boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype" title="Subranged
Conversion Direction, Subtype and Supertype">Subranged
<a name="boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype" title="Subranged Conversion Direction, Subtype and Supertype">Subranged
Conversion Direction, Subtype and Supertype</a>
</h3></div></div></div>
<p>
@@ -824,15 +798,13 @@
in which case it is said that <code class="computeroutput"><span class="identifier">X</span></code>
is enclosed by <code class="computeroutput"><span class="identifier">Y</span></code>.
</p>
<div class="blockquote"><blockquote class="blockquote">
<p>
</p>
<p>
<span class="bold"><strong>Formally:</strong></span> <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">S</span><span class="special">)</span></code> is enclosed by <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span></code> iif <code class="computeroutput"><span class="special">(</span><span class="identifier">R</span><span class="special">(</span><span class="identifier">S</span><span class="special">)</span> <span class="identifier">intersection</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">T</span><span class="special">))</span> <span class="special">==</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">S</span><span class="special">)</span></code>.
</p>
<p>
</p>
</blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="bold"><strong>Formally:</strong></span> <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">S</span><span class="special">)</span></code>
is enclosed by <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span></code> iif
<code class="computeroutput"><span class="special">(</span><span class="identifier">R</span><span class="special">(</span><span class="identifier">S</span><span class="special">)</span>
<span class="identifier">intersection</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">T</span><span class="special">))</span>
<span class="special">==</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">S</span><span class="special">)</span></code>.
</p></blockquote></div>
<p>
If the source type range, <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">S</span><span class="special">)</span></code>,
is not enclosed in the target type range, <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span></code>;
@@ -855,50 +827,50 @@
<p>
Given the following numeric types all representing real numbers:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
<code class="computeroutput"><span class="identifier">X</span></code> with numeric set <code class="computeroutput"><span class="special">{-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.0</span><span class="special">,</span><span class="number">0.0</span><span class="special">,+</span><span class="number">1.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">}</span></code> and
range <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">]</span></code>
</li>
<li>
<code class="computeroutput"><span class="identifier">Y</span></code> with numeric set <code class="computeroutput"><span class="special">{-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.5</span><span class="special">,-</span><span class="number">1.0</span><span class="special">,-</span><span class="number">0.5</span><span class="special">,</span><span class="number">0.0</span><span class="special">,+</span><span class="number">0.5</span><span class="special">,+</span><span class="number">1.0</span><span class="special">,+</span><span class="number">1.5</span><span class="special">,+</span><span class="number">2.0</span><span class="special">}</span></code> and range <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">]</span></code>
</li>
<li>
<code class="computeroutput"><span class="identifier">Z</span></code> with numeric set <code class="computeroutput"><span class="special">{-</span><span class="number">1.0</span><span class="special">,</span><span class="number">0.0</span><span class="special">,+</span><span class="number">1.0</span><span class="special">}</span></code> and range <code class="computeroutput"><span class="special">[-</span><span class="number">1.0</span><span class="special">,+</span><span class="number">1.0</span><span class="special">]</span></code>
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<code class="computeroutput"><span class="identifier">X</span></code> with numeric set <code class="computeroutput"><span class="special">{-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.0</span><span class="special">,</span><span class="number">0.0</span><span class="special">,+</span><span class="number">1.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">}</span></code> and
range <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">]</span></code>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">Y</span></code> with numeric set <code class="computeroutput"><span class="special">{-</span><span class="number">2.0</span><span class="special">,-</span><span class="number">1.5</span><span class="special">,-</span><span class="number">1.0</span><span class="special">,-</span><span class="number">0.5</span><span class="special">,</span><span class="number">0.0</span><span class="special">,+</span><span class="number">0.5</span><span class="special">,+</span><span class="number">1.0</span><span class="special">,+</span><span class="number">1.5</span><span class="special">,+</span><span class="number">2.0</span><span class="special">}</span></code> and range <code class="computeroutput"><span class="special">[-</span><span class="number">2.0</span><span class="special">,+</span><span class="number">2.0</span><span class="special">]</span></code>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">Z</span></code> with numeric set <code class="computeroutput"><span class="special">{-</span><span class="number">1.0</span><span class="special">,</span><span class="number">0.0</span><span class="special">,+</span><span class="number">1.0</span><span class="special">}</span></code> and range <code class="computeroutput"><span class="special">[-</span><span class="number">1.0</span><span class="special">,+</span><span class="number">1.0</span><span class="special">]</span></code>
</li>
</ul></div>
<p>
For:
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dl class="variablelist">
<dt><span class="term">(a) X-&gt;Y:</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span> <span class="special">&amp;</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">Y</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span></code>,
then <code class="computeroutput"><span class="identifier">X</span><span class="special">-&gt;</span><span class="identifier">Y</span></code> is not subranged. Thus, all values
of type <code class="computeroutput"><span class="identifier">X</span></code> are representable
in the type <code class="computeroutput"><span class="identifier">Y</span></code>.
</p></dd>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span> <span class="special">&amp;</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">Y</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span></code>,
then <code class="computeroutput"><span class="identifier">X</span><span class="special">-&gt;</span><span class="identifier">Y</span></code> is not subranged. Thus, all values
of type <code class="computeroutput"><span class="identifier">X</span></code> are representable
in the type <code class="computeroutput"><span class="identifier">Y</span></code>.
</p></dd>
<dt><span class="term">(b) Y-&gt;X:</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">Y</span><span class="special">)</span> <span class="special">&amp;</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">Y</span><span class="special">)</span></code>,
then <code class="computeroutput"><span class="identifier">Y</span><span class="special">-&gt;</span><span class="identifier">X</span></code> is not subranged. Thus, all values
of type <code class="computeroutput"><span class="identifier">Y</span></code> are representable
in the type <code class="computeroutput"><span class="identifier">X</span></code>, but in
this case, some values are <span class="emphasis"><em>inexactly</em></span> representable
(all the halves). (note: it is to permit this case that a range is an
interval of abstract values and not an interval of typed values)
</p></dd>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">Y</span><span class="special">)</span> <span class="special">&amp;</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">Y</span><span class="special">)</span></code>,
then <code class="computeroutput"><span class="identifier">Y</span><span class="special">-&gt;</span><span class="identifier">X</span></code> is not subranged. Thus, all values
of type <code class="computeroutput"><span class="identifier">Y</span></code> are representable
in the type <code class="computeroutput"><span class="identifier">X</span></code>, but
in this case, some values are <span class="emphasis"><em>inexactly</em></span> representable
(all the halves). (note: it is to permit this case that a range is
an interval of abstract values and not an interval of typed values)
</p></dd>
<dt><span class="term">(b) X-&gt;Z:</span></dt>
<dd><p>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span> <span class="special">&amp;</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">Z</span><span class="special">)</span> <span class="special">!=</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span></code>,
then <code class="computeroutput"><span class="identifier">X</span><span class="special">-&gt;</span><span class="identifier">Z</span></code> is subranged. Thus, some values of
type <code class="computeroutput"><span class="identifier">X</span></code> are not representable
in the type <code class="computeroutput"><span class="identifier">Z</span></code>, they fall
out of range <code class="computeroutput"><span class="special">(-</span><span class="number">2.0</span>
<span class="keyword">and</span> <span class="special">+</span><span class="number">2.0</span><span class="special">)</span></code>.
</p></dd>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span> <span class="special">&amp;</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">Z</span><span class="special">)</span> <span class="special">!=</span> <span class="identifier">R</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span></code>,
then <code class="computeroutput"><span class="identifier">X</span><span class="special">-&gt;</span><span class="identifier">Z</span></code> is subranged. Thus, some values
of type <code class="computeroutput"><span class="identifier">X</span></code> are not representable
in the type <code class="computeroutput"><span class="identifier">Z</span></code>, they
fall out of range <code class="computeroutput"><span class="special">(-</span><span class="number">2.0</span>
<span class="keyword">and</span> <span class="special">+</span><span class="number">2.0</span><span class="special">)</span></code>.
</p></dd>
</dl>
</div>
<p>
@@ -923,28 +895,22 @@
<p>
For example:
</p>
<div class="blockquote"><blockquote class="blockquote">
<p>
</p>
<p>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="keyword">float</span><span class="special">)=[-</span><span class="identifier">FLT_MAX</span><span class="special">,</span><span class="identifier">FLT_MAX</span><span class="special">]</span></code>
and <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="keyword">double</span><span class="special">)=[-</span><span class="identifier">DBL_MAX</span><span class="special">,</span><span class="identifier">DBL_MAX</span><span class="special">]</span></code>
</p>
<p>
</p>
</blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="keyword">float</span><span class="special">)=[-</span><span class="identifier">FLT_MAX</span><span class="special">,</span><span class="identifier">FLT_MAX</span><span class="special">]</span></code>
and <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="keyword">double</span><span class="special">)=[-</span><span class="identifier">DBL_MAX</span><span class="special">,</span><span class="identifier">DBL_MAX</span><span class="special">]</span></code>
</p></blockquote></div>
<p>
If <code class="computeroutput"><span class="identifier">FLT_MAX</span> <span class="special">&lt;</span>
<span class="identifier">DBL_MAX</span></code>:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
<code class="computeroutput"><span class="keyword">double</span><span class="special">-&gt;</span><span class="keyword">float</span></code> is subranged and <code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="keyword">double</span></code>,
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="keyword">float</span></code>.
</li>
<li>
<code class="computeroutput"><span class="keyword">float</span><span class="special">-&gt;</span><span class="keyword">double</span></code> is not subranged and <code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="keyword">double</span></code>, <code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="keyword">float</span></code>.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<code class="computeroutput"><span class="keyword">double</span><span class="special">-&gt;</span><span class="keyword">float</span></code> is subranged and <code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="keyword">double</span></code>,
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="keyword">float</span></code>.
</li>
<li class="listitem">
<code class="computeroutput"><span class="keyword">float</span><span class="special">-&gt;</span><span class="keyword">double</span></code> is not subranged and <code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="keyword">double</span></code>, <code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="keyword">float</span></code>.
</li>
</ul></div>
<p>
Notice that while <code class="computeroutput"><span class="keyword">double</span><span class="special">-&gt;</span><span class="keyword">float</span></code> is subranged, <code class="computeroutput"><span class="keyword">float</span><span class="special">-&gt;</span><span class="keyword">double</span></code>
@@ -953,31 +919,24 @@
<p>
Now consider:
</p>
<div class="blockquote"><blockquote class="blockquote">
<p>
</p>
<p>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="keyword">int</span><span class="special">)=[</span><span class="identifier">INT_MIN</span><span class="special">,</span><span class="identifier">INT_MAX</span><span class="special">]</span></code>
and <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">)=[</span><span class="number">0</span><span class="special">,</span><span class="identifier">UINT_MAX</span><span class="special">]</span></code>
</p>
<p>
</p>
</blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
<code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="keyword">int</span><span class="special">)=[</span><span class="identifier">INT_MIN</span><span class="special">,</span><span class="identifier">INT_MAX</span><span class="special">]</span></code> and <code class="computeroutput"><span class="identifier">R</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">)=[</span><span class="number">0</span><span class="special">,</span><span class="identifier">UINT_MAX</span><span class="special">]</span></code>
</p></blockquote></div>
<p>
A C++ implementation is required to have <code class="computeroutput"><span class="identifier">UINT_MAX</span>
<span class="special">&gt;</span> <span class="identifier">INT_MAX</span></code>
(§3.9/3), so:
(&#167;3.9/3), so:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
'int-&gt;unsigned' is subranged (negative values fall out of range) and
<code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="keyword">int</span></code>, <code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="keyword">unsigned</span></code>.
</li>
<li>
'unsigned-&gt;int' is <span class="emphasis"><em>also</em></span> subranged (high positive
values fall out of range) and <code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="keyword">unsigned</span></code>,
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="keyword">int</span></code>.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
'int-&gt;unsigned' is subranged (negative values fall out of range) and
<code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="keyword">int</span></code>, <code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="keyword">unsigned</span></code>.
</li>
<li class="listitem">
'unsigned-&gt;int' is <span class="emphasis"><em>also</em></span> subranged (high positive
values fall out of range) and <code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="keyword">unsigned</span></code>,
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="keyword">int</span></code>.
</li>
</ul></div>
<p>
In this case, the conversion is subranged in both directions and the supertype,subtype
@@ -1000,7 +959,8 @@
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -1008,7 +968,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../index.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="converter___function_object.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="../index.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="converter___function_object.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -1,66 +1,63 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Improved
numeric_cast&lt;&gt;</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Improved numeric_cast&lt;&gt;</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="prev" href="numeric_converter_policy_classes.html" title="Numeric
Converter Policy Classes">
<link rel="next" href="../numeric_conversion/history_and_acknowledgments.html" title="History
and Acknowledgments">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="numeric_converter_policy_classes.html" title="Numeric Converter Policy Classes">
<link rel="next" href="../numeric_conversion/history_and_acknowledgments.html" title="History and Acknowledgments">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="numeric_converter_policy_classes.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../numeric_conversion/history_and_acknowledgments.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="numeric_converter_policy_classes.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../numeric_conversion/history_and_acknowledgments.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_numericconversion.improved_numeric_cast__"></a><a href="improved_numeric_cast__.html" title="Improved
numeric_cast&lt;&gt;">Improved
<a name="boost_numericconversion.improved_numeric_cast__"></a><a class="link" href="improved_numeric_cast__.html" title="Improved numeric_cast&lt;&gt;">Improved
numeric_cast&lt;&gt;</a>
</h2></div></div></div>
<div class="toc"><dl>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast">numeric_cast</a></span></dt>
<dt><span class="section"><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast_traits">numeric_cast_traits</a></span></dt>
<dt><span class="section"><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.examples">Examples</a></span></dt>
</dl></div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.improved_numeric_cast__.introduction"></a><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.introduction" title="Introduction">Introduction</a>
<a name="boost_numericconversion.improved_numeric_cast__.introduction"></a><a class="link" href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
The lack of preservation of range makes conversions between numeric types
error prone. This is true for both implicit conversions and explicit conversions
(through <code class="computeroutput"><span class="keyword">static_cast</span></code>). <a href="improved_numeric_cast__.html#numeric_conversion_numeric_cast"><code class="computeroutput"><span class="identifier">numeric_cast</span></code></a>
detects loss of range when a numeric type is converted, and throws an exception
if the range cannot be preserved.
(through <code class="computeroutput"><span class="keyword">static_cast</span></code>). <a class="link" href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast" title="numeric_cast"><code class="computeroutput"><span class="identifier">numeric_cast</span></code></a> detects loss of range
when a numeric type is converted, and throws an exception if the range cannot
be preserved.
</p>
<p>
There are several situations where conversions are unsafe:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
Conversions from an integral type with a wider range than the target integral
type.
</li>
<li>
Conversions from unsigned to signed (and vice versa) integral types.
</li>
<li>
Conversions from floating point types to integral types.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Conversions from an integral type with a wider range than the target
integral type.
</li>
<li class="listitem">
Conversions from unsigned to signed (and vice versa) integral types.
</li>
<li class="listitem">
Conversions from floating point types to integral types.
</li>
</ul></div>
<p>
The C++ Standard does not specify the behavior when a numeric type is assigned
@@ -73,53 +70,79 @@
exposed to portability issues.
</p>
<p>
<code class="computeroutput"><span class="identifier">numeric_cast</span></code> adheres to the
rules for implicit conversions mandated by the C++ Standard, such as truncating
floating point types when converting to integral types. The implementation
must guarantee that for a conversion to a type that can hold all possible
values of the source type, there will be no runtime overhead.
By default <code class="computeroutput"><span class="identifier">numeric_cast</span></code> adheres
to the rules for implicit conversions mandated by the C++ Standard, such
as truncating floating point types when converting to integral types. The
implementation must guarantee that for a conversion to a type that can hold
all possible values of the source type, there will be no runtime overhead.
</p>
</div>
<a name="numeric_conversion_numeric_cast"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.improved_numeric_cast__.numeric_cast"></a><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast" title="numeric_cast">numeric_cast</a>
<a name="boost_numericconversion.improved_numeric_cast__.numeric_cast"></a><a class="link" href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast" title="numeric_cast">numeric_cast</a>
</h3></div></div></div>
<pre class="programlisting">
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Target</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Source</span><span class="special">&gt;</span> <span class="keyword">inline</span>
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">converter</span><span class="special">&lt;</span><span class="identifier">Target</span><span class="special">,</span><span class="identifier">Source</span><span class="special">&gt;::</span><span class="identifier">result_type</span>
<span class="identifier">numeric_cast</span> <span class="special">(</span> <span class="identifier">Source</span> <span class="identifier">arg</span> <span class="special">)</span>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Target</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Source</span><span class="special">&gt;</span> <span class="keyword">inline</span>
<span class="identifier">Target</span> <span class="identifier">numeric_cast</span><span class="special">(</span> <span class="identifier">Source</span> <span class="identifier">arg</span> <span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">converter</span><span class="special">&lt;</span><span class="identifier">Target</span><span class="special">,</span><span class="identifier">Source</span><span class="special">&gt;::</span><span class="identifier">convert</span><span class="special">(</span><span class="identifier">arg</span><span class="special">);</span>
<span class="keyword">typedef</span> <span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="identifier">Target</span><span class="special">,</span> <span class="identifier">Source</span><span class="special">&gt;</span> <span class="identifier">conv_traits</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">numeric_cast_traits</span><span class="special">&lt;</span><span class="identifier">Target</span><span class="special">,</span> <span class="identifier">Source</span><span class="special">&gt;</span> <span class="identifier">cast_traits</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">converter</span>
<span class="special">&lt;</span>
<span class="identifier">Target</span><span class="special">,</span>
<span class="identifier">Source</span><span class="special">,</span>
<span class="identifier">conv_traits</span><span class="special">,</span>
<span class="keyword">typename</span> <span class="identifier">cast_traits</span><span class="special">::</span><span class="identifier">overflow_policy</span><span class="special">,</span>
<span class="keyword">typename</span> <span class="identifier">cast_traits</span><span class="special">::</span><span class="identifier">rounding_policy</span><span class="special">,</span>
<span class="identifier">raw_converter</span><span class="special">&lt;</span><span class="identifier">conv_traits</span><span class="special">&gt;,</span>
<span class="keyword">typename</span> <span class="identifier">cast_traits</span><span class="special">::</span><span class="identifier">range_checking_policy</span>
<span class="special">&gt;</span> <span class="identifier">converter</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">converter</span><span class="special">::</span><span class="identifier">convert</span><span class="special">(</span><span class="identifier">arg</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
<code class="computeroutput"><span class="identifier">numeric_cast</span></code> returns the
result of converting a value of type Source to a value of type Target. If
out-of-range is detected, an exception is thrown (see <a href="numeric_converter_policy_classes.html#numeric_conversion_bad_numeric_cast">bad_numeric_cast</a>,
<a href="numeric_converter_policy_classes.html#numeric_conversion_negative_overflow">negative_overflow</a>
and <a href="numeric_converter_policy_classes.html#numeric_conversion_possitive_overflow">positive_overflow</a>
out-of-range is detected, an overflow policy is executed whose default behavior
is to throw an an exception (see <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_bad_numeric_cast">bad_numeric_cast</a>,
<a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_negative_overflow">negative_overflow</a>
and <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_possitive_overflow">positive_overflow</a>
).
</p>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.improved_numeric_cast__.examples"></a><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.examples" title="Examples">Examples</a>
<a name="boost_numericconversion.improved_numeric_cast__.numeric_cast_traits"></a><a class="link" href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast_traits" title="numeric_cast_traits">numeric_cast_traits</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Target</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Source</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">EnableIf</span> <span class="special">=</span> <span class="keyword">void</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">numeric_cast_traits</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">def_overflow_handler</span> <span class="identifier">overflow_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">UseInternalRangeChecker</span> <span class="identifier">range_checking_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">Trunc</span><span class="special">&lt;</span><span class="identifier">Source</span><span class="special">&gt;</span> <span class="identifier">rounding_policy</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
The behavior of <code class="computeroutput"><span class="identifier">numeric_cast</span></code>
may be tailored for custom numeric types through the specialization of <code class="computeroutput"><span class="identifier">numeric_cast_traits</span></code>. (see <a class="link" href="type_requirements_and_user_defined_types_support.html" title="Type Requirements and User-defined-types support">User
Defined Types</a> for details. )
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.improved_numeric_cast__.examples"></a><a class="link" href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
The following example performs some typical conversions between numeric types:
</p>
<div class="orderedlist"><ol type="1">
<li>
include &lt;boost/numeric/conversion/cast.hpp&gt;
</li>
<li>
include &lt;iostream&gt;
</li>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
include &lt;boost/numeric/conversion/cast.hpp&gt;
</li>
<li class="listitem">
include &lt;iostream&gt;
</li>
</ol></div>
<pre class="programlisting">
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric_cast</span><span class="special">;</span>
@@ -130,8 +153,8 @@
<span class="keyword">try</span>
<span class="special">{</span>
<span class="keyword">int</span> <span class="identifier">i</span><span class="special">=</span><span class="number">42</span><span class="special">;</span>
<span class="keyword">short</span> <span class="identifier">s</span><span class="special">=</span><span class="identifier">numeric_cast</span><span class="special">&lt;</span><span class="keyword">short</span><span class="special">&gt;(</span><span class="identifier">i</span><span class="special">);</span> <span class="comment">// This conversion succeeds (is in range)
</span> <span class="special">}</span>
<span class="keyword">short</span> <span class="identifier">s</span><span class="special">=</span><span class="identifier">numeric_cast</span><span class="special">&lt;</span><span class="keyword">short</span><span class="special">&gt;(</span><span class="identifier">i</span><span class="special">);</span> <span class="comment">// This conversion succeeds (is in range)</span>
<span class="special">}</span>
<span class="keyword">catch</span><span class="special">(</span><span class="identifier">negative_overflow</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">();</span>
<span class="special">}</span>
@@ -143,23 +166,23 @@
<span class="special">{</span>
<span class="keyword">float</span> <span class="identifier">f</span><span class="special">=-</span><span class="number">42.1234</span><span class="special">;</span>
<span class="comment">// This will cause a boost::numeric::negative_overflow exception to be thrown
</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">=</span><span class="identifier">numeric_cast</span><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">f</span><span class="special">);</span>
<span class="comment">// This will cause a boost::numeric::negative_overflow exception to be thrown</span>
<span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">=</span><span class="identifier">numeric_cast</span><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">f</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">catch</span><span class="special">(</span><span class="identifier">bad_numeric_cast</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">();</span>
<span class="special">}</span>
<span class="keyword">double</span> <span class="identifier">d</span><span class="special">=</span> <span class="identifier">f</span> <span class="special">+</span> <span class="identifier">numeric_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="number">123</span><span class="special">);</span> <span class="comment">// int -&gt; double
</span>
<span class="keyword">double</span> <span class="identifier">d</span><span class="special">=</span> <span class="identifier">f</span> <span class="special">+</span> <span class="identifier">numeric_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="number">123</span><span class="special">);</span> <span class="comment">// int -&gt; double</span>
<span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="identifier">l</span><span class="special">=</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">long</span><span class="special">&gt;::</span><span class="identifier">max</span><span class="special">();</span>
<span class="keyword">try</span>
<span class="special">{</span>
<span class="comment">// This will cause a boost::numeric::positive_overflow exception to be thrown
</span> <span class="comment">// NOTE: *operations* on unsigned integral types cannot cause overflow
</span> <span class="comment">// but *conversions* to a signed type ARE range checked by numeric_cast.
</span>
<span class="comment">// This will cause a boost::numeric::positive_overflow exception to be thrown</span>
<span class="comment">// NOTE: *operations* on unsigned integral types cannot cause overflow</span>
<span class="comment">// but *conversions* to a signed type ARE range checked by numeric_cast.</span>
<span class="keyword">unsigned</span> <span class="keyword">char</span> <span class="identifier">c</span><span class="special">=</span><span class="identifier">numeric_cast</span><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;(</span><span class="identifier">l</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">catch</span><span class="special">(</span><span class="identifier">positive_overflow</span><span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">{</span>
@@ -174,7 +197,8 @@
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -182,7 +206,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="numeric_converter_policy_classes.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../numeric_conversion/history_and_acknowledgments.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="numeric_converter_policy_classes.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../numeric_conversion/history_and_acknowledgments.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -1,37 +1,33 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Numeric
Converter Policy Classes</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Numeric Converter Policy Classes</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="prev" href="conversion_traits___traits_class.html" title="conversion_traits&lt;&gt;
traits class">
<link rel="next" href="improved_numeric_cast__.html" title="Improved
numeric_cast&lt;&gt;">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="conversion_traits___traits_class.html" title="conversion_traits&lt;&gt; traits class">
<link rel="next" href="improved_numeric_cast__.html" title="Improved numeric_cast&lt;&gt;">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="conversion_traits___traits_class.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="improved_numeric_cast__.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="conversion_traits___traits_class.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="improved_numeric_cast__.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_numericconversion.numeric_converter_policy_classes"></a><a href="numeric_converter_policy_classes.html" title="Numeric
Converter Policy Classes">Numeric
<a name="boost_numericconversion.numeric_converter_policy_classes"></a><a class="link" href="numeric_converter_policy_classes.html" title="Numeric Converter Policy Classes">Numeric
Converter Policy Classes</a>
</h2></div></div></div>
<div class="toc"><dl>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result">enum
range_check_result</a></span></dt>
<dt><span class="section"><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler">Policy
@@ -43,16 +39,12 @@
<dt><span class="section"><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker">Policy
UserRangeChecker</a></span></dt>
</dl></div>
<a name="numeric_conversion_converter_policies_range_check_result"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result" title="enum
range_check_result">enum
<a name="boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result"></a><a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result" title="enum range_check_result">enum
range_check_result</a>
</h3></div></div></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">enum</span> <span class="identifier">range_check_result</span>
<span class="special">{</span>
@@ -67,12 +59,9 @@
Defines the values returned by <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">converter</span><span class="special">&lt;&gt;::</span><span class="identifier">out_of_range</span><span class="special">()</span></code>
</p>
</div>
<a name="numeric_conversion_policy_overflow_handler"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler" title="Policy
OverflowHandler">Policy
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler"></a><a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler" title="Policy OverflowHandler">Policy
OverflowHandler</a>
</h3></div></div></div>
<p>
@@ -85,11 +74,10 @@
<p>
It must have the following interface (it does not has to be a template class):
</p>
<pre class="programlisting">
<span class="keyword">struct</span> <span class="identifier">YourOverflowHandlerPolicy</span>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">YourOverflowHandlerPolicy</span>
<span class="special">{</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">range_check_result</span> <span class="special">)</span> <span class="special">;</span> <span class="comment">// throw bad_cast or derived
</span><span class="special">}</span> <span class="special">;</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">range_check_result</span> <span class="special">)</span> <span class="special">;</span> <span class="comment">// throw bad_cast or derived</span>
<span class="special">}</span> <span class="special">;</span>
</pre>
<p>
It is called with the result of the converter's <code class="computeroutput"><span class="identifier">out_of_range</span><span class="special">()</span></code> inside <code class="computeroutput"><span class="identifier">validate_range</span><span class="special">()</span></code>.
@@ -97,13 +85,12 @@
<p>
These are the two overflow handler classes provided by the library:
</p>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">struct</span> <span class="identifier">def_overflow_handler</span>
<span class="special">{</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">range_check_result</span> <span class="identifier">r</span> <span class="special">)</span> <span class="comment">// throw bad_numeric_conversion derived
</span> <span class="special">{</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">range_check_result</span> <span class="identifier">r</span> <span class="special">)</span> <span class="comment">// throw bad_numeric_conversion derived</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(</span> <span class="identifier">r</span> <span class="special">==</span> <span class="identifier">cNegOverflow</span> <span class="special">)</span>
<span class="keyword">throw</span> <span class="identifier">negative_overflow</span><span class="special">()</span> <span class="special">;</span>
<span class="keyword">else</span> <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">r</span> <span class="special">==</span> <span class="identifier">cPosOverflow</span> <span class="special">)</span>
@@ -113,47 +100,46 @@
<span class="keyword">struct</span> <span class="identifier">silent_overflow_handler</span>
<span class="special">{</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">range_check_result</span> <span class="special">)</span> <span class="comment">// no-throw
</span> <span class="special">{}</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">range_check_result</span> <span class="special">)</span> <span class="comment">// no-throw</span>
<span class="special">{}</span>
<span class="special">}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span>
</pre>
<p>
And these are the Exception Classes thrown by the default overflow handler
<a href="numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler_important_note">(see
<a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler_important_note">(see
IMPORTANT note)</a>
</p>
<a name="numeric_conversion_bad_numeric_cast"></a><a name="numeric_conversion_negative_overflow"></a><a name="numeric_conversion_possitive_overflow"></a><pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<a name="numeric_conversion_bad_numeric_cast"></a>
<span class="keyword">class</span> <span class="identifier">bad_numeric_cast</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_cast</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">what</span><span class="special">()</span> <span class="keyword">const</span> <span class="comment">// throw()
</span> <span class="special">{</span>
<span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">what</span><span class="special">()</span> <span class="keyword">const</span> <span class="comment">// throw()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="string">"bad numeric conversion: overflow"</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">};</span>
<a name="numeric_conversion_negative_overflow"></a>
<span class="keyword">class</span> <span class="identifier">negative_overflow</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">bad_numeric_cast</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">what</span><span class="special">()</span> <span class="keyword">const</span> <span class="comment">// throw()
</span> <span class="special">{</span>
<span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">what</span><span class="special">()</span> <span class="keyword">const</span> <span class="comment">// throw()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="string">"bad numeric conversion: negative overflow"</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">};</span>
<a name="numeric_conversion_possitive_overflow"></a>
<span class="keyword">class</span> <span class="identifier">positive_overflow</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">bad_numeric_cast</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">what</span><span class="special">()</span> <span class="keyword">const</span> <span class="comment">// throw()
</span> <span class="special">{</span>
<span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">what</span><span class="special">()</span> <span class="keyword">const</span> <span class="comment">// throw()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="string">"bad numeric conversion: positive overflow"</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">};</span>
@@ -161,11 +147,9 @@
<span class="special">}</span> <span class="special">}</span>
</pre>
<a name="numeric_conversion_policy_overflow_handler_important_note"></a><p>
</p>
<div class="important"><table border="0" summary="Important">
<a name="numeric_conversion_policy_overflow_handler_important_note"></a><div class="important"><table border="0" summary="Important">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../../doc/html/images/important.png"></td>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../../doc/src/images/important.png"></td>
<th align="left">Important</th>
</tr>
<tr><td align="left" valign="top"><p>
@@ -183,12 +167,9 @@
</p></td></tr>
</table></div>
</div>
<a name="numeric_conversion_policy_float_to_int_rounder"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder" title="Policy
Float2IntRounder">Policy
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder"></a><a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder" title="Policy Float2IntRounder">Policy
Float2IntRounder</a>
</h3></div></div></div>
<p>
@@ -201,8 +182,7 @@
<p>
The policy must have the following interface:
</p>
<pre class="programlisting">
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">YourFloat2IntRounderPolicy</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">S</span> <span class="identifier">source_type</span> <span class="special">;</span>
@@ -220,7 +200,7 @@
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/html/images/note.png"></td>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
@@ -229,8 +209,7 @@
objects.
</p></td></tr>
</table></div>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
@@ -284,11 +263,11 @@
<span class="keyword">typedef</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">float_round_style</span><span class="special">,</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">round_toward_neg_infinity</span><span class="special">&gt;</span> <span class="identifier">round_style</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, namespace boost
</span></pre>
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder.math_functions_used_by_the_rounder_policies"></a><h5>
<a name="id2634042"></a>
<a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder.math_functions_used_by_the_rounder_policies">Math
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, namespace boost</span>
</pre>
<h5>
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder.h0"></a>
<span class="phrase"><a name="boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder.math_functions_used_by_the_rounder_policies"></a></span><a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder.math_functions_used_by_the_rounder_policies">Math
Functions used by the rounder policies</a>
</h5>
<p>
@@ -306,16 +285,13 @@
This technique allows the default rounder policies to be used directly with
user defined types. The user only requires that suitable overloads of <code class="computeroutput"><span class="identifier">floor</span><span class="special">()</span></code>
and <code class="computeroutput"><span class="identifier">ceil</span><span class="special">()</span></code>
be visible. See also <a href="../index.html#numeric_conversion_requirements">User
be visible. See also <a class="link" href="type_requirements_and_user_defined_types_support.html" title="Type Requirements and User-defined-types support">User
Defined Numeric Types</a> support.
</p>
</div>
<a name="numeric_conversion_policy_raw_converter"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter" title="Policy
RawConverter">Policy
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter"></a><a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter" title="Policy RawConverter">Policy
RawConverter</a>
</h3></div></div></div>
<p>
@@ -327,8 +303,7 @@
<p>
The policy must have the following interface:
</p>
<pre class="programlisting">
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Traits</span><span class="special">&gt;</span>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Traits</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">YourRawConverterPolicy</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">::</span><span class="identifier">result_type</span> <span class="identifier">result_type</span> <span class="special">;</span>
@@ -345,8 +320,7 @@
<p>
This is the only raw converter policy class provided by the library:
</p>
<pre class="programlisting">
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Traits</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">raw_numeric_converter</span>
@@ -356,19 +330,16 @@
<span class="keyword">static</span> <span class="identifier">result_type</span> <span class="identifier">low_level_convert</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="identifier">result_type</span><span class="special">&gt;(</span><span class="identifier">s</span><span class="special">)</span> <span class="special">;</span>
<span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="identifier">result_type</span><span class="special">&gt;(</span><span class="identifier">s</span><span class="special">)</span> <span class="special">;</span>
<span class="special">}</span>
<span class="special">}</span> <span class="special">;</span>
<span class="special">}</span> <span class="special">}</span>
</pre>
</div>
<a name="numeric_conversion_policy_user_range_checker"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker" title="Policy
UserRangeChecker">Policy
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker"></a><a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker" title="Policy UserRangeChecker">Policy
UserRangeChecker</a>
</h3></div></div></div>
<p>
@@ -382,18 +353,17 @@
<p>
The policy must have the following interface:
</p>
<pre class="programlisting">
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Traits</span><span class="special">&gt;</span>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Traits</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">YourRangeCheckerPolicy</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">::</span><span class="identifier">argument_type</span> <span class="identifier">argument_type</span> <span class="special">;</span>
<span class="comment">// Determines if the value 's' fits in the range of the Target type.
</span> <span class="keyword">static</span> <span class="identifier">range_check_result</span> <span class="identifier">out_of_range</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span> <span class="special">;</span>
<span class="comment">// Determines if the value 's' fits in the range of the Target type.</span>
<span class="keyword">static</span> <span class="identifier">range_check_result</span> <span class="identifier">out_of_range</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span> <span class="special">;</span>
<span class="comment">// Checks whether the value 's' is out_of_range()
</span> <span class="comment">// and passes the result of the check to the OverflowHandler policy.
</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">validate_range</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<span class="comment">// Checks whether the value 's' is out_of_range()</span>
<span class="comment">// and passes the result of the check to the OverflowHandler policy.</span>
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">validate_range</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">OverflowHandler</span><span class="special">()(</span> <span class="identifier">out_of_range</span><span class="special">(</span><span class="identifier">s</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
<span class="special">}</span>
@@ -410,7 +380,8 @@
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -418,7 +389,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="conversion_traits___traits_class.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="improved_numeric_cast__.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="conversion_traits___traits_class.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="improved_numeric_cast__.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
@@ -1,48 +1,45 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Type
Requirements and User-defined-types support</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Type Requirements and User-defined-types support</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="prev" href="converter___function_object.html" title="converter&lt;&gt;
function object">
<link rel="next" href="bounds___traits_class.html" title="bounds&lt;&gt;
traits class">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="converter___function_object.html" title="converter&lt;&gt; function object">
<link rel="next" href="bounds___traits_class.html" title="bounds&lt;&gt; traits class">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="converter___function_object.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="bounds___traits_class.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="converter___function_object.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bounds___traits_class.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support"></a><a href="type_requirements_and_user_defined_types_support.html" title="Type
Requirements and User-defined-types support">Type
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support"></a><a class="link" href="type_requirements_and_user_defined_types_support.html" title="Type Requirements and User-defined-types support">Type
Requirements and User-defined-types support</a>
</h2></div></div></div>
<div class="toc"><dl>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.type_requirements">Type
Requirements</a></span></dt>
<dt><span class="section"><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics">UDT's
special semantics</a></span></dt>
<dt><span class="section"><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies">Special
Policies</a></span></dt>
<dt><span class="section"><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udts_with_numeric_cast">UDTs
with numeric_cast</a></span></dt>
</dl></div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.type_requirements"></a><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.type_requirements" title="Type
Requirements">Type
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.type_requirements"></a><a class="link" href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.type_requirements" title="Type Requirements">Type
Requirements</a>
</h3></div></div></div>
<p>
@@ -60,8 +57,7 @@
policies uses unqualified calls to functions <code class="computeroutput"><span class="identifier">floor</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">ceil</span><span class="special">()</span></code>; but the standard functions are introduced
in scope by a using directive:
</p>
<pre class="programlisting">
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">floor</span> <span class="special">;</span> <span class="keyword">return</span> <span class="identifier">floor</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">floor</span> <span class="special">;</span> <span class="keyword">return</span> <span class="identifier">floor</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span>
</pre>
<p>
Therefore, for builtin arithmetic types, the std functions will be used.
@@ -79,59 +75,79 @@
user defined types require a visible <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;</span></code> in order to use the <code class="computeroutput"><span class="identifier">Trunc</span><span class="special">&lt;&gt;</span></code> policy (the default).
</p>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics"></a><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics" title="UDT's
special semantics">UDT's
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics"></a><a class="link" href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics" title="UDT's special semantics">UDT's
special semantics</a>
</h3></div></div></div>
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.conversion_traits"></a><h5>
<a name="id2625386"></a>
<a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.conversion_traits">Conversion
<h5>
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.h0"></a>
<span class="phrase"><a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.conversion_traits"></a></span><a class="link" href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.conversion_traits">Conversion
Traits</a>
</h5>
<p>
If a User Defined Type is involved in a conversion, it is <span class="emphasis"><em>assumed</em></span>
that the UDT has <a href="definitions.html#numeric_conversion_definitions_range">wider
that the UDT has <a class="link" href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">wider
range</a> than any built-in type, and consequently the values of some
<code class="computeroutput"><span class="identifier">converter_traits</span><span class="special">&lt;&gt;</span></code>
members are hardwired regardless of the reality. The following table summarizes
this:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
<code class="computeroutput"><span class="identifier">Target</span><span class="special">=</span></code><span class="emphasis"><em>UDT</em></span>
and <code class="computeroutput"><span class="identifier">Source</span><span class="special">=</span></code><span class="emphasis"><em>built-in</em></span><div class="itemizedlist"><ul type="circle">
<li><code class="computeroutput"><span class="identifier">subranged</span><span class="special">=</span><span class="keyword">false</span></code></li>
<li><code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Target</span></code></li>
<li><code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Source</span></code></li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<code class="computeroutput"><span class="identifier">Target</span><span class="special">=</span></code><span class="emphasis"><em>UDT</em></span>
and <code class="computeroutput"><span class="identifier">Source</span><span class="special">=</span></code><span class="emphasis"><em>built-in</em></span>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<code class="computeroutput"><span class="identifier">subranged</span><span class="special">=</span><span class="keyword">false</span></code>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Target</span></code>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Source</span></code>
</li>
</ul></div>
</li>
<li>
<code class="computeroutput"><span class="identifier">Target</span><span class="special">=</span></code><span class="emphasis"><em>built-in</em></span>
and <code class="computeroutput"><span class="identifier">Source</span><span class="special">=</span></code><span class="emphasis"><em>UDT</em></span><div class="itemizedlist"><ul type="circle">
<li><code class="computeroutput"><span class="identifier">subranged</span><span class="special">=</span><span class="keyword">true</span></code></li>
<li><code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Source</span></code></li>
<li><code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Target</span></code></li>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">Target</span><span class="special">=</span></code><span class="emphasis"><em>built-in</em></span>
and <code class="computeroutput"><span class="identifier">Source</span><span class="special">=</span></code><span class="emphasis"><em>UDT</em></span>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<code class="computeroutput"><span class="identifier">subranged</span><span class="special">=</span><span class="keyword">true</span></code>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Source</span></code>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Target</span></code>
</li>
</ul></div>
</li>
<li>
<code class="computeroutput"><span class="identifier">Target</span><span class="special">=</span></code><span class="emphasis"><em>UDT</em></span>
and <code class="computeroutput"><span class="identifier">Source</span><span class="special">=</span></code><span class="emphasis"><em>UDT</em></span><div class="itemizedlist"><ul type="circle">
<li><code class="computeroutput"><span class="identifier">subranged</span><span class="special">=</span><span class="keyword">false</span></code></li>
<li><code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Target</span></code></li>
<li><code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Source</span></code></li>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">Target</span><span class="special">=</span></code><span class="emphasis"><em>UDT</em></span>
and <code class="computeroutput"><span class="identifier">Source</span><span class="special">=</span></code><span class="emphasis"><em>UDT</em></span>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<code class="computeroutput"><span class="identifier">subranged</span><span class="special">=</span><span class="keyword">false</span></code>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Target</span></code>
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Source</span></code>
</li>
</ul></div>
</li>
</li>
</ul></div>
<p>
The <code class="computeroutput"><span class="identifier">Traits</span></code> member <code class="computeroutput"><span class="identifier">udt_mixture</span></code> can be used to detect whether
a UDT is involved and to infer the validity of the other members as shown
above.
</p>
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.range_checking"></a><h5>
<a name="id2625806"></a>
<a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.range_checking">Range
<h5>
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.h1"></a>
<span class="phrase"><a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.range_checking"></a></span><a class="link" href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.range_checking">Range
Checking</a>
</h5>
<p>
@@ -141,16 +157,13 @@
Target or Source are not built-in types, the bundled range checking of the
<code class="computeroutput"><span class="identifier">converter</span><span class="special">&lt;&gt;</span></code>
function object is automatically disabled. However, it is possible to supply
a user-defined range-checker. See <a href="type_requirements_and_user_defined_types_support.html#numeric_conversion_requirements_hooks">Special
a user-defined range-checker. See <a class="link" href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies" title="Special Policies">Special
Policies</a>
</p>
</div>
<a name="numeric_conversion_requirements_hooks"></a><p>
</p>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies"></a><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies" title="Special
Policies">Special
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies"></a><a class="link" href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies" title="Special Policies">Special
Policies</a>
</h3></div></div></div>
<p>
@@ -166,8 +179,8 @@
<p>
However, this internal logic is disabled when either type is User Defined.
In this case, the user can specify an <span class="emphasis"><em>external</em></span> range
checking policy which will be used in place of the internal code. See <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
policy for details.
checking policy which will be used in place of the internal code. See <a class="link" href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udts_with_numeric_cast" title="UDTs with numeric_cast">numeric_cast_traits</a>
for details on using UDTs with <code class="computeroutput"><span class="identifier">numeric_cast</span></code>.
</p>
<p>
The converter class performs the actual conversion using a Raw Converter
@@ -176,14 +189,358 @@
<p>
However, if the a UDT is involved, the <code class="computeroutput"><span class="keyword">static_cast</span></code>
might not work. In this case, the user can implement and pass a different
raw converter policy. See <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_raw_converter">RawConverter</a>
policy for details
raw converter policy. See <a class="link" href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter" title="Policy RawConverter">RawConverter</a>
policy for details.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udts_with_numeric_cast"></a><a class="link" href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udts_with_numeric_cast" title="UDTs with numeric_cast">UDTs
with numeric_cast</a>
</h3></div></div></div>
<p>
In order to employ UDTs with <code class="computeroutput"><span class="identifier">numeric_cast</span></code>,
the user should define a <code class="computeroutput"><span class="identifier">numeric_cast_traits</span></code>
specialization on the UDT for each conversion. Here is an example of specializations
for converting between the UDT and any other type:
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Source</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">numeric_cast_traits</span><span class="special">&lt;</span><span class="identifier">UDT</span><span class="special">,</span> <span class="identifier">Source</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="identifier">UDT</span><span class="special">,</span> <span class="identifier">Source</span><span class="special">&gt;</span> <span class="identifier">conv_traits</span><span class="special">;</span>
<span class="comment">//! The following are required:</span>
<span class="keyword">typedef</span> <span class="identifier">YourOverflowHandlerPolicy</span> <span class="identifier">overflow_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">YourRangeCheckerPolicy</span><span class="special">&lt;</span><span class="identifier">conv_traits</span><span class="special">&gt;</span> <span class="identifier">range_checking_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">YourFloat2IntRounderPolicy</span><span class="special">&lt;</span><span class="identifier">Source</span><span class="special">&gt;</span> <span class="identifier">rounding_policy</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Target</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">numeric_cast_traits</span><span class="special">&lt;</span><span class="identifier">Target</span><span class="special">,</span> <span class="identifier">UDT</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="identifier">Target</span><span class="special">,</span> <span class="identifier">UDT</span><span class="special">&gt;</span> <span class="identifier">conv_traits</span><span class="special">;</span>
<span class="comment">//! The following are required:</span>
<span class="keyword">typedef</span> <span class="identifier">YourOverflowHandlerPolicy</span> <span class="identifier">overflow_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">YourRangeCheckerPolicy</span><span class="special">&lt;</span><span class="identifier">conv_traits</span><span class="special">&gt;</span> <span class="identifier">range_checking_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">YourFloat2IntRounderPolicy</span><span class="special">&lt;</span><span class="identifier">UDT</span><span class="special">&gt;</span> <span class="identifier">rounding_policy</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}//</span><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">;</span>
</pre>
<p>
These specializations are already defined with default values for the built-in
numeric types. It is possible to disable the generation of specializations
for built-in types by defining <code class="computeroutput"><span class="identifier">BOOST_NUMERIC_CONVERSION_RELAX_BUILT_IN_CAST_TRAITS</span></code>.
For details on defining custom policies see <a class="link" href="numeric_converter_policy_classes.html" title="Numeric Converter Policy Classes">Converter
Policies</a>.
</p>
<p>
Here is a full example of how to define a custom UDT for use with <code class="computeroutput"><span class="identifier">numeric_cast</span></code>:
</p>
<pre class="programlisting"><span class="comment">//! Define a simple custom number</span>
<span class="keyword">struct</span> <span class="identifier">Double</span>
<span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators</span>
<span class="special">&lt;</span>
<span class="identifier">Double</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">long</span> <span class="keyword">double</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">double</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">float</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">int</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">int</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">long</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">long</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">long</span> <span class="keyword">long</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">char</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">char</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">short</span>
<span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ordered_field_operators2</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">short</span>
<span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="special">{</span>
<span class="identifier">Double</span><span class="special">()</span>
<span class="special">:</span> <span class="identifier">v</span><span class="special">(</span><span class="number">0</span><span class="special">)</span>
<span class="special">{}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">explicit</span> <span class="identifier">Double</span><span class="special">(</span> <span class="identifier">T</span> <span class="identifier">v</span> <span class="special">)</span>
<span class="special">:</span> <span class="identifier">v</span><span class="special">(</span><span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">v</span><span class="special">))</span>
<span class="special">{}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=</span> <span class="special">(</span> <span class="identifier">T</span> <span class="identifier">t</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">t</span><span class="special">);</span>
<span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">&lt;</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">Double</span><span class="special">&amp;</span> <span class="identifier">rhs</span> <span class="special">)</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">v</span> <span class="special">&lt;</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">v</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">&lt;</span> <span class="special">(</span> <span class="identifier">T</span> <span class="identifier">rhs</span> <span class="special">)</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">v</span> <span class="special">&lt;</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">rhs</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">&gt;</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">Double</span><span class="special">&amp;</span> <span class="identifier">rhs</span> <span class="special">)</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">v</span> <span class="special">&gt;</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">v</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">&gt;</span> <span class="special">(</span> <span class="identifier">T</span> <span class="identifier">rhs</span> <span class="special">)</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">v</span> <span class="special">&gt;</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">rhs</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">==(</span> <span class="keyword">const</span> <span class="identifier">Double</span><span class="special">&amp;</span> <span class="identifier">rhs</span> <span class="special">)</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">v</span> <span class="special">==</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">v</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">==</span> <span class="special">(</span> <span class="identifier">T</span> <span class="identifier">rhs</span> <span class="special">)</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">v</span> <span class="special">==</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">rhs</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">!()</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">v</span> <span class="special">==</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
<span class="identifier">Double</span> <span class="keyword">operator</span> <span class="special">-()</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">Double</span><span class="special">(-</span><span class="identifier">v</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span> <span class="special">+=(</span> <span class="keyword">const</span> <span class="identifier">Double</span><span class="special">&amp;</span> <span class="identifier">t</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">+=</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">v</span><span class="special">;</span>
<span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span> <span class="special">+=(</span> <span class="identifier">T</span> <span class="identifier">t</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">+=</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">t</span><span class="special">);</span>
<span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
<span class="special">}</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span> <span class="special">-=(</span> <span class="keyword">const</span> <span class="identifier">Double</span><span class="special">&amp;</span> <span class="identifier">t</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">-=</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">v</span><span class="special">;</span>
<span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span> <span class="special">-=(</span> <span class="identifier">T</span> <span class="identifier">t</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">-=</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">t</span><span class="special">);</span>
<span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
<span class="special">}</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span> <span class="special">*=</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">Double</span><span class="special">&amp;</span> <span class="identifier">factor</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">*=</span> <span class="identifier">factor</span><span class="special">.</span><span class="identifier">v</span><span class="special">;</span>
<span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span> <span class="special">*=(</span> <span class="identifier">T</span> <span class="identifier">t</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">*=</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">t</span><span class="special">);</span>
<span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
<span class="special">}</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span> <span class="special">/=</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">Double</span><span class="special">&amp;</span> <span class="identifier">divisor</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">/=</span> <span class="identifier">divisor</span><span class="special">.</span><span class="identifier">v</span><span class="special">;</span>
<span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">Double</span><span class="special">&amp;</span> <span class="keyword">operator</span> <span class="special">/=(</span> <span class="identifier">T</span> <span class="identifier">t</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">v</span> <span class="special">/=</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">t</span><span class="special">);</span>
<span class="keyword">return</span> <span class="special">(*</span><span class="keyword">this</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">double</span> <span class="identifier">v</span><span class="special">;</span>
<span class="special">};</span>
<span class="comment">//! Define numeric_limits for the custom type.</span>
<span class="keyword">namespace</span> <span class="identifier">std</span>
<span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;&gt;</span>
<span class="keyword">class</span> <span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">Double</span><span class="special">&gt;</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="comment">//! Limit our Double to a range of +/- 100.0</span>
<span class="keyword">static</span> <span class="identifier">Double</span> <span class="special">(</span><span class="identifier">min</span><span class="special">)()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">Double</span><span class="special">(</span><span class="number">1.e-2</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="identifier">Double</span> <span class="special">(</span><span class="identifier">max</span><span class="special">)()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">Double</span><span class="special">(</span><span class="number">1.e2</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="identifier">Double</span> <span class="identifier">epsilon</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">Double</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;::</span><span class="identifier">epsilon</span><span class="special">()</span> <span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="special">}</span>
<span class="comment">//! Define range checking and overflow policies.</span>
<span class="keyword">namespace</span> <span class="identifier">custom</span>
<span class="special">{</span>
<span class="comment">//! Define a custom range checker</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">OverFlowHandler</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">range_checker</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">::</span><span class="identifier">argument_type</span> <span class="identifier">argument_type</span> <span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">::</span><span class="identifier">source_type</span> <span class="identifier">S</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">::</span><span class="identifier">target_type</span> <span class="identifier">T</span><span class="special">;</span>
<span class="comment">//! Check range of integral types.</span>
<span class="keyword">static</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">range_check_result</span> <span class="identifier">out_of_range</span><span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">;</span>
<span class="keyword">if</span><span class="special">(</span> <span class="identifier">s</span> <span class="special">&gt;</span> <span class="identifier">bounds</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">highest</span><span class="special">()</span> <span class="special">)</span>
<span class="keyword">return</span> <span class="identifier">cPosOverflow</span><span class="special">;</span>
<span class="keyword">else</span> <span class="keyword">if</span><span class="special">(</span> <span class="identifier">s</span> <span class="special">&lt;</span> <span class="identifier">bounds</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">lowest</span><span class="special">()</span> <span class="special">)</span>
<span class="keyword">return</span> <span class="identifier">cNegOverflow</span><span class="special">;</span>
<span class="keyword">else</span>
<span class="keyword">return</span> <span class="identifier">cInRange</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">validate_range</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">BOOST_STATIC_ASSERT</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_bounded</span> <span class="special">);</span>
<span class="identifier">OverFlowHandler</span><span class="special">()(</span> <span class="identifier">out_of_range</span><span class="special">(</span><span class="identifier">s</span><span class="special">)</span> <span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="comment">//! Overflow handler</span>
<span class="keyword">struct</span> <span class="identifier">positive_overflow</span><span class="special">{};</span>
<span class="keyword">struct</span> <span class="identifier">negative_overflow</span><span class="special">{};</span>
<span class="keyword">struct</span> <span class="identifier">overflow_handler</span>
<span class="special">{</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">range_check_result</span> <span class="identifier">r</span> <span class="special">)</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">;</span>
<span class="keyword">if</span><span class="special">(</span> <span class="identifier">r</span> <span class="special">==</span> <span class="identifier">cNegOverflow</span> <span class="special">)</span>
<span class="keyword">throw</span> <span class="identifier">negative_overflow</span><span class="special">()</span> <span class="special">;</span>
<span class="keyword">else</span> <span class="keyword">if</span><span class="special">(</span> <span class="identifier">r</span> <span class="special">==</span> <span class="identifier">cPosOverflow</span> <span class="special">)</span>
<span class="keyword">throw</span> <span class="identifier">positive_overflow</span><span class="special">()</span> <span class="special">;</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="comment">//! Define a rounding policy and specialize on the custom type.</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">Ceil</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">Ceil</span><span class="special">&lt;</span><span class="identifier">S</span><span class="special">&gt;{};</span>
<span class="keyword">template</span><span class="special">&lt;&gt;</span>
<span class="keyword">struct</span> <span class="identifier">Ceil</span><span class="special">&lt;</span><span class="identifier">Double</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">Double</span> <span class="identifier">source_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">Double</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">argument_type</span><span class="special">;</span>
<span class="keyword">static</span> <span class="identifier">source_type</span> <span class="identifier">nearbyint</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<span class="special">{</span>
<span class="preprocessor">#if</span> <span class="special">!</span><span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_NO_STDC_NAMESPACE</span><span class="special">)</span>
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ceil</span> <span class="special">;</span>
<span class="preprocessor">#endif</span>
<span class="keyword">return</span> <span class="identifier">Double</span><span class="special">(</span> <span class="identifier">ceil</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">v</span><span class="special">)</span> <span class="special">);</span>
<span class="special">}</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">float_round_style</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">round_toward_infinity</span><span class="special">&gt;</span> <span class="identifier">round_style</span><span class="special">;</span>
<span class="special">};</span>
<span class="comment">//! Define a rounding policy and specialize on the custom type.</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">Trunc</span><span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">Trunc</span><span class="special">&lt;</span><span class="identifier">S</span><span class="special">&gt;{};</span>
<span class="keyword">template</span><span class="special">&lt;&gt;</span>
<span class="keyword">struct</span> <span class="identifier">Trunc</span><span class="special">&lt;</span><span class="identifier">Double</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">Double</span> <span class="identifier">source_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">Double</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">argument_type</span><span class="special">;</span>
<span class="keyword">static</span> <span class="identifier">source_type</span> <span class="identifier">nearbyint</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
<span class="special">{</span>
<span class="preprocessor">#if</span> <span class="special">!</span><span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_NO_STDC_NAMESPACE</span><span class="special">)</span>
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">floor</span><span class="special">;</span>
<span class="preprocessor">#endif</span>
<span class="keyword">return</span> <span class="identifier">Double</span><span class="special">(</span> <span class="identifier">floor</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">v</span><span class="special">)</span> <span class="special">);</span>
<span class="special">}</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">float_round_style</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">round_toward_zero</span><span class="special">&gt;</span> <span class="identifier">round_style</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}//</span><span class="keyword">namespace</span> <span class="identifier">custom</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
<span class="comment">//! Define the numeric_cast_traits specializations on the custom type.</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">numeric_cast_traits</span><span class="special">&lt;</span><span class="identifier">Double</span><span class="special">,</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">custom</span><span class="special">::</span><span class="identifier">overflow_handler</span> <span class="identifier">overflow_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">custom</span><span class="special">::</span><span class="identifier">range_checker</span>
<span class="special">&lt;</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="identifier">Double</span><span class="special">,</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="special">,</span> <span class="identifier">overflow_policy</span>
<span class="special">&gt;</span> <span class="identifier">range_checking_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">Trunc</span><span class="special">&lt;</span><span class="identifier">S</span><span class="special">&gt;</span> <span class="identifier">rounding_policy</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">numeric_cast_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Double</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">custom</span><span class="special">::</span><span class="identifier">overflow_handler</span> <span class="identifier">overflow_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">custom</span><span class="special">::</span><span class="identifier">range_checker</span>
<span class="special">&lt;</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Double</span><span class="special">&gt;</span>
<span class="special">,</span> <span class="identifier">overflow_policy</span>
<span class="special">&gt;</span> <span class="identifier">range_checking_policy</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">custom</span><span class="special">::</span><span class="identifier">Trunc</span><span class="special">&lt;</span><span class="identifier">Double</span><span class="special">&gt;</span> <span class="identifier">rounding_policy</span><span class="special">;</span>
<span class="special">};</span>
<span class="comment">//! Define the conversion from the custom type to built-in types and vice-versa.</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">raw_converter</span><span class="special">&lt;</span> <span class="identifier">conversion_traits</span><span class="special">&lt;</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">Double</span> <span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">low_level_convert</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">Double</span><span class="special">&amp;</span> <span class="identifier">n</span> <span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;(</span> <span class="identifier">n</span><span class="special">.</span><span class="identifier">v</span> <span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">S</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">raw_converter</span><span class="special">&lt;</span> <span class="identifier">conversion_traits</span><span class="special">&lt;</span> <span class="identifier">Double</span><span class="special">,</span> <span class="identifier">S</span> <span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">Double</span> <span class="identifier">low_level_convert</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">S</span><span class="special">&amp;</span> <span class="identifier">n</span> <span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">Double</span><span class="special">(</span><span class="identifier">n</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="special">}}//</span><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">;</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -191,7 +548,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="converter___function_object.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="bounds___traits_class.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="converter___function_object.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bounds___traits_class.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Executable → Regular
View File
+50 -56
View File
@@ -1,33 +1,34 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter 1. Boost.NumericConversion</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;1.&#160;Boost.NumericConversion</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="index.html" title="Chapter 1. Boost.NumericConversion">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="next" href="boost_numericconversion/definitions.html" title="Definitions">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav"><a accesskey="n" href="boost_numericconversion/definitions.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a></div>
<div class="chapter" lang="en">
<div class="spirit-nav"><a accesskey="n" href="boost_numericconversion/definitions.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a></div>
<div class="chapter">
<div class="titlepage"><div>
<div><h2 class="title">
<a name="numeric_conversion"></a>Chapter 1. Boost.NumericConversion</h2></div>
<a name="numeric_conversion"></a>Chapter&#160;1.&#160;Boost.NumericConversion</h2></div>
<div><div class="author"><h3 class="author">
<span class="firstname">Fernando Luis</span> <span class="surname">Cacciola Carballal</span>
</h3></div></div>
<div><p class="copyright">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal</p></div>
<div><p class="copyright">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal</p></div>
<div><div class="legalnotice">
<a name="id2604942"></a><p>
<a name="numeric_conversion.legal"></a><p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -35,7 +36,7 @@
</div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dl class="toc">
<dt><span class="section"><a href="index.html#numeric_conversion.overview">Overview</a></span></dt>
<dt><span class="section"><a href="boost_numericconversion/definitions.html">Definitions</a></span></dt>
<dd><dl>
@@ -76,6 +77,8 @@
special semantics</a></span></dt>
<dt><span class="section"><a href="boost_numericconversion/type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies">Special
Policies</a></span></dt>
<dt><span class="section"><a href="boost_numericconversion/type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udts_with_numeric_cast">UDTs
with numeric_cast</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="boost_numericconversion/bounds___traits_class.html">bounds&lt;&gt;
traits class</a></span></dt>
@@ -110,6 +113,7 @@
<dd><dl>
<dt><span class="section"><a href="boost_numericconversion/improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_numericconversion/improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast">numeric_cast</a></span></dt>
<dt><span class="section"><a href="boost_numericconversion/improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast_traits">numeric_cast_traits</a></span></dt>
<dt><span class="section"><a href="boost_numericconversion/improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.examples">Examples</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="numeric_conversion/history_and_acknowledgments.html">History
@@ -117,71 +121,61 @@
<dt><span class="section"><a href="numeric_conversion/bibliography.html">Bibliography</a></span></dt>
</dl>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="numeric_conversion.overview"></a><a href="index.html#numeric_conversion.overview" title="Overview">Overview</a>
<a name="numeric_conversion.overview"></a><a class="link" href="index.html#numeric_conversion.overview" title="Overview">Overview</a>
</h2></div></div></div>
<p>
The Boost Numeric Conversion library is a collection of tools to describe and
perform conversions between values of different <a href="boost_numericconversion/definitions.html#numeric_conversion_definitions_numeric_types">numeric
perform conversions between values of different <a class="link" href="boost_numericconversion/definitions.html#boost_numericconversion.definitions.numeric_types" title="Numeric Types">numeric
types</a>.
</p>
<p>
The library includes a special alternative for a subset of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;</span></code>, the <a href="index.html#numeric_conversion_bounds">bounds&lt;&gt;</a>
traits class, which provides a consistent way to obtain the <a href="boost_numericconversion/definitions.html#numeric_conversion_definitions_range">boundary</a>
values for the <a href="boost_numericconversion/definitions.html#numeric_conversion_definitions_range">range</a>
The library includes a special alternative for a subset of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;</span></code>, the <a class="link" href="boost_numericconversion/bounds___traits_class.html" title="bounds&lt;&gt; traits class">bounds&lt;&gt;</a>
traits class, which provides a consistent way to obtain the <a class="link" href="boost_numericconversion/definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">boundary</a>
values for the <a class="link" href="boost_numericconversion/definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">range</a>
of a numeric type.
</p>
<p>
It also includes a set of <a href="index.html#numeric_conversion_traits">trait classes</a>
which describes the compile-time properties of a conversion from a source to
a target numeric type. Both <a href="boost_numericconversion/definitions.html#numeric_conversion_cpp_arithmetic_types">arithmetic</a>
and <a href="boost_numericconversion/definitions.html#numeric_conversion_definitions_numeric_types">user-defined
It also includes a set of <a class="link" href="boost_numericconversion/conversion_traits___traits_class.html" title="conversion_traits&lt;&gt; traits class">trait
classes</a> which describes the compile-time properties of a conversion
from a source to a target numeric type. Both <a class="link" href="boost_numericconversion/definitions.html#boost_numericconversion.definitions.c___arithmetic_types" title="C++ Arithmetic Types">arithmetic</a>
and <a class="link" href="boost_numericconversion/definitions.html#boost_numericconversion.definitions.numeric_types" title="Numeric Types">user-defined
numeric types</a> can be used.
</p>
<p>
A policy-based <a href="index.html#numeric_conversion_converter">converter</a>
A policy-based <a class="link" href="boost_numericconversion/converter___function_object.html" title="converter&lt;&gt; function object">converter</a>
object which uses <code class="computeroutput"><span class="identifier">conversion_traits</span></code>
to select an optimized implementation is supplied. Such implementation uses
an optimal range checking code suitable for the source/target combination.
</p>
<div class="itemizedlist"><ul type="disc">
<li>
The converter's out-of-range behavior can be customized via an <a href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler">OverflowHandler</a>
policy.
</li>
<li>
For floating-point to integral conversions, the rounding mode can be selected
via the <a href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_float_to_int_rounder">Float2IntRounder</a>
policy.
</li>
<li>
A custom low-level conversion routine (for UDTs for instance) can be passed
via a <a href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_raw_converter">RawConverter</a>
policy.
</li>
<li>
The optimized automatic range-checking logic can be overridden via a <a href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
policy.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
The converter's out-of-range behavior can be customized via an <a class="link" href="boost_numericconversion/numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler" title="Policy OverflowHandler">OverflowHandler</a>
policy.
</li>
<li class="listitem">
For floating-point to integral conversions, the rounding mode can be selected
via the <a class="link" href="boost_numericconversion/numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder" title="Policy Float2IntRounder">Float2IntRounder</a>
policy.
</li>
<li class="listitem">
A custom low-level conversion routine (for UDTs for instance) can be passed
via a <a class="link" href="boost_numericconversion/numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter" title="Policy RawConverter">RawConverter</a>
policy.
</li>
<li class="listitem">
The optimized automatic range-checking logic can be overridden via a <a class="link" href="boost_numericconversion/numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker" title="Policy UserRangeChecker">UserRangeChecker</a>
policy.
</li>
</ul></div>
</div>
<a name="numeric_conversion_converter"></a><p>
</p>
<a name="numeric_conversion_requirements"></a><p>
</p>
<a name="numeric_conversion_bounds"></a><p>
</p>
<a name="numeric_conversion_traits"></a><p>
</p>
<a name="numeric_coversion_converter_policies"></a><p>
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: February 12, 2008 at 22:56:38 GMT</small></p></td>
<td align="left"><p><small>Last revised: June 02, 2014 at 09:10:01 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
<div class="spirit-nav"><a accesskey="n" href="boost_numericconversion/definitions.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a></div>
<div class="spirit-nav"><a accesskey="n" href="boost_numericconversion/definitions.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a></div>
</body>
</html>
+57 -56
View File
@@ -1,79 +1,80 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Bibliography</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="prev" href="history_and_acknowledgments.html" title="History
and Acknowledgments">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="history_and_acknowledgments.html" title="History and Acknowledgments">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="history_and_acknowledgments.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a>
<a accesskey="p" href="history_and_acknowledgments.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="numeric_conversion.bibliography"></a><a href="bibliography.html" title="Bibliography">Bibliography</a>
<a name="numeric_conversion.bibliography"></a><a class="link" href="bibliography.html" title="Bibliography">Bibliography</a>
</h2></div></div></div>
<div class="itemizedlist"><ul type="disc">
<li>
Standard Documents:
<div class="orderedlist"><ol type="1">
<li>
ISO/IEC 14882:98 (C++98 Standard)
</li>
<li>
ISO/IEC 9899:1999 (C99 Standard)
</li>
<li>
ISO/IEC 10967-1 (Language Independent Arithmetic (LIA), Part I, 1994)
</li>
<li>
ISO/IEC 2382-1:1993 (Information Technology - Vocabulary - Part I: Fundamental
Terms)
</li>
<li>
ANSI/IEEE 754-1985 [and IEC 60559:1989] (Binary floating-point)
</li>
<li>
ANSI/IEEE 854-1988 (Radix Independent floating-point)
</li>
<li>
ANSI X3/TR-1-82 (Dictionary for Information Processing Systems)
</li>
<li>
ISO/IEC JTC1/SC22/WG14/N753 C9X Revision Proposal: LIA-1 Binding: Rationale
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Standard Documents:
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
ISO/IEC 14882:98 (C++98 Standard)
</li>
<li class="listitem">
ISO/IEC 9899:1999 (C99 Standard)
</li>
<li class="listitem">
ISO/IEC 10967-1 (Language Independent Arithmetic (LIA), Part I, 1994)
</li>
<li class="listitem">
ISO/IEC 2382-1:1993 (Information Technology - Vocabulary - Part I:
Fundamental Terms)
</li>
<li class="listitem">
ANSI/IEEE 754-1985 [and IEC 60559:1989] (Binary floating-point)
</li>
<li class="listitem">
ANSI/IEEE 854-1988 (Radix Independent floating-point)
</li>
<li class="listitem">
ANSI X3/TR-1-82 (Dictionary for Information Processing Systems)
</li>
<li class="listitem">
ISO/IEC JTC1/SC22/WG14/N753 C9X Revision Proposal: LIA-1 Binding:
Rationale
</li>
</ol></div>
</li>
<li>
Papers:
<div class="orderedlist"><ol type="1">
<li>
David Goldberg What Every Computer Scientist Should Know About Floating-Point
Arithmetic
</li>
<li>
Prof. William Kahan papers on floating-point.
</li>
</li>
<li class="listitem">
Papers:
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
David Goldberg What Every Computer Scientist Should Know About Floating-Point
Arithmetic
</li>
<li class="listitem">
Prof. William Kahan papers on floating-point.
</li>
</ol></div>
</li>
</li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -81,7 +82,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="history_and_acknowledgments.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a>
<a accesskey="p" href="history_and_acknowledgments.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a>
</div>
</body>
</html>
@@ -1,91 +1,89 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>History
and Acknowledgments</title>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>History and Acknowledgments</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
<link rel="prev" href="../boost_numericconversion/improved_numeric_cast__.html" title="Improved
numeric_cast&lt;&gt;">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.NumericConversion">
<link rel="prev" href="../boost_numericconversion/improved_numeric_cast__.html" title="Improved numeric_cast&lt;&gt;">
<link rel="next" href="bibliography.html" title="Bibliography">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../boost_numericconversion/improved_numeric_cast__.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="bibliography.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="../boost_numericconversion/improved_numeric_cast__.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bibliography.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="numeric_conversion.history_and_acknowledgments"></a><a href="history_and_acknowledgments.html" title="History
and Acknowledgments">History
<a name="numeric_conversion.history_and_acknowledgments"></a><a class="link" href="history_and_acknowledgments.html" title="History and Acknowledgments">History
and Acknowledgments</a>
</h2></div></div></div>
<a name="numeric_conversion.history_and_acknowledgments.pre_formal_review"></a><h4>
<a name="id2636499"></a>
<a href="history_and_acknowledgments.html#numeric_conversion.history_and_acknowledgments.pre_formal_review">Pre-formal
<h4>
<a name="numeric_conversion.history_and_acknowledgments.h0"></a>
<span class="phrase"><a name="numeric_conversion.history_and_acknowledgments.pre_formal_review"></a></span><a class="link" href="history_and_acknowledgments.html#numeric_conversion.history_and_acknowledgments.pre_formal_review">Pre-formal
review</a>
</h4>
<div class="itemizedlist"><ul type="disc">
<li>
Kevlin Henney, with help from David Abrahams and Beman Dawes, originally
contributed the previous version of <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code> which already presented the idea
of a runtime range check.
</li>
<li>
Later, Eric Ford, Kevin Lynch and the author spotted some genericity problems
with that <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code>
which prevented it from being used in a generic layer of math functions.
</li>
<li>
An improved <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code> which properly handled all combinations
of arithmetic types was presented.
</li>
<li>
David Abrahams and Beman Dawes acknowledged the need of an improved version
of <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code>
and supported the submission as originally laid out. Daryl Walker and Darin
Adler made some important comments and proposed fixes to the original submission.
</li>
<li>
Special thanks go to Björn Karlsoon who helped the author considerably.
Having found the problems with <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code> himself, he revised very carefully
the original submission and spot a subtle bug in the range checking implementation.
He also wrote part of this documentation and proof-read and corrected other
parts. And most importantly: the features now presented here in this library
evolved from the original submission as a result of the useful private communications
between Björn and the author.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Kevlin Henney, with help from David Abrahams and Beman Dawes, originally
contributed the previous version of <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code> which already presented the idea
of a runtime range check.
</li>
<li class="listitem">
Later, Eric Ford, Kevin Lynch and the author spotted some genericity problems
with that <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code> which prevented it from being used
in a generic layer of math functions.
</li>
<li class="listitem">
An improved <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code> which properly handled all combinations
of arithmetic types was presented.
</li>
<li class="listitem">
David Abrahams and Beman Dawes acknowledged the need of an improved version
of <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code>
and supported the submission as originally laid out. Daryl Walker and Darin
Adler made some important comments and proposed fixes to the original submission.
</li>
<li class="listitem">
Special thanks go to Bj&#246;rn Karlsoon who helped the author considerably.
Having found the problems with <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special">&lt;&gt;</span></code> himself, he revised very carefully
the original submission and spot a subtle bug in the range checking implementation.
He also wrote part of this documentation and proof-read and corrected other
parts. And most importantly: the features now presented here in this library
evolved from the original submission as a result of the useful private
communications between Bj&#246;rn and the author.
</li>
</ul></div>
<a name="numeric_conversion.history_and_acknowledgments.post_formal_review"></a><h4>
<a name="id2636651"></a>
<a href="history_and_acknowledgments.html#numeric_conversion.history_and_acknowledgments.post_formal_review">Post-formal
<h4>
<a name="numeric_conversion.history_and_acknowledgments.h1"></a>
<span class="phrase"><a name="numeric_conversion.history_and_acknowledgments.post_formal_review"></a></span><a class="link" href="history_and_acknowledgments.html#numeric_conversion.history_and_acknowledgments.post_formal_review">Post-formal
review</a>
</h4>
<div class="itemizedlist"><ul type="disc">
<li>
Guillaume Melquiond spoted some documentation and code issues, particularly
about rounding conversions.
</li>
<li>
The following people contributed an important review of the design, documentation
and c ode: Kevin Lynch, Thorsten Ottosen, Paul Bristow, Daryle Walker, Jhon
Torjo, Eric Ford, Gennadiy Rozental.
</li>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Guillaume Melquiond spoted some documentation and code issues, particularly
about rounding conversions.
</li>
<li class="listitem">
The following people contributed an important review of the design, documentation
and c ode: Kevin Lynch, Thorsten Ottosen, Paul Bristow, Daryle Walker,
Jhon Torjo, Eric Ford, Gennadiy Rozental.
</li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal<p>
<td align="right"><div class="copyright-footer">Copyright &#169; 2004-2007 Fernando
Luis Cacciola Carballal<p>
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" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
@@ -93,7 +91,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../boost_numericconversion/improved_numeric_cast__.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="bibliography.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
<a accesskey="p" href="../boost_numericconversion/improved_numeric_cast__.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bibliography.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
+38 -11
View File
@@ -15,7 +15,7 @@
The lack of preservation of range makes conversions between numeric types
error prone. This is true for both implicit conversions and explicit
conversions (through `static_cast`).
[link numeric_conversion_numeric_cast `numeric_cast`]
[link boost_numericconversion.improved_numeric_cast__.numeric_cast `numeric_cast`]
detects loss of range when a numeric type is converted, and throws an
exception if the range cannot be preserved.
@@ -34,7 +34,7 @@ behavior for overflow is undefined for all conversions (except the
aforementioned unsigned to unsigned) makes any code that may produce
positive or negative overflows exposed to portability issues.
`numeric_cast` adheres to the rules for implicit conversions mandated by
By default `numeric_cast` adheres to the rules for implicit conversions mandated by
the C++ Standard, such as truncating floating point types when converting
to integral types. The implementation must guarantee that for a conversion
to a type that can hold all possible values of the source type, there will
@@ -42,20 +42,29 @@ be no runtime overhead.
[endsect]
[#numeric_conversion_numeric_cast]
[section numeric_cast]
template<typename Target, typename Source> inline
typename boost::numeric::converter<Target,Source>::result_type
numeric_cast ( Source arg )
template <typename Target, typename Source> inline
Target numeric_cast( Source arg )
{
return boost::numeric::converter<Target,Source>::convert(arg);
typedef conversion_traits<Target, Source> conv_traits;
typedef numeric_cast_traits<Target, Source> cast_traits;
typedef converter
<
Target,
Source,
conv_traits,
typename cast_traits::overflow_policy,
typename cast_traits::rounding_policy,
raw_converter<conv_traits>,
typename cast_traits::range_checking_policy
> converter;
return converter::convert(arg);
}
`numeric_cast` returns the result of converting a value of type Source
to a value of type Target. If out-of-range is detected, an exception is
thrown (see
to a value of type Target. If out-of-range is detected, an overflow policy
is executed whose default behavior is to throw an an exception (see
[link numeric_conversion_bad_numeric_cast bad_numeric_cast],
[link numeric_conversion_negative_overflow negative_overflow] and
[link numeric_conversion_possitive_overflow positive_overflow]
@@ -63,6 +72,24 @@ thrown (see
[endsect]
[section numeric_cast_traits]
template <typename Target, typename Source, typename EnableIf = void>
struct numeric_cast_traits
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<Source> rounding_policy;
};
The behavior of `numeric_cast` may be tailored for custom numeric types through
the specialization of `numeric_cast_traits`. (see
[link boost_numericconversion.type_requirements_and_user_defined_types_support User Defined Types]
for details.
)
[endsect]
[section Examples]
The following example performs some typical conversions between numeric types:
+343 -9
View File
@@ -8,8 +8,6 @@
http://www.boost.org/LICENSE_1_0.txt)
]
[#numeric_conversion_requirements]
[section Type Requirements and User-defined-types support]
[section Type Requirements]
@@ -49,7 +47,7 @@ is positive or not, and for this it evaluates the expression
[heading Conversion Traits]
If a User Defined Type is involved in a conversion, it is ['assumed] that
the UDT has [link numeric_conversion_definitions_range wider range]
the UDT has [link boost_numericconversion.definitions.range_and_precision wider range]
than any built-in type, and consequently the values
of some `converter_traits<>` members are hardwired regardless of the reality.
The following table summarizes this:
@@ -80,12 +78,10 @@ checking logic when UDTs are involved in a conversion. Therefore, if either
Target or Source are not built-in types, the bundled range checking of the
`converter<>` function object is automatically disabled. However, it is possible
to supply a user-defined range-checker. See
[link numeric_conversion_requirements_hooks Special Policies]
[link boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies Special Policies]
[endsect]
[#numeric_conversion_requirements_hooks]
[section Special Policies]
There are two components of the `converter<>` class that might require special
@@ -98,17 +94,355 @@ of the types.
However, this internal logic is disabled when either type is User Defined.
In this case, the user can specify an ['external] range checking policy which will be
used in place of the internal code. See
[link numeric_conversion_policy_user_range_checker UserRangeChecker] policy for details.
used in place of the internal code. See
[link boost_numericconversion.type_requirements_and_user_defined_types_support.udts_with_numeric_cast numeric_cast_traits]
for details on using UDTs with `numeric_cast`.
The converter class performs the actual conversion using a Raw Converter policy.
The default raw converter simply performs a `static_cast<Target>(source)`.
However, if the a UDT is involved, the `static_cast` might not work. In this case,
the user can implement and pass a different raw converter policy.
See [link numeric_conversion_policy_raw_converter RawConverter] policy for details
See [link boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter RawConverter] policy for details.
[endsect]
[section UDTs with numeric_cast]
In order to employ UDTs with `numeric_cast`, the user should define
a `numeric_cast_traits` specialization on the UDT for each conversion.
Here is an example of specializations for converting between the UDT
and any other type:
namespace boost { namespace numeric {
template <typename Source>
struct numeric_cast_traits<UDT, Source>
{
typedef conversion_traits<UDT, Source> conv_traits;
//! The following are required:
typedef YourOverflowHandlerPolicy overflow_policy;
typedef YourRangeCheckerPolicy<conv_traits> range_checking_policy;
typedef YourFloat2IntRounderPolicy<Source> rounding_policy;
};
template <typename Target>
struct numeric_cast_traits<Target, UDT>
{
typedef conversion_traits<Target, UDT> conv_traits;
//! The following are required:
typedef YourOverflowHandlerPolicy overflow_policy;
typedef YourRangeCheckerPolicy<conv_traits> range_checking_policy;
typedef YourFloat2IntRounderPolicy<UDT> rounding_policy;
};
}}//namespace boost::numeric;
These specializations are already defined with default values for the built-in
numeric types. It is possible to disable the generation of specializations for
built-in types by defining `BOOST_NUMERIC_CONVERSION_RELAX_BUILT_IN_CAST_TRAITS`.
For details on defining custom policies see [link boost_numericconversion.numeric_converter_policy_classes Converter Policies].
Here is a full example of how to define a custom UDT for use with `numeric_cast`:
//! Define a simple custom number
struct Double
: boost::ordered_field_operators
<
Double
, boost::ordered_field_operators2< Double, long double
, boost::ordered_field_operators2< Double, double
, boost::ordered_field_operators2< Double, float
, boost::ordered_field_operators2< Double, int
, boost::ordered_field_operators2< Double, unsigned int
, boost::ordered_field_operators2< Double, long
, boost::ordered_field_operators2< Double, unsigned long
, boost::ordered_field_operators2< Double, long long
, boost::ordered_field_operators2< Double, unsigned long long
, boost::ordered_field_operators2< Double, char
, boost::ordered_field_operators2< Double, unsigned char
, boost::ordered_field_operators2< Double, short
, boost::ordered_field_operators2< Double, unsigned short
> > > > > > > > > > > > > >
{
Double()
: v(0)
{}
template <typename T>
explicit Double( T v )
: v(static_cast<double>(v))
{}
template <typename T>
Double& operator= ( T t )
{
v = static_cast<double>(t);
return *this;
}
bool operator < ( const Double& rhs ) const
{
return v < rhs.v;
}
template <typename T>
bool operator < ( T rhs ) const
{
return v < static_cast<double>(rhs);
}
bool operator > ( const Double& rhs ) const
{
return v > rhs.v;
}
template <typename T>
bool operator > ( T rhs ) const
{
return v > static_cast<double>(rhs);
}
bool operator ==( const Double& rhs ) const
{
return v == rhs.v;
}
template <typename T>
bool operator == ( T rhs ) const
{
return v == static_cast<double>(rhs);
}
bool operator !() const
{
return v == 0;
}
Double operator -() const
{
return Double(-v);
}
Double& operator +=( const Double& t )
{
v += t.v;
return *this;
}
template <typename T>
Double& operator +=( T t )
{
v += static_cast<double>(t);
return *this;
}
Double& operator -=( const Double& t )
{
v -= t.v;
return *this;
}
template <typename T>
Double& operator -=( T t )
{
v -= static_cast<double>(t);
return *this;
}
Double& operator *= ( const Double& factor )
{
v *= factor.v;
return *this;
}
template <typename T>
Double& operator *=( T t )
{
v *= static_cast<double>(t);
return *this;
}
Double& operator /= (const Double& divisor)
{
v /= divisor.v;
return *this;
}
template <typename T>
Double& operator /=( T t )
{
v /= static_cast<double>(t);
return (*this);
}
double v;
};
//! Define numeric_limits for the custom type.
namespace std
{
template<>
class numeric_limits<Double> : public numeric_limits<double>
{
public:
//! Limit our Double to a range of +/- 100.0
static Double (min)()
{
return Double(1.e-2);
}
static Double (max)()
{
return Double(1.e2);
}
static Double epsilon()
{
return Double( std::numeric_limits<double>::epsilon() );
}
};
}
//! Define range checking and overflow policies.
namespace custom
{
//! Define a custom range checker
template<typename Traits, typename OverFlowHandler>
struct range_checker
{
typedef typename Traits::argument_type argument_type ;
typedef typename Traits::source_type S;
typedef typename Traits::target_type T;
//! Check range of integral types.
static boost::numeric::range_check_result out_of_range( argument_type s )
{
using namespace boost::numeric;
if( s > bounds<T>::highest() )
return cPosOverflow;
else if( s < bounds<T>::lowest() )
return cNegOverflow;
else
return cInRange;
}
static void validate_range ( argument_type s )
{
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_bounded );
OverFlowHandler()( out_of_range(s) );
}
};
//! Overflow handler
struct positive_overflow{};
struct negative_overflow{};
struct overflow_handler
{
void operator() ( boost::numeric::range_check_result r )
{
using namespace boost::numeric;
if( r == cNegOverflow )
throw negative_overflow() ;
else if( r == cPosOverflow )
throw positive_overflow() ;
}
};
//! Define a rounding policy and specialize on the custom type.
template<class S>
struct Ceil : boost::numeric::Ceil<S>{};
template<>
struct Ceil<Double>
{
typedef Double source_type;
typedef Double const& argument_type;
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::ceil ;
#endif
return Double( ceil(s.v) );
}
typedef boost::mpl::integral_c< std::float_round_style, std::round_toward_infinity> round_style;
};
//! Define a rounding policy and specialize on the custom type.
template<class S>
struct Trunc: boost::numeric::Trunc<S>{};
template<>
struct Trunc<Double>
{
typedef Double source_type;
typedef Double const& argument_type;
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::floor;
#endif
return Double( floor(s.v) );
}
typedef boost::mpl::integral_c< std::float_round_style, std::round_toward_zero> round_style;
};
}//namespace custom;
namespace boost { namespace numeric {
//! Define the numeric_cast_traits specializations on the custom type.
template <typename S>
struct numeric_cast_traits<Double, S>
{
typedef custom::overflow_handler overflow_policy;
typedef custom::range_checker
<
boost::numeric::conversion_traits<Double, S>
, overflow_policy
> range_checking_policy;
typedef boost::numeric::Trunc<S> rounding_policy;
};
template <typename T>
struct numeric_cast_traits<T, Double>
{
typedef custom::overflow_handler overflow_policy;
typedef custom::range_checker
<
boost::numeric::conversion_traits<T, Double>
, overflow_policy
> range_checking_policy;
typedef custom::Trunc<Double> rounding_policy;
};
//! Define the conversion from the custom type to built-in types and vice-versa.
template<typename T>
struct raw_converter< conversion_traits< T, Double > >
{
static T low_level_convert ( const Double& n )
{
return static_cast<T>( n.v );
}
};
template<typename S>
struct raw_converter< conversion_traits< Double, S > >
{
static Double low_level_convert ( const S& n )
{
return Double(n);
}
};
}}//namespace boost::numeric;
[endsect]
[endsect]
+20
View File
@@ -0,0 +1,20 @@
// boost cast.hpp header file
//
// (C) Copyright Antony Polukhin 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)
//
// See http://www.boost.org/libs/conversion for Documentation.
// This is a DEPRECATED header file!
// Use <boost/polymorphic_cast.hpp> or <boost/numeric/conversion/cast.hpp> instead
#ifndef BOOST_CAST_HPP
#define BOOST_CAST_HPP
# include <boost/polymorphic_cast.hpp>
# include <boost/numeric/conversion/cast.hpp>
#endif // BOOST_CAST_HPP
+22 -12
View File
@@ -16,13 +16,14 @@
// 30 Oct 2001 Some fixes suggested by Daryle Walker (Fernando Cacciola)
// 25 Oct 2001 Initial boostification (Fernando Cacciola)
// 23 Jan 2004 Inital add to cvs (post review)s
// 22 Jun 2011 Added support for specializing cast policies via numeric_cast_traits (Brandon Kohn).
//
#ifndef BOOST_NUMERIC_CONVERSION_CAST_25OCT2001_HPP
#define BOOST_NUMERIC_CONVERSION_CAST_25OCT2001_HPP
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
# include<boost/numeric/conversion/detail/old_numeric_cast.hpp>
@@ -30,22 +31,31 @@
#include <boost/type.hpp>
#include <boost/numeric/conversion/converter.hpp>
#include <boost/numeric/conversion/numeric_cast_traits.hpp>
namespace boost
{
template<typename Target, typename Source>
inline
Target numeric_cast ( Source arg )
{
typedef boost::numeric::converter<Target,Source> Converter ;
return Converter::convert(arg);
}
using numeric::bad_numeric_cast;
template <typename Target, typename Source>
inline Target numeric_cast( Source arg )
{
typedef numeric::conversion_traits<Target, Source> conv_traits;
typedef numeric::numeric_cast_traits<Target, Source> cast_traits;
typedef boost::numeric::converter
<
Target,
Source,
conv_traits,
typename cast_traits::overflow_policy,
typename cast_traits::rounding_policy,
boost::numeric::raw_converter< conv_traits >,
typename cast_traits::range_checking_policy
> converter;
return converter::convert(arg);
}
using numeric::bad_numeric_cast;
} // namespace boost
#endif
#endif
@@ -21,13 +21,6 @@ template<class T, class S>
struct conversion_traits
: convdetail::get_conversion_traits<T,S>::type
{
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
typedef typename convdetail::get_conversion_traits<T,S>::type base_;
typedef typename base_::target_type target_type;
typedef typename base_::source_type source_type;
typedef typename base_::result_type result_type;
typedef typename base_::argument_type argument_type;
#endif
} ;
} } // namespace boost::numeric
@@ -10,11 +10,12 @@
#ifndef BOOST_NUMERIC_CONVERSION_CONVERTER_POLICIES_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_CONVERTER_POLICIES_FLC_12NOV2002_HPP
#include <functional>
#include <typeinfo> // for std::bad_cast
#include <cmath> // for std::floor and std::ceil
#include <functional>
#include <boost/config.hpp>
#include <boost/config/no_tr1/cmath.hpp> // for std::floor and std::ceil
#include <boost/throw_exception.hpp>
#include "boost/type_traits/is_arithmetic.hpp"
@@ -135,7 +136,7 @@ class bad_numeric_cast : public std::bad_cast
{
public:
virtual const char * what() const throw()
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{ return "bad numeric conversion: overflow"; }
};
@@ -143,14 +144,14 @@ class negative_overflow : public bad_numeric_cast
{
public:
virtual const char * what() const throw()
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{ return "bad numeric conversion: negative overflow"; }
};
class positive_overflow : public bad_numeric_cast
{
public:
virtual const char * what() const throw()
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{ return "bad numeric conversion: positive overflow"; }
};
@@ -158,10 +159,17 @@ struct def_overflow_handler
{
void operator() ( range_check_result r ) // throw(negative_overflow,positive_overflow)
{
#ifndef BOOST_NO_EXCEPTIONS
if ( r == cNegOverflow )
throw negative_overflow() ;
else if ( r == cPosOverflow )
throw positive_overflow() ;
#else
if ( r == cNegOverflow )
::boost::throw_exception(negative_overflow()) ;
else if ( r == cPosOverflow )
::boost::throw_exception(positive_overflow()) ;
#endif
}
} ;
@@ -450,13 +450,10 @@ namespace boost { namespace numeric { namespace convdetail
// Trivial Converter : used when (cv-unqualified) T == (cv-unqualified) S
//
template<class Traits>
struct trivial_converter_impl : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public dummy_range_checker<Traits>
struct trivial_converter_impl : public dummy_range_checker<Traits>
{
typedef Traits traits ;
typedef typename Traits::source_type source_type ;
typedef typename Traits::argument_type argument_type ;
typedef typename Traits::result_type result_type ;
@@ -471,10 +468,7 @@ namespace boost { namespace numeric { namespace convdetail
// Rounding Converter : used for float to integral conversions.
//
template<class Traits,class RangeChecker,class RawConverter,class Float2IntRounder>
struct rounding_converter : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public RangeChecker
struct rounding_converter : public RangeChecker
,public Float2IntRounder
,public RawConverter
{
@@ -501,10 +495,7 @@ namespace boost { namespace numeric { namespace convdetail
// Non-Rounding Converter : used for all other conversions.
//
template<class Traits,class RangeChecker,class RawConverter>
struct non_rounding_converter : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public RangeChecker
struct non_rounding_converter : public RangeChecker
,public RawConverter
{
typedef RangeChecker RangeCheckerBase ;
@@ -570,7 +561,7 @@ namespace boost { namespace numeric { namespace convdetail
>
struct get_converter_impl
{
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT( 0x0561 ) )
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT( 0x0561 ) )
// bcc55 prefers sometimes template parameters to be explicit local types.
// (notice that is is illegal to reuse the names like this)
typedef Traits Traits ;
@@ -16,15 +16,15 @@
#include "boost/numeric/conversion/int_float_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
#include "boost/type_traits/integral_constant.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'IntFloatMixture'
typedef mpl::integral_c<int_float_mixture_enum, integral_to_integral> int2int_c ;
typedef mpl::integral_c<int_float_mixture_enum, integral_to_float> int2float_c ;
typedef mpl::integral_c<int_float_mixture_enum, float_to_integral> float2int_c ;
typedef mpl::integral_c<int_float_mixture_enum, float_to_float> float2float_c ;
typedef boost::integral_constant<int_float_mixture_enum, integral_to_integral> int2int_c ;
typedef boost::integral_constant<int_float_mixture_enum, integral_to_float> int2float_c ;
typedef boost::integral_constant<int_float_mixture_enum, float_to_integral> float2int_c ;
typedef boost::integral_constant<int_float_mixture_enum, float_to_float> float2float_c ;
// Metafunction:
//
@@ -25,7 +25,7 @@ namespace boost { namespace numeric { namespace convdetail
template< class T1, class T2>
struct equal_to
{
#if !defined(__BORLANDC__)
#if !defined(BOOST_BORLANDC)
enum { x = ( BOOST_MPL_AUX_VALUE_WKND(T1)::value == BOOST_MPL_AUX_VALUE_WKND(T2)::value ) };
@@ -0,0 +1,138 @@
//
//! Copyright (c) 2011-2012
//! Brandon Kohn
//
// 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)
//
#if !defined(BOOST_NUMERIC_CONVERSION_DONT_USE_PREPROCESSED_FILES)
#include <boost/numeric/conversion/detail/preprocessed/numeric_cast_traits_common.hpp>
#if !defined(BOOST_NO_LONG_LONG)
#include <boost/numeric/conversion/detail/preprocessed/numeric_cast_traits_long_long.hpp>
#endif
#else
#if !BOOST_PP_IS_ITERATING
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/numeric_cast_traits_common.hpp")
#endif
//
//! Copyright (c) 2011-2012
//! Brandon Kohn
//
// 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)
//
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 1)
#endif
//! These are the assumed common built in fundamental types (not typedefs/macros.)
#define BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES() \
(char) \
(signed char) \
(unsigned char) \
(short) \
(unsigned short) \
(int) \
(unsigned int) \
(long) \
(unsigned long) \
(float) \
(double) \
(long double) \
/***/
#define BOOST_NUMERIC_CONVERSION_SEQ_A() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()
#define BOOST_NUMERIC_CONVERSION_SEQ_B() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()
namespace boost { namespace numeric {
#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_A())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
#include BOOST_PP_ITERATE()
}}//namespace boost::numeric;
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(output: null)
#endif
#if ( defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES) ) || !defined(BOOST_NO_LONG_LONG)
#undef BOOST_NUMERIC_CONVERSION_SEQ_A
#undef BOOST_NUMERIC_CONVERSION_SEQ_B
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/numeric_cast_traits_long_long.hpp")
#endif
//
//! Copyright (c) 2011-2012
//! Brandon Kohn
//
// 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)
//
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(preserve: 1)
#endif
namespace boost { namespace numeric {
#define BOOST_NUMERIC_CONVERSION_SEQ_A() BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES()(boost::long_long_type)(boost::ulong_long_type)
#define BOOST_NUMERIC_CONVERSION_SEQ_B() (boost::long_long_type)(boost::ulong_long_type)
#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_A())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
#include BOOST_PP_ITERATE()
}}//namespace boost::numeric;
#if defined(__WAVE__) && defined(BOOST_NUMERIC_CONVERSION_CREATE_PREPROCESSED_FILES)
#pragma wave option(output: null)
#endif
#endif
#undef BOOST_NUMERIC_CONVERSION_BASE_BUILTIN_TYPES
#undef BOOST_NUMERIC_CONVERSION_SEQ_A
#undef BOOST_NUMERIC_CONVERSION_SEQ_B
#elif BOOST_PP_ITERATION_DEPTH() == 1
#define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(BOOST_NUMERIC_CONVERSION_SEQ_B())), <boost/numeric/conversion/detail/numeric_cast_traits.hpp>))
#include BOOST_PP_ITERATE()
#elif BOOST_PP_ITERATION_DEPTH() == 2
//! Generate default traits for the specified source and target.
#define BOOST_NUMERIC_CONVERSION_A BOOST_PP_FRAME_ITERATION(1)
#define BOOST_NUMERIC_CONVERSION_B BOOST_PP_FRAME_ITERATION(2)
template <>
struct numeric_cast_traits
<
BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_A, BOOST_NUMERIC_CONVERSION_SEQ_A())
, BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_B, BOOST_NUMERIC_CONVERSION_SEQ_B())
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<BOOST_PP_SEQ_ELEM(BOOST_NUMERIC_CONVERSION_B, BOOST_NUMERIC_CONVERSION_SEQ_B())> rounding_policy;
};
#undef BOOST_NUMERIC_CONVERSION_A
#undef BOOST_NUMERIC_CONVERSION_B
#endif//! Depth 2.
#endif// BOOST_NUMERIC_CONVERSION_DONT_USE_PREPROCESSED_FILES
+7 -38
View File
@@ -8,6 +8,8 @@
// See http://www.boost.org/libs/conversion for Documentation.
// Revision History
// 02 Jun 14 Remove VC6 workarounds.
// 16 Jul 11 Bugfixes for VC6.
// 23 JUN 05 Code extracted from /boost/cast.hpp into this new header.
// Keeps this legacy version of numeric_cast<> for old compilers
// wich can't compile the new version in /boost/numeric/conversion/cast.hpp
@@ -53,19 +55,6 @@
# include <boost/limits.hpp>
# include <boost/numeric/conversion/converter_policies.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?
// FLC: This macro is repeated in boost/cast.hpp but only locally (is undefined at the bottom)
// so is OK to reproduce it here.
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
# else
# define BOOST_EXPLICIT_DEFAULT_TARGET
# endif
namespace boost
{
using numeric::bad_numeric_cast;
@@ -214,24 +203,6 @@ namespace boost
template <class X, class Y>
static inline bool check(X x, Y)
{ return x >= 0 && static_cast<X>(static_cast<Y>(x)) != x; }
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
// MSVC6 can't static_cast unsigned __int64 -> floating types
# define BOOST_UINT64_CAST(src_type) \
static inline bool check(src_type x, unsigned __int64) \
{ \
if (x < 0) return false; \
unsigned __int64 y = static_cast<unsigned __int64>(x); \
bool odd = y & 0x1; \
__int64 div2 = static_cast<__int64>(y >> 1); \
return ((static_cast<src_type>(div2) * 2.0) + odd) != x; \
}
BOOST_UINT64_CAST(long double);
BOOST_UINT64_CAST(double);
BOOST_UINT64_CAST(float);
# undef BOOST_UINT64_CAST
# endif
};
template<>
@@ -260,7 +231,7 @@ namespace boost
# pragma warning(push)
# pragma warning(disable : 4018)
# pragma warning(disable : 4146)
#elif defined(__BORLANDC__)
#elif defined(BOOST_BORLANDC)
# pragma option push -w-8041
# endif
@@ -277,7 +248,7 @@ namespace boost
# if BOOST_MSVC
# pragma warning(pop)
#elif defined(__BORLANDC__)
#elif defined(BOOST_BORLANDC)
# pragma option pop
# endif
} // namespace detail
@@ -285,7 +256,7 @@ namespace boost
#endif
template<typename Target, typename Source>
inline Target numeric_cast(Source arg BOOST_EXPLICIT_DEFAULT_TARGET)
inline Target numeric_cast(Source arg)
{
// typedefs abbreviating respective trait classes
typedef detail::fixed_numeric_limits<Source> arg_traits;
@@ -314,7 +285,7 @@ namespace boost
# if BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4018)
#elif defined(__BORLANDC__)
#elif defined(BOOST_BORLANDC)
#pragma option push -w-8012
# endif
if ((arg < 0 && !result_traits::is_signed) // loss of negative range
@@ -322,7 +293,7 @@ namespace boost
|| arg > (result_traits::max)()) // overflow
# if BOOST_MSVC
# pragma warning(pop)
#elif defined(__BORLANDC__)
#elif defined(BOOST_BORLANDC)
#pragma option pop
# endif
#endif
@@ -332,8 +303,6 @@ namespace boost
return static_cast<Target>(arg);
} // numeric_cast
# undef BOOST_EXPLICIT_DEFAULT_TARGET
} // namespace boost
#endif // BOOST_OLD_NUMERIC_CAST_HPP
@@ -0,0 +1,347 @@
//
//! Copyright (c) 2011-2012
//! Brandon Kohn
//
// 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)
//
namespace boost { namespace numeric {
template <>
struct numeric_cast_traits
<
char
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
char
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
signed char
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
signed char
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned char
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned char
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
short
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
short
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned short
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned short
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
int
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
int
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned int
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned int
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
long
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
long
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned long
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
unsigned long
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
float
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
float
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
double
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
double
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
long double
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
long double
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
boost::long_long_type
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
boost::long_long_type
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
boost::ulong_long_type
, boost::long_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::long_long_type> rounding_policy;
};
template <>
struct numeric_cast_traits
<
boost::ulong_long_type
, boost::ulong_long_type
>
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<boost::ulong_long_type> rounding_policy;
};
}}
@@ -16,15 +16,15 @@
#include "boost/numeric/conversion/sign_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
#include "boost/type_traits/integral_constant.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'SignMixture'
typedef mpl::integral_c<sign_mixture_enum, unsigned_to_unsigned> unsig2unsig_c ;
typedef mpl::integral_c<sign_mixture_enum, signed_to_signed> sig2sig_c ;
typedef mpl::integral_c<sign_mixture_enum, signed_to_unsigned> sig2unsig_c ;
typedef mpl::integral_c<sign_mixture_enum, unsigned_to_signed> unsig2sig_c ;
typedef boost::integral_constant<sign_mixture_enum, unsigned_to_unsigned> unsig2unsig_c ;
typedef boost::integral_constant<sign_mixture_enum, signed_to_signed> sig2sig_c ;
typedef boost::integral_constant<sign_mixture_enum, signed_to_unsigned> sig2unsig_c ;
typedef boost::integral_constant<sign_mixture_enum, unsigned_to_signed> unsig2sig_c ;
// Metafunction:
//
@@ -15,15 +15,15 @@
#include "boost/numeric/conversion/udt_builtin_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
#include "boost/type_traits/integral_constant.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'UdtMixture'
typedef mpl::integral_c<udt_builtin_mixture_enum, builtin_to_builtin> builtin2builtin_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, builtin_to_udt> builtin2udt_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, udt_to_builtin> udt2builtin_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, udt_to_udt> udt2udt_c ;
typedef boost::integral_constant<udt_builtin_mixture_enum, builtin_to_builtin> builtin2builtin_c ;
typedef boost::integral_constant<udt_builtin_mixture_enum, builtin_to_udt> builtin2udt_c ;
typedef boost::integral_constant<udt_builtin_mixture_enum, udt_to_builtin> udt2builtin_c ;
typedef boost::integral_constant<udt_builtin_mixture_enum, udt_to_udt> udt2udt_c ;
// Metafunction:
//
@@ -0,0 +1,31 @@
//
//! Copyright (c) 2011
//! Brandon Kohn
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_NUMERIC_CAST_TRAITS_HPP
#define BOOST_NUMERIC_CAST_TRAITS_HPP
#include <boost/numeric/conversion/converter_policies.hpp>
namespace boost { namespace numeric {
template <typename Target, typename Source, typename EnableIf = void>
struct numeric_cast_traits
{
typedef def_overflow_handler overflow_policy;
typedef UseInternalRangeChecker range_checking_policy;
typedef Trunc<Source> rounding_policy;
};
}}//namespace boost::numeric;
#if !defined( BOOST_NUMERIC_CONVERSION_RELAX_BUILT_IN_CAST_TRAITS )
#include <boost/cstdint.hpp>
#include <boost/numeric/conversion/detail/numeric_cast_traits.hpp>
#endif//!defined BOOST_NUMERIC_CONVERSION_RELAX_BUILT_IN_CAST_TRAITS
#endif//BOOST_NUMERIC_CAST_TRAITS_HPP
+17
View File
@@ -0,0 +1,17 @@
{
"key": "numeric/conversion",
"name": "Numeric Conversion",
"authors": [
"Fernando Cacciola"
],
"description": "Optimized Policy-based Numeric Conversions.",
"category": [
"Math",
"Miscellaneous"
],
"maintainers": [
"Fernando Cacciola <fernando_cacciola -at- ciudad.com.ar>",
"Brandon Kohn <blkohn -at- hotmail.com>"
],
"cxxstd": "03"
}
+33 -8
View File
@@ -5,13 +5,38 @@
# 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)
#
# import testing ;
test-suite numeric/conversion :
[ run bounds_test.cpp ]
[ run traits_test.cpp ]
[ run converter_test.cpp ]
[ run udt_support_test.cpp ]
[ run numeric_cast_test.cpp ]
[ run udt_example_0.cpp ]
;
project numeric_conversion_unit_tests
:
requirements
<include>.
<toolset>gcc:<cxxflags>"-ftemplate-depth-300 -g0"
<toolset>darwin:<cxxflags>"-ftemplate-depth-300 -g0"
;
test-suite minimal
:
[ run bounds_test.cpp ]
[ run traits_test.cpp : : : <toolset>msvc:<cxxflags>/bigobj ]
[ run converter_test.cpp ]
[ run udt_support_test.cpp ]
[ run numeric_cast_test.cpp ]
[ run udt_example_0.cpp ]
[ run numeric_cast_traits_test.cpp ]
;
test-suite full
:
minimal
[ compile-fail compile_fail/built_in_numeric_cast_traits.cpp ]
;
test-suite extra ;
explicit minimal ;
explicit extra ;
# support the old test target
test-suite numeric/conversion : full ;
+6 -12
View File
@@ -13,7 +13,7 @@
#include "boost/numeric/conversion/bounds.hpp"
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
@@ -32,17 +32,11 @@ void test_bounds( T expected_lowest, T expected_highest, T expected_smallest )
T highest = bounds<T>::highest () ;
T smallest = bounds<T>::smallest() ;
BOOST_CHECK_MESSAGE ( lowest == expected_lowest,
"bounds<" << typeid(T).name() << ">::lowest() = " << printable(lowest) << ". Expected " << printable(expected_lowest)
) ;
BOOST_TEST_EQ(lowest, expected_lowest);
BOOST_CHECK_MESSAGE ( highest == expected_highest,
"bounds<" << typeid(T).name() << ">::highest() = " << printable(highest) << ". Expected " << printable(expected_highest)
) ;
BOOST_TEST_EQ(highest, expected_highest);
BOOST_CHECK_MESSAGE ( smallest == expected_smallest,
"bounds<" << typeid(T).name() << ">::smallest() = " << printable(smallest) << ". Expected " << printable(expected_smallest)
) ;
BOOST_TEST_EQ(smallest, expected_smallest);
}
@@ -90,12 +84,12 @@ void test_bounds()
}
int test_main( int, char * [] )
int main( )
{
cout << setprecision( std::numeric_limits<long double>::digits10 ) ;
test_bounds();
return 0;
return boost::report_errors();
}
@@ -0,0 +1,115 @@
//
//! Copyright (c) 2011
//! Brandon Kohn
//
// 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/operators.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/preprocessor/control/iif.hpp>
#include <boost/preprocessor/comparison/less.hpp>
#include <boost/preprocessor/comparison/not_equal.hpp>
#include <boost/preprocessor/repetition/for.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/seq/size.hpp>
//! Generate default traits for the specified source and target.
#define BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS(r, state) \
template <> \
struct numeric_cast_traits< \
BOOST_PP_SEQ_ELEM( BOOST_PP_TUPLE_ELEM(4,0,state) \
, BOOST_PP_TUPLE_ELEM(4,3,state) ) \
, BOOST_PP_TUPLE_ELEM(4,2,state)> \
{ \
typedef def_overflow_handler overflow_policy; \
typedef UseInternalRangeChecker range_checking_policy; \
typedef Trunc<BOOST_PP_TUPLE_ELEM(4,2,state)> rounding_policy; \
}; \
/***/
#define BOOST_NUMERIC_CONVERSION_TUPLE_SENTINAL(r, state) \
BOOST_PP_LESS \
( \
BOOST_PP_TUPLE_ELEM(4,0,state) \
, BOOST_PP_TUPLE_ELEM(4,1,state) \
) \
/***/
#define BOOST_NUMERIC_CONVERSION_INC_OP(r, state) \
( \
BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(4,0,state)) \
, BOOST_PP_TUPLE_ELEM(4,1,state) \
, BOOST_PP_TUPLE_ELEM(4,2,state) \
, BOOST_PP_TUPLE_ELEM(4,3,state) \
) \
/***/
#define BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP(r, state) \
BOOST_PP_FOR \
( \
( \
0 \
, BOOST_PP_TUPLE_ELEM(4,1,state) \
, BOOST_PP_SEQ_ELEM(BOOST_PP_TUPLE_ELEM(4,0,state),BOOST_PP_TUPLE_ELEM(4,2,state)) \
, BOOST_PP_TUPLE_ELEM(4,2,state) \
) \
, BOOST_NUMERIC_CONVERSION_TUPLE_SENTINAL \
, BOOST_NUMERIC_CONVERSION_INC_OP \
, BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS \
) \
/***/
#define BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS(types) \
BOOST_PP_FOR \
( \
(0,BOOST_PP_SEQ_SIZE(types),types,_) \
, BOOST_NUMERIC_CONVERSION_TUPLE_SENTINAL \
, BOOST_NUMERIC_CONVERSION_INC_OP \
, BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP \
) \
/***/
namespace boost { namespace numeric {
#if !defined( BOOST_NO_INT64_T )
//! Generate the specializations for the built-in types.
BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
(
(char)
(boost::int8_t)
(boost::uint8_t)
(boost::int16_t)
(boost::uint16_t)
(boost::int32_t)
(boost::uint32_t)
(boost::int64_t)
(boost::uint64_t)
(float)
(double)
(long double)
)
#else
BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
(
(char)
(boost::int8_t)
(boost::uint8_t)
(boost::int16_t)
(boost::uint16_t)
(boost::int32_t)
(boost::uint32_t)
(float)
(double)
(long double)
)
#endif
}}//namespace boost::numeric;
#undef BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
#undef BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP
#undef BOOST_NUMERIC_CONVERSION_INC_OP
#undef BOOST_NUMERIC_CONVERSION_TUPLE_SENTINAL
#undef BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS
+7 -7
View File
@@ -22,7 +22,7 @@
//
// Borland 5.5 lacks the following math overloads
//
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
#if BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x551)
namespace std
{
@@ -37,7 +37,7 @@ inline long double floor (long double x) { return std::floorl(x); }
#include "boost/numeric/conversion/converter.hpp"
#include "boost/numeric/conversion/cast.hpp"
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
@@ -368,7 +368,7 @@ void test_round_style( MATCH_FNTPL_ARG(T), MATCH_FNTPL_ARG(S) )
void test_round_even( double n, double x )
{
double r = boost::numeric::RoundEven<double>::nearbyint(n);
BOOST_CHECK( r == x ) ;
BOOST_TEST( r == x ) ;
}
void test_round_even()
@@ -419,7 +419,7 @@ void test_converter_as_function_object()
// Match 'w' and 'i' which should be equal.
bool double_to_int_OK = std::equal(W.begin(),W.end(),I.begin()) ;
BOOST_CHECK_MESSAGE(double_to_int_OK, "converter (int,double) as function object");
BOOST_TEST(double_to_int_OK);
// Create a sequence of double values from s using a default numeric::converter (which should be the trivial conv).
std::vector<double> D ;
@@ -431,7 +431,7 @@ void test_converter_as_function_object()
// Match 's' and 'd' which should be equal.
bool double_to_double_OK = std::equal(S.begin(),S.end(),D.begin()) ;
BOOST_CHECK_MESSAGE(double_to_double_OK, "converter (double,double) as function object");
BOOST_TEST(double_to_double_OK);
}
#if BOOST_WORKAROUND(__IBMCPP__, <= 600 ) // VCAPP6
@@ -545,7 +545,7 @@ void test_optimizations()
//---------------------------------
}
int test_main( int, char* argv[] )
int main()
{
std::cout << std::setprecision( std::numeric_limits<long double>::digits10 ) ;
@@ -556,7 +556,7 @@ int test_main( int, char* argv[] )
test_converter_as_function_object();
test_optimizations() ;
return 0;
return boost::report_errors();
}
//---------------------------------------------------------------------------
+17 -34
View File
@@ -15,7 +15,7 @@
#include <boost/numeric/conversion/cast.hpp>
#include "boost/test/minimal.hpp"
#include <boost/core/lightweight_test.hpp>
# if SCHAR_MAX == LONG_MAX
# error "This test program doesn't work if SCHAR_MAX == LONG_MAX"
@@ -24,7 +24,7 @@
using namespace boost;
using std::cout;
int test_main( int argc, char * argv[] )
int main()
{
# ifdef NDEBUG
@@ -47,51 +47,34 @@ int test_main( int argc, char * argv[] )
c = large_value; // see if compiler generates warning
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
BOOST_TEST( c == 1 );
c = 0;
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
BOOST_TEST( c == 1 );
c = 0;
c = numeric_cast<signed char>( small_negative_value );
BOOST_CHECK( c == -1 );
BOOST_TEST( 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 ) );
BOOST_TEST( 0.0f == numeric_cast<float>( 0.0 ) );
BOOST_TEST( 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 ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #1\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { c = numeric_cast<signed char>( large_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #2\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_negative_value),
numeric::bad_numeric_cast );
unsigned long ul;
caught_exception = false;
try { ul = numeric_cast<unsigned long>( large_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #3\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_negative_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { ul = numeric_cast<unsigned long>( small_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #4\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<unsigned long>(small_negative_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { numeric_cast<int>( DBL_MAX ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<int>(DBL_MAX), numeric::bad_numeric_cast );
return 0 ;
return boost::report_errors() ;
} // main
+377
View File
@@ -0,0 +1,377 @@
//
//! Copyright (c) 2011
//! Brandon Kohn
//
// 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/operators.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/cstdint.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/static_assert.hpp>
//! Define a simple custom number
struct Double
{
Double()
: v(0)
{}
template <typename T>
explicit Double( T v )
: v(static_cast<double>(v))
{}
template <typename T>
Double& operator= ( T t )
{
v = static_cast<double>(t);
return *this;
}
bool operator < ( const Double& rhs ) const
{
return v < rhs.v;
}
template <typename T>
bool operator < ( T rhs ) const
{
return v < static_cast<double>(rhs);
}
template <typename LHS>
friend bool operator < ( const LHS& lhs, const Double& rhs )
{
return lhs < rhs.v;
}
bool operator > ( const Double& rhs ) const
{
return v > rhs.v;
}
template <typename LHS>
friend bool operator > ( const LHS& lhs, const Double& rhs )
{
return lhs > rhs.v;
}
template <typename T>
bool operator > ( T rhs ) const
{
return v > static_cast<double>(rhs);
}
bool operator == ( const Double& rhs ) const
{
return v == rhs.v;
}
template <typename T>
bool operator == ( T rhs ) const
{
return v == static_cast<double>(rhs);
}
template <typename LHS>
friend bool operator == ( const LHS& lhs, const Double& rhs )
{
return lhs == rhs.v;
}
bool operator !() const
{
return v == 0;
}
Double operator -() const
{
return Double(-v);
}
Double& operator +=( const Double& t )
{
v += t.v;
return *this;
}
template <typename T>
Double& operator +=( T t )
{
v += static_cast<double>(t);
return *this;
}
Double& operator -=( const Double& t )
{
v -= t.v;
return *this;
}
template <typename T>
Double& operator -=( T t )
{
v -= static_cast<double>(t);
return *this;
}
Double& operator *= ( const Double& factor )
{
v *= factor.v;
return *this;
}
template <typename T>
Double& operator *=( T t )
{
v *= static_cast<double>(t);
return *this;
}
Double& operator /= (const Double& divisor)
{
v /= divisor.v;
return *this;
}
template <typename T>
Double& operator /=( T t )
{
v /= static_cast<double>(t);
return (*this);
}
double v;
};
//! Define numeric_limits for the custom type.
namespace std
{
template<>
class numeric_limits< Double > : public numeric_limits<double>
{
public:
//! Limit our Double to a range of +/- 100.0
static Double (min)()
{
return Double(1.e-2);
}
static Double (max)()
{
return Double(1.e2);
}
static Double epsilon()
{
return Double( std::numeric_limits<double>::epsilon() );
}
};
}
//! Define range checking and overflow policies.
namespace custom
{
//! Define a custom range checker
template<typename Traits, typename OverFlowHandler>
struct range_checker
{
typedef typename Traits::argument_type argument_type ;
typedef typename Traits::source_type S;
typedef typename Traits::target_type T;
//! Check range of integral types.
static boost::numeric::range_check_result out_of_range( argument_type s )
{
using namespace boost::numeric;
if( s > bounds<T>::highest() )
return cPosOverflow;
else if( s < bounds<T>::lowest() )
return cNegOverflow;
else
return cInRange;
}
static void validate_range ( argument_type s )
{
BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_bounded );
OverFlowHandler()( out_of_range(s) );
}
};
//! Overflow handler
struct positive_overflow{};
struct negative_overflow{};
struct overflow_handler
{
void operator() ( boost::numeric::range_check_result r )
{
using namespace boost::numeric;
if( r == cNegOverflow )
throw negative_overflow() ;
else if( r == cPosOverflow )
throw positive_overflow() ;
}
};
//! Define a rounding policy and specialize on the custom type.
template<class S>
struct Ceil : boost::numeric::Ceil<S>{};
template<>
struct Ceil<Double>
{
typedef Double source_type;
typedef Double const& argument_type;
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::ceil ;
#endif
return Double( ceil(s.v) );
}
typedef boost::mpl::integral_c< std::float_round_style, std::round_toward_infinity> round_style;
};
//! Define a rounding policy and specialize on the custom type.
template<class S>
struct Trunc: boost::numeric::Trunc<S>{};
template<>
struct Trunc<Double>
{
typedef Double source_type;
typedef Double const& argument_type;
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::floor;
#endif
return Double( floor(s.v) );
}
typedef boost::mpl::integral_c< std::float_round_style, std::round_toward_zero> round_style;
};
}//namespace custom;
namespace boost { namespace numeric {
//! Define the numeric_cast_traits specializations on the custom type.
template <typename S>
struct numeric_cast_traits<Double, S>
{
typedef custom::overflow_handler overflow_policy;
typedef custom::range_checker
<
boost::numeric::conversion_traits<Double, S>
, overflow_policy
> range_checking_policy;
typedef boost::numeric::Trunc<S> rounding_policy;
};
template <typename T>
struct numeric_cast_traits<T, Double>
{
typedef custom::overflow_handler overflow_policy;
typedef custom::range_checker
<
boost::numeric::conversion_traits<T, Double>
, overflow_policy
> range_checking_policy;
typedef custom::Trunc<Double> rounding_policy;
};
//! Define the conversion from the custom type to built-in types and vice-versa.
template<typename T>
struct raw_converter< conversion_traits< T, Double > >
{
static T low_level_convert ( const Double& n )
{
return static_cast<T>( n.v );
}
};
template<typename S>
struct raw_converter< conversion_traits< Double, S > >
{
static Double low_level_convert ( const S& n )
{
return Double(n);
}
};
}}//namespace boost::numeric;
#define BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW( CastCode ) \
BOOST_TEST_THROWS( CastCode, custom::positive_overflow )
/***/
#define BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW( CastCode ) \
BOOST_TEST_THROWS( CastCode, custom::negative_overflow )
/***/
struct test_cast_traits
{
template <typename T>
void operator()(T) const
{
Double d = boost::numeric_cast<Double>( static_cast<T>(50) );
BOOST_TEST( d.v == 50. );
T v = boost::numeric_cast<T>( d );
BOOST_TEST( v == 50 );
}
};
void test_numeric_cast_traits()
{
typedef boost::mpl::vector
<
boost::int8_t
, boost::uint8_t
, boost::int16_t
, boost::uint16_t
, boost::int32_t
, boost::uint32_t
#if !defined( BOOST_NO_INT64_T )
, boost::int64_t
, boost::uint64_t
#endif
, float
, double
, long double
> types;
boost::mpl::for_each<types>( test_cast_traits() );
//! Check overflow handler.
Double d( 56.0 );
BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW( d = boost::numeric_cast<Double>( 101 ) );
BOOST_TEST( d.v == 56. );
BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW( d = boost::numeric_cast<Double>( -101 ) );
BOOST_TEST( d.v == 56.);
//! Check custom round policy.
d = 5.9;
int five = boost::numeric_cast<int>( d );
BOOST_TEST( five == 5 );
}
int main()
{
test_numeric_cast_traits();
return boost::report_errors();
}
#undef BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW
#undef BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW
+3 -2
View File
@@ -16,7 +16,8 @@
#include "boost/limits.hpp"
#include "boost/utility.hpp"
#include "boost/test/included/test_exec_monitor.hpp"
#include <boost/core/lightweight_test.hpp>
#include <stdexcept> // std::runtime_error
// Convenience macros to help with compilers which don't parse
// explicit template function instantiations (MSVC6)
@@ -118,7 +119,7 @@ class numeric_limits<MyUDT::MyFloat> : public numeric_limits<double>
// should be found by koenig loopkup, but some compilers don't do it right
// so we inyect them into namespace std so ordinary overload resolution
// can found them.
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) || defined(__BORLANDC__) || defined(__GNUC__)
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) || defined(BOOST_BORLANDC) || defined(__GNUC__)
namespace std {
using MyUDT::floor ;
using MyUDT::ceil ;
+6 -35
View File
@@ -69,51 +69,22 @@ void test_conv_base( Instance const& conv )
{
result_type result = converter::convert(source);
if ( conv.post == c_converted )
if (BOOST_TEST_EQ(conv.post, c_converted))
{
BOOST_CHECK_MESSAGE( result == conv.result,
conv.to_string() << printable(source) << ")= " << printable(result) << ". Expected:" << printable(conv.result)
) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = " << printable(result)
<< ". Expected:" << ( conv.post == c_neg_overflow ? " negative_overflow" : "positive_overflow" )
) ;
BOOST_TEST_EQ(result, conv.result);
}
}
catch ( boost::numeric::negative_overflow const& )
{
if ( conv.post == c_neg_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = negative_overflow, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = negative_overflow. Expected:" << printable(conv.result) ) ;
}
{
BOOST_TEST_EQ(conv.post, c_neg_overflow);
}
catch ( boost::numeric::positive_overflow const& )
{
if ( conv.post == c_pos_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = positive_overflow, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = positive_overflow. Expected:" << printable(conv.result) ) ;
}
BOOST_TEST_EQ(conv.post, c_pos_overflow);
}
catch ( boost::numeric::bad_numeric_cast const& )
{
if ( conv.post == c_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = bad_numeric_cast, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = bad_numeric_cast. Expected:" << printable(conv.result) ) ;
}
BOOST_TEST_EQ(conv.post, c_overflow);
}
}
+5 -13
View File
@@ -22,7 +22,7 @@
#include <boost/numeric/conversion/udt_builtin_mixture.hpp>
#include <boost/numeric/conversion/is_subranged.hpp>
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
@@ -258,11 +258,7 @@ struct generate_expected_traits
#define TEST_VALUE_FIELD(Name) \
typedef typename traits::Name BOOST_PP_CAT(t,Name) ; \
typedef typename expected::Name BOOST_PP_CAT(x,Name) ; \
BOOST_CHECK_MESSAGE ( ( BOOST_PP_CAT(t,Name)::value == BOOST_PP_CAT(x,Name)::value ) , \
"conversion_traits<" << typeid(T).name() << "," << typeid(S).name() \
<< ">::" << #Name << " = " << to_string(BOOST_PP_CAT(t,Name)::value) \
<< ". Expected: " << to_string(BOOST_PP_CAT(x,Name)::value) \
) ;
BOOST_TEST( ( BOOST_PP_CAT(t,Name)::value == BOOST_PP_CAT(x,Name)::value ) ) ;
// This macro generates the code that compares a type field
// in numeric::conversion_traits<> with its corresponding field
@@ -271,11 +267,7 @@ struct generate_expected_traits
#define TEST_TYPE_FIELD(Name) \
typedef typename traits::Name BOOST_PP_CAT(t,Name) ; \
typedef typename expected::Name BOOST_PP_CAT(x,Name) ; \
BOOST_CHECK_MESSAGE ( ( typeid(BOOST_PP_CAT(t,Name)) == typeid(BOOST_PP_CAT(x,Name)) ) , \
"conversion_traits<" << typeid(T).name() << "," << typeid(S).name() \
<< ">::" << #Name << " = " << typeid(BOOST_PP_CAT(t,Name)).name() \
<< ". Expected: " << typeid(BOOST_PP_CAT(x,Name)).name() \
) ;
BOOST_TEST ( ( typeid(BOOST_PP_CAT(t,Name)) == typeid(BOOST_PP_CAT(x,Name)) ) ) ;
//
// Test core.
@@ -329,13 +321,13 @@ void test_traits()
test_traits_from( SET_FNTPL_ARG(MyFloat) );
}
int test_main( int, char * [])
int main()
{
std::cout << std::setprecision( std::numeric_limits<long double>::digits10 ) ;
test_traits();
return 0;
return boost::report_errors();
}
//---------------------------------------------------------------------------
+19 -19
View File
@@ -16,7 +16,7 @@
#include<cmath>
#include "boost/test/included/test_exec_monitor.hpp"
#include <boost/core/lightweight_test.hpp>
#include "boost/numeric/conversion/cast.hpp"
@@ -58,13 +58,13 @@ void simplest_case()
//
// conversion_traits<>::udt_builtin_mixture works out of the box as long as boost::is_arithmetic<UDT> yields false
//
BOOST_CHECK( (conversion_traits<double,Double>::udt_builtin_mixture::value == udt_to_builtin) ) ;
BOOST_CHECK( (conversion_traits<Double,double>::udt_builtin_mixture::value == builtin_to_udt) ) ;
BOOST_CHECK( (conversion_traits<Double,Double>::udt_builtin_mixture::value == udt_to_udt ) ) ;
BOOST_TEST( (conversion_traits<double,Double>::udt_builtin_mixture::value == udt_to_builtin) ) ;
BOOST_TEST( (conversion_traits<Double,double>::udt_builtin_mixture::value == builtin_to_udt) ) ;
BOOST_TEST( (conversion_traits<Double,Double>::udt_builtin_mixture::value == udt_to_udt ) ) ;
// BY DEFINITION, a conversion from UDT to Builtin is subranged. No attempt is made to actually compare ranges.
BOOST_CHECK( (conversion_traits<double,Double>::subranged::value) == true ) ;
BOOST_CHECK( (conversion_traits<Double,double>::subranged::value) == false ) ;
BOOST_TEST( (conversion_traits<double,Double>::subranged::value) == true ) ;
BOOST_TEST( (conversion_traits<Double,double>::subranged::value) == false ) ;
@@ -72,18 +72,18 @@ void simplest_case()
// Conversions to/from FLOATING types, if already supported by an UDT
// are also supported out-of-the-box by converter<> in its default configuration.
//
BOOST_CHECK( numeric_cast<double>(Dv) == static_cast<double>(Dv) ) ;
BOOST_CHECK( numeric_cast<Double>(dv) == static_cast<Double>(dv) ) ;
BOOST_TEST( numeric_cast<double>(Dv) == static_cast<double>(Dv) ) ;
BOOST_TEST( numeric_cast<Double>(dv) == static_cast<Double>(dv) ) ;
BOOST_CHECK( numeric_cast<float> (Dv) == static_cast<float> (Dv) ) ;
BOOST_CHECK( numeric_cast<Double>(fv) == static_cast<Double>(fv) ) ;
BOOST_TEST( numeric_cast<float> (Dv) == static_cast<float> (Dv) ) ;
BOOST_TEST( numeric_cast<Double>(fv) == static_cast<Double>(fv) ) ;
//
// Range checking is disabled by default if an UDT is either the source or target of the conversion.
//
BOOST_CHECK( (converter<float,double>::out_of_range(dv) == cPosOverflow) );
BOOST_CHECK( (converter<float,Double>::out_of_range(Dv) == cInRange) );
BOOST_TEST( (converter<float,double>::out_of_range(dv) == cPosOverflow) );
BOOST_TEST( (converter<float,Double>::out_of_range(Dv) == cInRange) );
}
@@ -110,7 +110,7 @@ Double ceil ( Double v ) { return Double(std::ceil (v.mV)) ; }
void rounding()
{
BOOST_CHECK( numeric_cast<int>(Dv) == static_cast<int>(Dv) ) ;
BOOST_TEST( numeric_cast<int>(Dv) == static_cast<int>(Dv) ) ;
}
@@ -135,7 +135,7 @@ void custom_rounding()
>
DoubleToIntConverter ;
BOOST_CHECK( DoubleToIntConverter::convert(Dv) == static_cast<int>(Dv) ) ;
BOOST_TEST( DoubleToIntConverter::convert(Dv) == static_cast<int>(Dv) ) ;
}
//
@@ -187,8 +187,8 @@ void custom_raw_converter()
Int i (12);
Float fi(12);
BOOST_CHECK(numeric_cast<Int> (f).mV == i .mV ) ;
BOOST_CHECK(numeric_cast<Float>(i).mV == fi.mV ) ;
BOOST_TEST(numeric_cast<Int> (f).mV == i .mV ) ;
BOOST_TEST(numeric_cast<Float>(i).mV == fi.mV ) ;
}
//
@@ -219,10 +219,10 @@ void custom_raw_converter2()
>
Float2IntConverter ;
BOOST_CHECK(Float2IntConverter::convert(f).mV == i .mV ) ;
BOOST_TEST(Float2IntConverter::convert(f).mV == i .mV ) ;
}
int test_main( int, char* [] )
int main()
{
cout << setprecision( numeric_limits<long double>::digits10 ) ;
@@ -232,7 +232,7 @@ int test_main( int, char* [] )
custom_raw_converter();
custom_raw_converter2();
return 0;
return boost::report_errors();
}
+3 -3
View File
@@ -14,7 +14,7 @@
#include "boost/numeric/conversion/converter.hpp"
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
@@ -292,14 +292,14 @@ void test_udt_conversions_with_custom_range_checking()
}
int test_main( int, char* [] )
int main()
{
cout << setprecision( numeric_limits<long double>::digits10 ) ;
test_udt_conversions_with_defaults();
test_udt_conversions_with_custom_range_checking();
return 0;
return boost::report_errors();
}