mirror of
https://github.com/boostorg/numeric_conversion.git
synced 2026-07-21 13:33:43 +00:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50a1eae942 | |||
| 7c846ddf63 | |||
| 902588b6bd | |||
| 95c9f7f918 | |||
| db44689f4f | |||
| 1bc71b7971 | |||
| f9397e9cba | |||
| ccb153a506 | |||
| 07d5e56494 | |||
| 8c30716176 | |||
| 6c83ad8c57 | |||
| aab2ea1fed | |||
| 1d856f673f | |||
| de92292140 | |||
| 53de752e1f | |||
| a83247065b | |||
| a4d54f8f89 | |||
| a8467a8723 | |||
| 721dc89e7f | |||
| 36f969a4c5 | |||
| b900379a74 | |||
| 8ad516370a | |||
| c993894676 | |||
| 1da5d0d8fe | |||
| 5a45a8d824 | |||
| 3ae7d59e7a | |||
| 54d571dde2 | |||
| 4505bc3808 | |||
| 7f3a74cb74 | |||
| 278025d9c6 | |||
| 7436ca7113 | |||
| ebfded1d7d | |||
| c9d7a49b4a | |||
| 2009f0d4fc | |||
| 736745061d | |||
| 593aafab5a | |||
| a6681748be | |||
| d6ec138927 | |||
| 30d2e6d9f6 | |||
| d76eb6fa72 | |||
| c90517da96 | |||
| 907ae79790 | |||
| f4c6bd9711 | |||
| 86f8af551c | |||
| cda4506afe | |||
| 718767f1e6 | |||
| 26218a6e86 | |||
| 69a46fea8a | |||
| 056045e503 | |||
| d4a8c7049a | |||
| 0fc4c240b9 | |||
| c9e3ffd511 | |||
| e7b5847b5a | |||
| 0ab23addef | |||
| 5d344f7463 | |||
| 6bd888475f | |||
| 4c8e454bbb |
@@ -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
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
@@ -3,9 +3,11 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>bounds<> traits class</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" 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<> traits class">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -18,20 +20,24 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_numericconversion.bounds___traits_class"></a><a class="link" href="bounds___traits_class.html" title="bounds<> traits class">bounds<>
|
||||
traits class</a>
|
||||
</h2></div></div></div>
|
||||
|
||||
<div class="section">
|
||||
<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<N></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">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<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>
|
||||
[18.2.1], different syntax have to be used depending on numeric type. Specifically,
|
||||
<code class="computeroutput"><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">min</span><span class="special">()</span></code> for
|
||||
@@ -39,20 +45,19 @@
|
||||
types it returns the minimum positive normalized value. The difference in
|
||||
semantics makes client code unnecessarily complex and error prone.
|
||||
</p>
|
||||
<p>
|
||||
<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">bounds</span><span class="special"><></span></code>
|
||||
provides a consistent interface for retrieving the maximum finite value,
|
||||
the minimum finite value and the minimum positive normalized value (0 for
|
||||
integral types) for numeric types. The selection of implementation is performed
|
||||
at compile time, so there is no runtime overhead.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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<N>">traits
|
||||
class bounds<N></a>
|
||||
</h3></div></div></div>
|
||||
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">N</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">bounds</span>
|
||||
<span class="special">{</span>
|
||||
@@ -61,45 +66,38 @@
|
||||
<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>
|
||||
<h5>
|
||||
<h5>
|
||||
<a name="boost_numericconversion.bounds___traits_class.traits_class_bounds_n_.h0"></a>
|
||||
<span><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>
|
||||
<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>
|
||||
<div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<code class="computeroutput"><span class="identifier">lowest</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</blockquote></div>
|
||||
<p>
|
||||
</p></blockquote></div>
|
||||
<p>
|
||||
Returns the minimum finite value, equivalent to <code class="computeroutput"><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</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"><</span><span class="identifier">T</span><span class="special">>::</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>
|
||||
<div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<code class="computeroutput"><span class="identifier">highest</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</blockquote></div>
|
||||
<p>
|
||||
</p></blockquote></div>
|
||||
<p>
|
||||
Returns the maximum finite value, equivalent to <code class="computeroutput"><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">max</span><span class="special">()</span></code>.
|
||||
</p>
|
||||
<div class="blockquote"><blockquote class="blockquote">
|
||||
<p>
|
||||
<div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<code class="computeroutput"><span class="identifier">smallest</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</blockquote></div>
|
||||
<p>
|
||||
</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">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<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"><></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"><</span><span class="identifier">iostream</span><span class="special">></span>
|
||||
@@ -126,15 +124,20 @@
|
||||
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</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"></div></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 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>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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>
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>conversion_traits<> traits class</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" 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<> 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>
|
||||
@@ -18,25 +20,44 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class"></a><a class="link" href="conversion_traits___traits_class.html" title="conversion_traits<> traits class">conversion_traits<>
|
||||
traits class</a>
|
||||
</h2></div></div></div>
|
||||
|
||||
<div class="section">
|
||||
<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">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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="section">
|
||||
<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
|
||||
sign_mixture_enum</a></span></dt>
|
||||
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum">enumeration
|
||||
udt_builtin_mixture_enum</a></span></dt>
|
||||
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__">template
|
||||
class int_float_mixture<></a></span></dt>
|
||||
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__">template
|
||||
class sign_mixture<></a></span></dt>
|
||||
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__">template
|
||||
class udt_builtin_mixture<></a></span></dt>
|
||||
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__">template
|
||||
class is_subranged<></a></span></dt>
|
||||
<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<></a></span></dt>
|
||||
</dl></div>
|
||||
<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 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>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">int_float_mixture_enum</span>
|
||||
@@ -49,13 +70,12 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<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 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>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">sign_mixture_enum</span>
|
||||
@@ -68,13 +88,12 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<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 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>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">udt_builtin_mixture_enum</span>
|
||||
@@ -87,13 +106,12 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<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 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<>">template
|
||||
class int_float_mixture<></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"><</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">></span>
|
||||
@@ -101,22 +119,21 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
|
||||
</pre>
|
||||
<p>
|
||||
<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 class="ulink" href="../../../../mpl/doc/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>
|
||||
<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_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>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<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<>">template
|
||||
class sign_mixture<></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"><</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">></span>
|
||||
@@ -124,22 +141,21 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
|
||||
</pre>
|
||||
<p>
|
||||
<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 class="ulink" href="../../../../mpl/doc/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>
|
||||
<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>
|
||||
<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<>">template
|
||||
class udt_builtin_mixture<></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"><</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">></span>
|
||||
@@ -147,22 +163,21 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
|
||||
</pre>
|
||||
<p>
|
||||
<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 class="ulink" href="../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
this <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
Integral Constant</a> indicates the combination of these attributes.
|
||||
</p>
|
||||
<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>
|
||||
<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<>">template
|
||||
class is_subranged<></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"><</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">></span>
|
||||
@@ -170,28 +185,27 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace boost::numeric</span>
|
||||
</pre>
|
||||
<p>
|
||||
<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>.
|
||||
That is: if there are some source values which fall out of the Target type's
|
||||
range.
|
||||
</p>
|
||||
<p>
|
||||
It is a boolean <a class="ulink" href="../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
<p>
|
||||
It is a boolean <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
Integral Constant</a> .
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
It does not indicate if a particular conversion is effectively out of range;
|
||||
it indicates that some conversion might be out of range because not all
|
||||
the source values are representable as Target type.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<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 class="link" href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_conversion_traits__" title="template class conversion_traits<>">template
|
||||
class conversion_traits<></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"><</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">></span>
|
||||
@@ -214,7 +228,7 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, namespace boost</span>
|
||||
</pre>
|
||||
<p>
|
||||
<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
|
||||
@@ -222,14 +236,13 @@
|
||||
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 class="ulink" href="../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
<p>
|
||||
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):
|
||||
</p>
|
||||
<div class="informaltable">
|
||||
<table border="1">
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
@@ -278,16 +291,14 @@
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p>
|
||||
The traits class provides the following <a class="ulink" href="../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
</table></div>
|
||||
<p>
|
||||
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 class="link" href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">Definitions</a>
|
||||
for details).
|
||||
</p>
|
||||
<div class="informaltable">
|
||||
<table border="1">
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
@@ -329,14 +340,12 @@
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p>
|
||||
</table></div>
|
||||
<p>
|
||||
The traits class provides the following types. They are the Source and
|
||||
Target types classified and qualified for different purposes.
|
||||
</p>
|
||||
<div class="informaltable">
|
||||
<table border="1">
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
@@ -444,15 +453,13 @@
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
</table></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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"><</span><span class="identifier">cassert</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">typeinfo</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</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</span><span class="special">/</span><span class="identifier">conversion_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
@@ -479,15 +486,20 @@
|
||||
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</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"></div></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 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>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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>
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>converter<> function object</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. 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">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -18,19 +20,27 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_numericconversion.converter___function_object"></a><a class="link" href="converter___function_object.html" title="converter<> function object">converter<>
|
||||
function object</a>
|
||||
</h2></div></div></div>
|
||||
|
||||
<div class="section">
|
||||
<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>
|
||||
<dt><span class="section"><a href="converter___function_object.html#boost_numericconversion.converter___function_object.member_functions">Member
|
||||
functions</a></span></dt>
|
||||
<dt><span class="section"><a href="converter___function_object.html#boost_numericconversion.converter___function_object.range_checking_logic">Range
|
||||
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">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
|
||||
|
||||
@@ -65,24 +75,22 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, boost</span>
|
||||
</pre>
|
||||
<p>
|
||||
<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"><></span></code>
|
||||
is a <a class="ulink" href="http://www.sgi.com/tech/stl/UnaryFunction.html" target="_top">Unary Function
|
||||
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 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">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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 border="1">
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
@@ -203,32 +211,28 @@
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
</table></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<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"><>::</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>
|
||||
</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>.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
If the conversion requires it, it performs a range checking before the conversion
|
||||
and passes the result of the check to the overflow handler policy (the default
|
||||
policy throws an exception if out-of-range is detected)
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
The implementation of this function is actually built from the policies and
|
||||
is basically as follows:
|
||||
</p>
|
||||
@@ -244,35 +248,33 @@
|
||||
<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>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">converter</span><span class="special"><>::</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>
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<div class="blockquote"><blockquote class="blockquote">
|
||||
<p>
|
||||
<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"><>::</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></blockquote></div>
|
||||
<p>
|
||||
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>
|
||||
<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 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>
|
||||
<p>
|
||||
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>
|
||||
<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>-><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>
|
||||
@@ -280,115 +282,107 @@
|
||||
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>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<div class="blockquote"><blockquote class="blockquote">
|
||||
<p>
|
||||
<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"><>::</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></blockquote></div>
|
||||
<p>
|
||||
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 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>
|
||||
<p>
|
||||
For those Target/Source combinations which don't require range checking,
|
||||
this is an empty inline function.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
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
|
||||
the overflow handler.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<div class="blockquote"><blockquote class="blockquote">
|
||||
<p>
|
||||
<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"><>::</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></blockquote></div>
|
||||
<p>
|
||||
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
|
||||
static member function performs the actual conversion.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
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>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<div class="blockquote"><blockquote class="blockquote">
|
||||
<p>
|
||||
<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"><>::</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></blockquote></div>
|
||||
<p>
|
||||
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>
|
||||
<p>
|
||||
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>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<a name="numeric_conversion_converter_internal"></a>
|
||||
<h5>
|
||||
<a name="numeric_conversion_converter_internal"></a><h5>
|
||||
<a name="boost_numericconversion.converter___function_object.member_functions.h0"></a>
|
||||
<span><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
|
||||
<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>
|
||||
<p>
|
||||
These static member functions build the actual conversion code used by <code class="computeroutput"><span class="identifier">convert</span><span class="special">()</span></code>.
|
||||
The user does not have to call these if calling <code class="computeroutput"><span class="identifier">convert</span><span class="special">()</span></code>, since <code class="computeroutput"><span class="identifier">convert</span><span class="special">()</span></code> calls them infernally, but they can be
|
||||
called separately for specific needs.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<p>
|
||||
The following table summarizes the internal range checking logic performed
|
||||
for each combination of the properties of Source and Target.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
LowestT/HighestT denotes the highest and lowest values of the Target type,
|
||||
respectively.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">S</span><span class="special">(</span><span class="identifier">n</span><span class="special">)</span></code> is short
|
||||
for <code class="computeroutput"><span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">S</span><span class="special">>(</span><span class="identifier">n</span><span class="special">)</span></code> (<code class="computeroutput"><span class="identifier">S</span></code> denotes the Source type).
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">NONE</span></code> indicates that for this
|
||||
case there is no range checking.
|
||||
</p>
|
||||
@@ -419,12 +413,11 @@ float_to_float |--> subranged |--> ( s >= S(LowestT) ) && (
|
||||
|--> not subranged |--> NONE
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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"><</span><span class="identifier">cassert</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</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</span><span class="special">/</span><span class="identifier">converter</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
@@ -450,15 +443,20 @@ float_to_float |--> subranged |--> ( s >= S(LowestT) ) && (
|
||||
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</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"></div></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 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>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,9 +3,11 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Improved numeric_cast<></title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" 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">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -18,48 +20,46 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_numericconversion.improved_numeric_cast__"></a><a class="link" href="improved_numeric_cast__.html" title="Improved numeric_cast<>">Improved
|
||||
numeric_cast<></a>
|
||||
</h2></div></div></div>
|
||||
|
||||
<div class="section">
|
||||
<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">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<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 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>
|
||||
<p>
|
||||
There are several situations where conversions are unsafe:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<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>
|
||||
<li class="listitem">
|
||||
|
||||
Conversions from unsigned to signed (and vice versa) integral types.
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
Conversions from floating point types to integral types.
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
<p>
|
||||
The C++ Standard does not specify the behavior when a numeric type is assigned
|
||||
a value that cannot be represented by the type, except for unsigned integral
|
||||
types [3.9.1.4], which must obey the laws of arithmetic modulo 2n (this implies
|
||||
@@ -69,19 +69,18 @@
|
||||
to unsigned) makes any code that may produce positive or negative overflows
|
||||
exposed to portability issues.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
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>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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"><</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">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>
|
||||
@@ -100,7 +99,7 @@
|
||||
<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>
|
||||
<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 overflow policy is executed whose default behavior
|
||||
@@ -109,12 +108,11 @@
|
||||
and <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_possitive_overflow">positive_overflow</a>
|
||||
).
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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"><</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">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">numeric_cast_traits</span>
|
||||
<span class="special">{</span>
|
||||
@@ -123,31 +121,26 @@
|
||||
<span class="keyword">typedef</span> <span class="identifier">Trunc</span><span class="special"><</span><span class="identifier">Source</span><span class="special">></span> <span class="identifier">rounding_policy</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
<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>
|
||||
<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>
|
||||
<p>
|
||||
The following example performs some typical conversions between numeric types:
|
||||
</p>
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1">
|
||||
<div class="orderedlist"><ol class="orderedlist" type="1">
|
||||
<li class="listitem">
|
||||
|
||||
include <boost/numeric/conversion/cast.hpp>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
include <iostream>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ol></div>
|
||||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
@@ -200,15 +193,20 @@
|
||||
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</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"></div></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 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>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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>
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
<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-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" 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<> traits class">
|
||||
<link rel="next" href="improved_numeric_cast__.html" title="Improved numeric_cast<>">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -18,20 +20,30 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<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="section">
|
||||
<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
|
||||
OverflowHandler</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder">Policy
|
||||
Float2IntRounder</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter">Policy
|
||||
RawConverter</a></span></dt>
|
||||
<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>
|
||||
<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 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>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">range_check_result</span>
|
||||
@@ -43,24 +55,23 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
<p>
|
||||
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"><>::</span><span class="identifier">out_of_range</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<p>
|
||||
This <span class="emphasis"><em>stateless</em></span> non-template policy class must be a
|
||||
<span class="emphasis"><em>function object</em></span> and is called to administrate the result
|
||||
of the range checking. It can throw an exception if overflow has been detected
|
||||
by the range checking as indicated by its argument. If it throws, is is recommended
|
||||
that it be <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_cast</span></code> or derived.
|
||||
</p>
|
||||
<p>
|
||||
<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>
|
||||
@@ -68,10 +79,10 @@
|
||||
<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>
|
||||
<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>.
|
||||
</p>
|
||||
<p>
|
||||
<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>
|
||||
@@ -95,7 +106,7 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
<p>
|
||||
And these are the Exception Classes thrown by the default overflow handler
|
||||
<a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler_important_note">(see
|
||||
IMPORTANT note)</a>
|
||||
@@ -136,14 +147,12 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span>
|
||||
</pre>
|
||||
<a name="numeric_conversion_policy_overflow_handler_important_note"></a>
|
||||
<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/src/images/important.png"></td>
|
||||
<th align="left">Important</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top">
|
||||
<p>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
<span class="bold"><strong>RELEASE NOTE for 1.33</strong></span> Previous to boost
|
||||
version 1.33, the exception class <code class="computeroutput"><span class="identifier">bad_numeric_cast</span></code>
|
||||
was named <code class="computeroutput"><span class="identifier">bad_numeric_conversion</span></code>.
|
||||
@@ -155,24 +164,22 @@
|
||||
its exception type so I decided to avoid backward compatibility problems
|
||||
by adopting it (guessing that the user base for the old code is wider than
|
||||
for the new code).
|
||||
</p>
|
||||
</td></tr>
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<p>
|
||||
This <span class="emphasis"><em>stateless</em></span> template policy class specifies the rounding
|
||||
mode used for <span class="underline">float to integral</span> conversions.
|
||||
It supplies the <code class="computeroutput"><span class="identifier">nearbyint</span><span class="special">()</span></code> static member function exposed by the converter,
|
||||
which means that it <span class="underline">publicly inherits from this
|
||||
policy</span>.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
The policy must have the following interface:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">S</span><span class="special">></span>
|
||||
@@ -187,22 +194,20 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
<p>
|
||||
These are the rounder classes provided by the library (only the specific
|
||||
parts are shown, see the general policy form above)
|
||||
</p>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<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>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
These classes are not intended to be general purpose rounding functions
|
||||
but specific policies for <code class="computeroutput"><span class="identifier">converter</span><span class="special"><></span></code>. This is why they are not function
|
||||
objects.
|
||||
</p>
|
||||
</td></tr>
|
||||
</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>
|
||||
|
||||
@@ -260,43 +265,42 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, namespace boost</span>
|
||||
</pre>
|
||||
<h5>
|
||||
<h5>
|
||||
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder.h0"></a>
|
||||
<span><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
|
||||
<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>
|
||||
<p>
|
||||
The rounder policies supplied by this header use math 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>.
|
||||
The standard versions of these functions are introduced in context by a using
|
||||
directive, so in normal conditions, the standard functions will be used.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
However, if there are other visible corresponding overloads an ambiguity
|
||||
could arise. In this case, the user can supply her own rounder policy which
|
||||
could, for instance, use a fully qualified call.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
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 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>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<p>
|
||||
This <span class="emphasis"><em>stateless</em></span> template policy class is used to perform
|
||||
the actual conversion from Source to Target. 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, which means that it publicly
|
||||
inherits from this policy.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
The policy must have the following interface:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Traits</span><span class="special">></span>
|
||||
@@ -308,12 +312,12 @@
|
||||
<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="special"><</span><span class="identifier">impl</span> <span class="identifier">defined</span><span class="special">></span> <span class="special">;</span> <span class="special">}</span>
|
||||
<span class="special">}</span> <span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
<p>
|
||||
This policy is mostly provided as a hook for user defined types which don't
|
||||
support <code class="computeroutput"><span class="keyword">static_cast</span><span class="special"><></span></code>
|
||||
conversions to some types
|
||||
</p>
|
||||
<p>
|
||||
<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>
|
||||
@@ -332,22 +336,21 @@
|
||||
|
||||
<span class="special">}</span> <span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<p>
|
||||
This <span class="emphasis"><em>stateless</em></span> template policy class is used <span class="underline">only if supplied</span> to <span class="bold"><strong>override</strong></span>
|
||||
the internal range checking logic.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
It supplies the <code class="computeroutput"><span class="identifier">validate_range</span><span class="special">()</span></code> static member function exposed by the converter,
|
||||
which means that it publicly inherits from this policy.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
The policy must have the following interface:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Traits</span><span class="special">></span>
|
||||
@@ -366,22 +369,27 @@
|
||||
<span class="special">}</span>
|
||||
<span class="special">}</span> <span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
<p>
|
||||
This policy is <span class="bold"><strong>only</strong></span> provided as a hook for
|
||||
user defined types which require range checking (which is disabled by default
|
||||
when a UDT is involved). The library provides a class: <code class="computeroutput"><span class="identifier">UseInternalRangeChecker</span><span class="special">{}</span></code>; which is a <span class="emphasis"><em>fake</em></span>
|
||||
<code class="computeroutput"><span class="identifier">RangeChecker</span></code> policy used
|
||||
to signal the converter to use its internal range checking implementation.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</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"></div></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 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>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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>
|
||||
|
||||
+66
-78
@@ -3,9 +3,11 @@
|
||||
<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-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" 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<> function object">
|
||||
<link rel="next" href="bounds___traits_class.html" title="bounds<> traits class">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -18,38 +20,46 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<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="section">
|
||||
<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">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<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>
|
||||
<p>
|
||||
Both arithmetic (built-in) and user-defined numeric types require proper
|
||||
specialization of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><></span></code>
|
||||
(that is, with (in-class) integral constants).
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
The library uses <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">is_specialized</span></code> to detect whether the type
|
||||
is builtin or user defined, and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">is_integer</span></code>, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">is_signed</span></code> to detect whether the type is
|
||||
integer or floating point; and whether it is signed/unsigned.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
The default <code class="computeroutput"><span class="identifier">Float2IntRounder</span></code>
|
||||
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>
|
||||
<p>
|
||||
<p>
|
||||
Therefore, for builtin arithmetic types, the std functions will be used.
|
||||
User defined types should provide overloaded versions of these functions
|
||||
in order to use the default rounder policies. If these overloads are defined
|
||||
@@ -57,26 +67,25 @@
|
||||
but if your compiler has a weak ADL you might need to put these functions
|
||||
some place else or write your own rounder policy.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
The default <code class="computeroutput"><span class="identifier">Trunc</span><span class="special"><></span></code>
|
||||
rounder policy needs to determine if the source value is positive or not,
|
||||
and for this it evaluates the expression <code class="computeroutput"><span class="identifier">s</span>
|
||||
<span class="special"><</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">S</span><span class="special">>(</span><span class="number">0</span><span class="special">)</span></code>. Therefore,
|
||||
user defined types require a visible <code class="computeroutput"><span class="keyword">operator</span><span class="special"><</span></code> in order to use the <code class="computeroutput"><span class="identifier">Trunc</span><span class="special"><></span></code> policy (the default).
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
</div>
|
||||
<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 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>
|
||||
|
||||
<h5>
|
||||
<h5>
|
||||
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.h0"></a>
|
||||
<span><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
|
||||
<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>
|
||||
<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 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
|
||||
@@ -84,88 +93,64 @@
|
||||
members are hardwired regardless of the reality. The following table summarizes
|
||||
this:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<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" type="circle">
|
||||
<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>
|
||||
<li class="listitem">
|
||||
|
||||
<code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Target</span></code>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Source</span></code>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ul></div>
|
||||
|
||||
</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" type="circle">
|
||||
<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>
|
||||
<li class="listitem">
|
||||
|
||||
<code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Source</span></code>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Target</span></code>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ul></div>
|
||||
|
||||
</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" type="circle">
|
||||
<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>
|
||||
<li class="listitem">
|
||||
|
||||
<code class="computeroutput"><span class="identifier">supertype</span><span class="special">=</span><span class="identifier">Target</span></code>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
<code class="computeroutput"><span class="identifier">subtype</span><span class="special">=</span><span class="identifier">Source</span></code>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ul></div>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
<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>
|
||||
<h5>
|
||||
<h5>
|
||||
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.h1"></a>
|
||||
<span><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
|
||||
<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>
|
||||
<p>
|
||||
Because User Defined Numeric Types might have peculiar ranges (such as an
|
||||
unbounded range), this library does not attempt to supply a meaningful range
|
||||
checking logic when UDTs are involved in a conversion. Therefore, if either
|
||||
@@ -175,47 +160,45 @@
|
||||
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>
|
||||
<div class="section">
|
||||
</div>
|
||||
<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 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>
|
||||
<p>
|
||||
There are two components of the <code class="computeroutput"><span class="identifier">converter</span><span class="special"><></span></code> class that might require special
|
||||
behavior if User Defined Numeric Types are involved: the Range Checking and
|
||||
the Raw Conversion.
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
When both Target and Source are built-in types, the converter class uses
|
||||
an internal range checking logic which is optimized and customized for the
|
||||
combined properties of the types.
|
||||
</p>
|
||||
<p>
|
||||
<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 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>
|
||||
<p>
|
||||
The converter class performs the actual conversion using a Raw Converter
|
||||
policy. The default raw converter simply performs a <code class="computeroutput"><span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">Target</span><span class="special">>(</span><span class="identifier">source</span><span class="special">)</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
<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 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>
|
||||
<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>
|
||||
<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
|
||||
@@ -244,14 +227,14 @@
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
@@ -552,15 +535,20 @@
|
||||
<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>
|
||||
</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"></div></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 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>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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
+20
-40
@@ -3,8 +3,9 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Chapter 1. Boost.NumericConversion</title>
|
||||
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="index.html" title="Chapter 1. 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>
|
||||
@@ -16,7 +17,7 @@
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav"></div>
|
||||
<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">
|
||||
@@ -27,16 +28,15 @@
|
||||
<div><p class="copyright">Copyright © 2004-2007 Fernando
|
||||
Luis Cacciola Carballal</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="numeric_conversion.legal"></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 class="ulink" href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
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>
|
||||
</div></div>
|
||||
</div></div>
|
||||
</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>
|
||||
@@ -121,81 +121,61 @@
|
||||
<dt><span class="section"><a href="numeric_conversion/bibliography.html">Bibliography</a></span></dt>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="section">
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="numeric_conversion.overview"></a><a class="link" href="index.html#numeric_conversion.overview" title="Overview">Overview</a>
|
||||
</h2></div></div></div>
|
||||
|
||||
<p>
|
||||
<p>
|
||||
The Boost Numeric Conversion library is a collection of tools to describe and
|
||||
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>
|
||||
<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"><></span></code>, the <a class="link" href="boost_numericconversion/bounds___traits_class.html" title="bounds<> traits class">bounds<></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>
|
||||
<p>
|
||||
It also includes a set of <a class="link" href="boost_numericconversion/conversion_traits___traits_class.html" title="conversion_traits<> 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>
|
||||
<p>
|
||||
A policy-based <a class="link" href="boost_numericconversion/converter___function_object.html" title="converter<> 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 class="itemizedlist" type="disc">
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: November 21, 2011 at 16:44:25 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"></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>
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
<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-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" 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">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -18,90 +19,70 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="numeric_conversion.bibliography"></a><a class="link" href="bibliography.html" title="Bibliography">Bibliography</a>
|
||||
</h2></div></div></div>
|
||||
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<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>
|
||||
<li class="listitem">
|
||||
|
||||
ISO/IEC 9899:1999 (C99 Standard)
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
ISO/IEC 10967-1 (Language Independent Arithmetic (LIA), Part I, 1994)
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
ISO/IEC 2382-1:1993 (Information Technology - Vocabulary - Part I:
|
||||
Fundamental Terms)
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
ANSI/IEEE 754-1985 [and IEC 60559:1989] (Binary floating-point)
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
ANSI/IEEE 854-1988 (Radix Independent floating-point)
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
ANSI X3/TR-1-82 (Dictionary for Information Processing Systems)
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
ISO/IEC JTC1/SC22/WG14/N753 C9X Revision Proposal: LIA-1 Binding:
|
||||
Rationale
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ol></div>
|
||||
|
||||
</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>
|
||||
<li class="listitem">
|
||||
|
||||
Prof. William Kahan papers on floating-point.
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ol></div>
|
||||
|
||||
</li>
|
||||
</li>
|
||||
</ul></div>
|
||||
</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"></div></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 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>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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>
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
<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-NS Stylesheets V1.76.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" 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<>">
|
||||
<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>
|
||||
@@ -18,50 +20,40 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<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>
|
||||
|
||||
<h4>
|
||||
<h4>
|
||||
<a name="numeric_conversion.history_and_acknowledgments.h0"></a>
|
||||
<span><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
|
||||
<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 class="itemizedlist" type="disc">
|
||||
<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"><></span></code> which already presented the idea
|
||||
of a runtime range check.
|
||||
|
||||
</li>
|
||||
</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"><></span></code> which prevented it from being used
|
||||
in a generic layer of math functions.
|
||||
|
||||
</li>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
||||
An improved <code class="computeroutput"><span class="identifier">numeric_cast</span><span class="special"><></span></code> which properly handled all combinations
|
||||
of arithmetic types was presented.
|
||||
|
||||
</li>
|
||||
</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"><></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>
|
||||
<li class="listitem">
|
||||
|
||||
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"><></span></code> himself, he revised very carefully
|
||||
the original submission and spot a subtle bug in the range checking implementation.
|
||||
@@ -69,37 +61,37 @@
|
||||
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>
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<h4>
|
||||
<a name="numeric_conversion.history_and_acknowledgments.h1"></a>
|
||||
<span><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
|
||||
<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 class="itemizedlist" type="disc">
|
||||
<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>
|
||||
<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>
|
||||
</li>
|
||||
</ul></div>
|
||||
</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"></div></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 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>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<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="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>
|
||||
|
||||
@@ -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
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#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>
|
||||
|
||||
|
||||
@@ -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,13 +10,13 @@
|
||||
#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 <boost/config.hpp>
|
||||
#include <boost/config/no_tr1/cmath.hpp> // for std::floor and std::ceil
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "boost/type_traits/is_arithmetic.hpp"
|
||||
|
||||
#include "boost/mpl/if.hpp"
|
||||
@@ -136,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"; }
|
||||
};
|
||||
|
||||
@@ -144,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"; }
|
||||
};
|
||||
|
||||
|
||||
@@ -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 ) };
|
||||
|
||||
|
||||
Executable → Regular
+7
-38
@@ -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
|
||||
|
||||
@@ -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,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"
|
||||
}
|
||||
+25
-15
@@ -11,22 +11,32 @@
|
||||
project numeric_conversion_unit_tests
|
||||
:
|
||||
requirements
|
||||
<include>.
|
||||
<toolset>gcc:<cxxflags>"-ftemplate-depth-300 -g0"
|
||||
<toolset>darwin:<cxxflags>"-ftemplate-depth-300 -g0"
|
||||
<include>.
|
||||
<toolset>gcc:<cxxflags>"-ftemplate-depth-300 -g0"
|
||||
<toolset>darwin:<cxxflags>"-ftemplate-depth-300 -g0"
|
||||
;
|
||||
|
||||
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 ]
|
||||
[ run numeric_cast_traits_test.cpp ]
|
||||
;
|
||||
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 "compile_fail_test" :
|
||||
[ compile-fail compile_fail/built_in_numeric_cast_traits.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
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <boost/preprocessor/tuple/elem.hpp>
|
||||
#include <boost/preprocessor/seq/elem.hpp>
|
||||
#include <boost/preprocessor/seq/size.hpp>
|
||||
#include <boost/test/minimal.hpp>
|
||||
|
||||
//! Generate default traits for the specified source and target.
|
||||
#define BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS(r, state) \
|
||||
@@ -109,12 +108,6 @@ namespace boost { namespace numeric {
|
||||
#endif
|
||||
}}//namespace boost::numeric;
|
||||
|
||||
int test_main( int argc, char * argv[] )
|
||||
{
|
||||
//! This test should not compile.
|
||||
return 1;
|
||||
}
|
||||
|
||||
#undef BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
|
||||
#undef BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP
|
||||
#undef BOOST_NUMERIC_CONVERSION_INC_OP
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/test/minimal.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
//! Define a simple custom number
|
||||
struct Double
|
||||
@@ -314,15 +315,11 @@ namespace boost { namespace numeric {
|
||||
}}//namespace boost::numeric;
|
||||
|
||||
#define BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW( CastCode ) \
|
||||
try { CastCode; BOOST_CHECK( false ); } \
|
||||
catch( custom::positive_overflow& ){} \
|
||||
catch(...){ BOOST_CHECK( false ); } \
|
||||
BOOST_TEST_THROWS( CastCode, custom::positive_overflow )
|
||||
/***/
|
||||
|
||||
#define BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW( CastCode ) \
|
||||
try { CastCode; BOOST_CHECK( false ); } \
|
||||
catch( custom::negative_overflow& ){} \
|
||||
catch(...){ BOOST_CHECK( false ); } \
|
||||
BOOST_TEST_THROWS( CastCode, custom::negative_overflow )
|
||||
/***/
|
||||
|
||||
struct test_cast_traits
|
||||
@@ -331,9 +328,9 @@ struct test_cast_traits
|
||||
void operator()(T) const
|
||||
{
|
||||
Double d = boost::numeric_cast<Double>( static_cast<T>(50) );
|
||||
BOOST_CHECK( d.v == 50. );
|
||||
BOOST_TEST( d.v == 50. );
|
||||
T v = boost::numeric_cast<T>( d );
|
||||
BOOST_CHECK( v == 50 );
|
||||
BOOST_TEST( v == 50 );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -360,20 +357,20 @@ void test_numeric_cast_traits()
|
||||
//! Check overflow handler.
|
||||
Double d( 56.0 );
|
||||
BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW( d = boost::numeric_cast<Double>( 101 ) );
|
||||
BOOST_CHECK( d.v == 56. );
|
||||
BOOST_TEST( d.v == 56. );
|
||||
BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW( d = boost::numeric_cast<Double>( -101 ) );
|
||||
BOOST_CHECK( d.v == 56.);
|
||||
BOOST_TEST( d.v == 56.);
|
||||
|
||||
//! Check custom round policy.
|
||||
d = 5.9;
|
||||
int five = boost::numeric_cast<int>( d );
|
||||
BOOST_CHECK( five == 5 );
|
||||
BOOST_TEST( five == 5 );
|
||||
}
|
||||
|
||||
int test_main( int argc, char * argv[] )
|
||||
int main()
|
||||
{
|
||||
test_numeric_cast_traits();
|
||||
return 0;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#undef BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW
|
||||
|
||||
@@ -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
@@ -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
@@ -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
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user