mirror of
https://github.com/boostorg/numeric_conversion.git
synced 2026-07-21 13:33:43 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ab5a806137 | |||
| 128e01f1ea | |||
| 6dc956e342 | |||
| 2994de17ef |
@@ -12,9 +12,6 @@
|
||||
|
||||
import quickbook ;
|
||||
|
||||
path-constant images : html ;
|
||||
|
||||
|
||||
xml conversion
|
||||
:
|
||||
conversion.qbk
|
||||
@@ -29,8 +26,5 @@ boostbook standalone
|
||||
<xsl:param>toc.max.depth=2
|
||||
<xsl:param>toc.section.depth=2
|
||||
<xsl:param>chunk.section.depth=1
|
||||
<format>pdf:<xsl:param>img.src.path=$(images)/
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/numeric/conversion/doc/html
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
]
|
||||
|
||||
[#numeric_conversion_bounds]
|
||||
|
||||
[section bounds<> traits class]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
+12
-12
@@ -46,32 +46,32 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
The Boost Numeric Conversion library is a collection of tools to describe and
|
||||
perform conversions between values of different
|
||||
[link boost_numericconversion.definitions.numeric_types numeric types].
|
||||
[link numeric_conversion_definitions_numeric_types numeric types].
|
||||
|
||||
The library includes a special alternative for a subset of `std::numeric_limits<>`,
|
||||
the [link boost_numericconversion.bounds___traits_class bounds<>] traits class, which provides
|
||||
a consistent way to obtain the [link boost_numericconversion.definitions.range_and_precision boundary]
|
||||
values for the [link boost_numericconversion.definitions.range_and_precision range] of a numeric type.
|
||||
the [link numeric_conversion_bounds bounds<>] traits class, which provides
|
||||
a consistent way to obtain the [link numeric_conversion_definitions_range boundary]
|
||||
values for the [link numeric_conversion_definitions_range range] of a numeric type.
|
||||
|
||||
It also includes a set of [link boost_numericconversion.conversion_traits___traits_class trait classes]
|
||||
It also includes a set of [link numeric_conversion_traits trait classes]
|
||||
which describes the compile-time
|
||||
properties of a conversion from a source to a target numeric type.
|
||||
Both [link boost_numericconversion.definitions.c___arithmetic_types arithmetic] and
|
||||
[link boost_numericconversion.definitions.numeric_types user-defined numeric types] can be used.
|
||||
Both [link numeric_conversion_cpp_arithmetic_types arithmetic] and
|
||||
[link numeric_conversion_definitions_numeric_types user-defined numeric types] can be used.
|
||||
|
||||
A policy-based [link boost_numericconversion.converter___function_object converter] object which
|
||||
A policy-based [link numeric_conversion_converter converter] object which
|
||||
uses `conversion_traits` to select
|
||||
an optimized implementation is supplied. Such implementation uses an optimal
|
||||
range checking code suitable for the source/target combination.
|
||||
|
||||
* The converter's out-of-range behavior can be customized via an
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler OverflowHandler] policy.
|
||||
[link numeric_conversion_policy_overflow_handler OverflowHandler] policy.
|
||||
* For floating-point to integral conversions, the rounding mode can be selected via the
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder Float2IntRounder] policy.
|
||||
[link numeric_conversion_policy_float_to_int_rounder Float2IntRounder] policy.
|
||||
* A custom low-level conversion routine (for UDTs for instance) can be passed via a
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter RawConverter] policy.
|
||||
[link numeric_conversion_policy_raw_converter RawConverter] policy.
|
||||
* The optimized automatic range-checking logic can be overridden via a
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker UserRangeChecker] policy.
|
||||
[link numeric_conversion_policy_user_range_checker UserRangeChecker] policy.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
+27
-11
@@ -8,10 +8,14 @@
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
]
|
||||
|
||||
[#numeric_conversion_traits]
|
||||
|
||||
[section conversion_traits<> traits class]
|
||||
|
||||
[section Types]
|
||||
|
||||
[#numeric_conversion_traits_int_float_mixture_enum]
|
||||
|
||||
[section enumeration int_float_mixture_enum]
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
@@ -28,6 +32,8 @@
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_traits_sign_mixture_enum]
|
||||
|
||||
[section enumeration sign_mixture_enum]
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
@@ -44,6 +50,8 @@
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_traits_udt_builtin_mixture_enum]
|
||||
|
||||
[section enumeration udt_builtin_mixture_enum]
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
@@ -60,6 +68,8 @@
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_traits_class_int_float_mixture]
|
||||
|
||||
[section template class int_float_mixture<>]
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
@@ -73,10 +83,12 @@ Classifying `S` and `T` as either integral or float, this __MPL_INTEGRAL_CONSTAN
|
||||
indicates the combination of these attributes.
|
||||
|
||||
Its `::value` is of enumeration type
|
||||
[link boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum `boost::numeric::int_float_mixture_enum`]
|
||||
[link numeric_conversion_traits_int_float_mixture_enum `boost::numeric::int_float_mixture_enum`]
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_traits_class_sign_mixture]
|
||||
|
||||
[section template class sign_mixture<>]
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
@@ -90,10 +102,12 @@ Classifying `S` and `T` as either signed or unsigned, this __MPL_INTEGRAL_CONSTA
|
||||
indicates the combination of these attributes.
|
||||
|
||||
Its `::value` is of enumeration type
|
||||
[link boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum `boost::numeric::sign_mixture_enum`]
|
||||
[link numeric_conversion_traits_sign_mixture_enum `boost::numeric::sign_mixture_enum`]
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_traits_class_udt_builtin_mixture]
|
||||
|
||||
[section template class udt_builtin_mixture<>]
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
@@ -107,10 +121,12 @@ Classifying `S` and `T` as either user-defined or builtin, this __MPL_INTEGRAL_C
|
||||
indicates the combination of these attributes.
|
||||
|
||||
Its `::value` is of enumeration type
|
||||
[link boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum `boost::numeric::udt_builtin_mixture_enum`]
|
||||
[link numeric_conversion_traits_udt_builtin_mixture_enum `boost::numeric::udt_builtin_mixture_enum`]
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_traits_is_subranged]
|
||||
|
||||
[section template class is_subranged<>]
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
@@ -160,7 +176,7 @@ source values are representable as Target type.
|
||||
This traits class indicates some properties of a ['numeric conversion] direction:
|
||||
from a source type `S` to a target type `T`. It does not indicate the properties
|
||||
of a ['specific] conversion, but of the conversion direction. See
|
||||
[link boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype Definitions] for details.
|
||||
[link numeric_conversion_definitions_subranged Definitions] for details.
|
||||
|
||||
The traits class provides the following __MPL_INTEGRAL_CONSTANT__\s of enumeration
|
||||
type. They express the combination of certain attributes of the Source and
|
||||
@@ -170,26 +186,26 @@ Target types (thus they are call mixture):
|
||||
[[ ][ ]]
|
||||
[[[*int_float_mixture ]][
|
||||
Same as given by the traits class
|
||||
[link boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__ int_float_mixture]
|
||||
[link numeric_conversion_traits_class_int_float_mixture int_float_mixture]
|
||||
]]
|
||||
[[[*sign_mixture ]][
|
||||
Same as given by the traits class
|
||||
[link boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__ sign_mixture]
|
||||
[link numeric_conversion_traits_class_sign_mixture sign_mixture]
|
||||
]]
|
||||
[[[*udt_builtin_mixture ]]
|
||||
[Same as given by the traits class
|
||||
[link boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__ udt_builtin_mixture]
|
||||
[link numeric_conversion_traits_class_udt_builtin_mixture udt_builtin_mixture]
|
||||
]]
|
||||
]
|
||||
|
||||
The traits class provides the following __MPL_INTEGRAL_CONSTANT__\s of boolean type
|
||||
which indicates indirectly the relation between the Source and Target ranges
|
||||
(see [link boost_numericconversion.definitions.range_and_precision Definitions] for details).
|
||||
(see [link numeric_conversion_definitions_range Definitions] for details).
|
||||
|
||||
[table
|
||||
[[ ][ ]]
|
||||
[[subranged ][
|
||||
Same as given by [link boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__ is_subranged]
|
||||
Same as given by [link numeric_conversion_traits_is_subranged is_subranged]
|
||||
]]
|
||||
[[trivial][
|
||||
Indicates if both Source and Target, [_without cv-qualifications], are the same type.
|
||||
@@ -214,7 +230,7 @@ The template parameter `S` without cv-qualifications
|
||||
This type is either source_type or `source_type const&`.
|
||||
|
||||
It represents the optimal argument type for the
|
||||
[link boost_numericconversion.converter___function_object converter] member functions.
|
||||
[link numeric_conversion_converter converter] member functions.
|
||||
|
||||
If S is a built-in type, this is `source_type`, otherwise, this is `source_type const&`.
|
||||
]]
|
||||
@@ -222,7 +238,7 @@ If S is a built-in type, this is `source_type`, otherwise, this is `source_type
|
||||
This type is either target_type or target_type const&
|
||||
|
||||
It represents the return type of the
|
||||
[link boost_numericconversion.converter___function_object converter] member functions.
|
||||
[link numeric_conversion_converter converter] member functions.
|
||||
|
||||
If `T==S`, it is `target_type const&`, otherwise, it is `target_type`.
|
||||
]]
|
||||
|
||||
+16
-12
@@ -8,6 +8,8 @@
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
]
|
||||
|
||||
[#numeric_conversion_converter]
|
||||
|
||||
[section converter<> function object]
|
||||
|
||||
[section Synopsis]
|
||||
@@ -50,7 +52,7 @@
|
||||
`boost::numeric::converter<>` is a __SGI_UNARY_FUNCTION__ encapsulating
|
||||
the code to perform a numeric conversion with the direction and
|
||||
properties specified by the Traits template parameter. It can optionally
|
||||
take some [link boost_numericconversion.numeric_converter_policy_classes policies] which can be used to customize its behavior. The
|
||||
take some [link numeric_coversion_converter_policies policies] which can be used to customize its behavior. The
|
||||
`Traits` parameter is not a policy but the parameter that defines
|
||||
the conversion.
|
||||
|
||||
@@ -61,16 +63,16 @@ the conversion.
|
||||
[table
|
||||
[[ ][ ]]
|
||||
[[`T`][
|
||||
The [link boost_numericconversion.definitions.numeric_types Numeric Type]
|
||||
The [link numeric_conversion_definitions_numeric_types Numeric Type]
|
||||
which is the ['Target] of the conversion.
|
||||
]]
|
||||
[[`S`][
|
||||
The [link boost_numericconversion.definitions.numeric_types Numeric Type]
|
||||
The [link numeric_conversion_definitions_numeric_types Numeric Type]
|
||||
which is the ['Source] of the conversion.
|
||||
]]
|
||||
[[`Traits`][
|
||||
This must be a conversion traits class with the interface of
|
||||
[link boost_numericconversion.conversion_traits___traits_class `boost::numeric::conversion_traits`]
|
||||
[link numeric_conversion_traits `boost::numeric::conversion_traits`]
|
||||
]]
|
||||
[[`OverflowHandler`][
|
||||
[*Stateless Policy] called to administrate the result of the range checking.
|
||||
@@ -141,19 +143,19 @@ represented by the target type without overflow.
|
||||
|
||||
It does not determine if the conversion is ['exact]; that is, it does not detect
|
||||
['inexact] conversions, only ['out-of-range] conversions (see the
|
||||
[link boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations Definitions] for further details).
|
||||
[link numeric_conversion_definitions_roundoff Definitions] for further details).
|
||||
|
||||
The return value is of enum type
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result `boost::numeric::range_check_result`]
|
||||
[link numeric_conversion_converter_policies_range_check_result `boost::numeric::range_check_result`]
|
||||
|
||||
The actual code for the range checking logic is optimized for the combined
|
||||
properties of the source and target types. For example, a non-subranged
|
||||
conversion (i.e: `int`->`float`), requires no range checking, so `out_of_range()`
|
||||
returns `cInRange` directly. See the following
|
||||
[link boost_numericconversion.converter___function_object.range_checking_logic table] for more details.
|
||||
[link numeric_conversion_converter_range_checking_logic table] for more details.
|
||||
|
||||
If the user supplied a
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker UserRangeChecker] policy,
|
||||
[link numeric_conversion_policy_user_range_checker UserRangeChecker] policy,
|
||||
is this policy which implements this function, so the implementation is user
|
||||
defined, although it is expected to perform the same conceptual check and
|
||||
return the appropriate result.
|
||||
@@ -165,14 +167,14 @@ __SPACE__
|
||||
|
||||
This [link numeric_conversion_converter_internal internal] static member function
|
||||
calls out_of_range(s), and passes the
|
||||
result to the [link boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler OverflowHandler]
|
||||
result to the [link numeric_conversion_policy_overflow_handler OverflowHandler]
|
||||
policy class.
|
||||
|
||||
For those Target/Source combinations which don't require range checking, this
|
||||
is an empty inline function.
|
||||
|
||||
If the user supplied a
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker UserRangeChecker] policy,
|
||||
[link numeric_conversion_policy_user_range_checker UserRangeChecker] policy,
|
||||
is this policy which implements this function, so the implementation is user
|
||||
defined, although it is expected to perform the same action as the default.
|
||||
In particular, it is expected to pass the result of the check to the overflow handler.
|
||||
@@ -185,7 +187,7 @@ This [link numeric_conversion_converter_internal internal] static member functio
|
||||
performs the actual conversion.
|
||||
|
||||
This function is externally supplied by the
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter RawConverter] policy class.
|
||||
[link numeric_conversion_policy_raw_converter RawConverter] policy class.
|
||||
|
||||
__SPACE__
|
||||
|
||||
@@ -197,7 +199,7 @@ which is [_only used] for
|
||||
type]] according to some rounding direction.
|
||||
|
||||
This function is externally supplied by the
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder Float2IntRounder] policy class
|
||||
[link numeric_conversion_policy_float_to_int_rounder Float2IntRounder] policy class
|
||||
which encapsulates the specific rounding mode.
|
||||
|
||||
__SPACE__
|
||||
@@ -212,6 +214,8 @@ them infernally, but they can be called separately for specific needs.
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_converter_range_checking_logic]
|
||||
|
||||
[section Range Checking Logic]
|
||||
|
||||
The following table summarizes the internal range checking logic performed for
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
]
|
||||
|
||||
[#numeric_coversion_converter_policies]
|
||||
|
||||
[section Numeric Converter Policy Classes]
|
||||
|
||||
|
||||
[#numeric_conversion_converter_policies_range_check_result]
|
||||
|
||||
[section enum range_check_result]
|
||||
|
||||
namespace boost { namespace numeric {
|
||||
@@ -28,6 +32,8 @@ Defines the values returned by `boost::numeric::converter<>::out_of_range()`
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_policy_overflow_handler]
|
||||
|
||||
[section Policy OverflowHandler]
|
||||
|
||||
This ['stateless] non-template policy class must be a ['function object] and is
|
||||
@@ -122,6 +128,8 @@ the old code is wider than for the new code).
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_policy_float_to_int_rounder]
|
||||
|
||||
[section Policy Float2IntRounder]
|
||||
|
||||
This ['stateless] template policy class specifies the rounding mode used
|
||||
@@ -219,11 +227,13 @@ use a fully qualified call.
|
||||
|
||||
This technique allows the default rounder policies to be used directly with
|
||||
user defined types. The user only requires that suitable overloads of `floor()` and `ceil()`
|
||||
be visible. See also [link boost_numericconversion.type_requirements_and_user_defined_types_support User Defined Numeric Types]
|
||||
be visible. See also [link numeric_conversion_requirements User Defined Numeric Types]
|
||||
support.
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_policy_raw_converter]
|
||||
|
||||
[section Policy RawConverter]
|
||||
|
||||
This ['stateless] template policy class is used to perform the
|
||||
@@ -265,6 +275,8 @@ This is the only raw converter policy class provided by the library:
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_policy_user_range_checker]
|
||||
|
||||
[section Policy UserRangeChecker]
|
||||
|
||||
This ['stateless] template policy class is used [_only if supplied]
|
||||
|
||||
+12
-2
@@ -85,6 +85,8 @@ rest of this document.
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_cpp_arithmetic_types]
|
||||
|
||||
[section C++ Arithmetic Types]
|
||||
|
||||
The C++ language defines [_fundamental types] (§3.9.1). The following subsets of
|
||||
@@ -142,6 +144,8 @@ positive values only (you can do this with signed types as well).
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_definitions_numeric_types]
|
||||
|
||||
[section Numeric Types]
|
||||
|
||||
This section introduces the following definitions intended to integrate
|
||||
@@ -157,8 +161,8 @@ A type is [*numeric] if:
|
||||
* It is a user-defined type which
|
||||
* Represents numeric abstract values (i.e. numbers).
|
||||
* Can be converted (either implicitly or explicitly) to/from at least one arithmetic type.
|
||||
* Has [link boost_numericconversion.definitions.range_and_precision range] (possibly unbounded)
|
||||
and [link boost_numericconversion.definitions.range_and_precision precision] (possibly dynamic or
|
||||
* Has [link numeric_conversion_definitions_range range] (possibly unbounded)
|
||||
and [link numeric_conversion_definitions_range precision] (possibly dynamic or
|
||||
unlimited).
|
||||
* Provides an specialization of `std::numeric_limits`.
|
||||
|
||||
@@ -212,6 +216,8 @@ types (and values):
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_definitions_range]
|
||||
|
||||
[section Range and Precision]
|
||||
|
||||
Given a number set `N`, some of its elements are representable in a numeric type `T`.
|
||||
@@ -312,6 +318,8 @@ while the higher the number of mantissa bits, the higher the precision.
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_definitions_roundoff]
|
||||
|
||||
[section Exact, Correctly Rounded and Out-Of-Range Representations]
|
||||
|
||||
Given an abstract value `V` and a type `T` with its corresponding range `[abt(l),abt(h)]`:
|
||||
@@ -446,6 +454,8 @@ that is, the conversion is required to be correctly rounded.
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_definitions_subranged]
|
||||
|
||||
[section Subranged Conversion Direction, Subtype and Supertype]
|
||||
|
||||
Given a source type `S` and a destination type `T`, there is a
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>bounds<> traits class</title>
|
||||
<title>bounds<>
|
||||
traits class</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="type_requirements_and_user_defined_types_support.html" title="Type Requirements and User-defined-types support">
|
||||
<link rel="next" href="conversion_traits___traits_class.html" title="conversion_traits<> traits class">
|
||||
<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>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -24,7 +27,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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<>
|
||||
<a name="boost_numericconversion.bounds___traits_class"></a><a href="bounds___traits_class.html" title="bounds<>
|
||||
traits class">bounds<>
|
||||
traits class</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
@@ -35,7 +39,7 @@
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.bounds___traits_class.introduction"></a><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.introduction" title="Introduction">Introduction</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
To determine the ranges of numeric types with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>
|
||||
@@ -55,10 +59,12 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.bounds___traits_class.traits_class_bounds_n_"></a><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.traits_class_bounds_n_" title="traits
|
||||
class bounds<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>
|
||||
<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>
|
||||
<span class="keyword">static</span> <span class="identifier">N</span> <span class="identifier">lowest</span> <span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">implementation_defined</span><span class="special">;</span> <span class="special">}</span>
|
||||
@@ -67,8 +73,8 @@
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<a name="boost_numericconversion.bounds___traits_class.traits_class_bounds_n_.members"></a><h5>
|
||||
<a name="id2849558"></a>
|
||||
<a class="link" href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.traits_class_bounds_n_.members">Members</a>
|
||||
<a name="id2626382"></a>
|
||||
<a 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>
|
||||
@@ -113,12 +119,13 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.bounds___traits_class.examples"></a><a href="bounds___traits_class.html#boost_numericconversion.bounds___traits_class.examples" title="Examples">Examples</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The following example demonstrates the use of <code class="computeroutput"><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">bounds</span><span class="special"><></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>
|
||||
<pre class="programlisting">
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</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">bounds</span><span class="special">.</span><span class="identifier">hpp</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">limits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>conversion_traits<> traits class</title>
|
||||
<title>conversion_traits<>
|
||||
traits class</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="bounds___traits_class.html" title="bounds<> traits class">
|
||||
<link rel="next" href="numeric_converter_policy_classes.html" title="Numeric Converter Policy Classes">
|
||||
<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>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -24,7 +27,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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<>
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class"></a><a href="conversion_traits___traits_class.html" title="conversion_traits<>
|
||||
traits class">conversion_traits<>
|
||||
traits class</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
@@ -33,7 +37,7 @@
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types" title="Types">Types</a>
|
||||
</h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum">enumeration
|
||||
@@ -57,10 +61,12 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_int_float_mixture_enum" title="enumeration
|
||||
int_float_mixture_enum">enumeration
|
||||
int_float_mixture_enum</a>
|
||||
</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">int_float_mixture_enum</span>
|
||||
<span class="special">{</span>
|
||||
@@ -77,10 +83,12 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_sign_mixture_enum" title="enumeration
|
||||
sign_mixture_enum">enumeration
|
||||
sign_mixture_enum</a>
|
||||
</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">sign_mixture_enum</span>
|
||||
<span class="special">{</span>
|
||||
@@ -97,10 +105,12 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.enumeration_udt_builtin_mixture_enum" title="enumeration
|
||||
udt_builtin_mixture_enum">enumeration
|
||||
udt_builtin_mixture_enum</a>
|
||||
</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">udt_builtin_mixture_enum</span>
|
||||
<span class="special">{</span>
|
||||
@@ -117,10 +127,12 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_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
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_int_float_mixture__" title="template
|
||||
class int_float_mixture<>">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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_float_mixture</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special"><</span><span class="identifier">int_float_mixture_enum</span><span class="special">,</span> <span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">></span> <span class="special">{}</span> <span class="special">;</span>
|
||||
@@ -129,22 +141,24 @@
|
||||
</span></pre>
|
||||
<p>
|
||||
Classifying <code class="computeroutput"><span class="identifier">S</span></code> and <code class="computeroutput"><span class="identifier">T</span></code> as either integral or float, this
|
||||
<a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
Integral Constant</a> indicates the combination of these attributes.
|
||||
<a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's Integral
|
||||
Constant</a> indicates the combination of these attributes.
|
||||
</p>
|
||||
<p>
|
||||
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
|
||||
is of enumeration type <a class="link" href="conversion_traits___traits_class.html#numeric_conversion_traits_int_float_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">int_float_mixture_enum</span></code></a>
|
||||
is of enumeration type <a href="conversion_traits___traits_class.html#numeric_conversion_traits_int_float_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">int_float_mixture_enum</span></code></a>
|
||||
</p>
|
||||
</div>
|
||||
<a name="numeric_conversion_traits_class_sign_mixture"></a><p>
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__"></a><a 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
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_sign_mixture__" title="template
|
||||
class sign_mixture<>">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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="identifier">sign_mixture</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special"><</span><span class="identifier">sign_mixture_enum</span><span class="special">,</span> <span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">></span> <span class="special">{}</span> <span class="special">;</span>
|
||||
@@ -153,22 +167,24 @@
|
||||
</span></pre>
|
||||
<p>
|
||||
Classifying <code class="computeroutput"><span class="identifier">S</span></code> and <code class="computeroutput"><span class="identifier">T</span></code> as either signed or unsigned, this
|
||||
<a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
Integral Constant</a> indicates the combination of these attributes.
|
||||
<a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's Integral
|
||||
Constant</a> indicates the combination of these attributes.
|
||||
</p>
|
||||
<p>
|
||||
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
|
||||
is of enumeration type <a class="link" href="conversion_traits___traits_class.html#numeric_conversion_traits_sign_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">sign_mixture_enum</span></code></a>
|
||||
is of enumeration type <a href="conversion_traits___traits_class.html#numeric_conversion_traits_sign_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">sign_mixture_enum</span></code></a>
|
||||
</p>
|
||||
</div>
|
||||
<a name="numeric_conversion_traits_class_udt_builtin_mixture"></a><p>
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__"></a><a 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
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_udt_builtin_mixture__" title="template
|
||||
class udt_builtin_mixture<>">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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="identifier">udt_builtin_mixture</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special"><</span><span class="identifier">udt_builtin__mixture_enum</span><span class="special">,</span> <span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">></span> <span class="special">{}</span> <span class="special">;</span>
|
||||
@@ -177,22 +193,24 @@
|
||||
</span></pre>
|
||||
<p>
|
||||
Classifying <code class="computeroutput"><span class="identifier">S</span></code> and <code class="computeroutput"><span class="identifier">T</span></code> as either user-defined or builtin,
|
||||
this <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
this <a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's
|
||||
Integral Constant</a> indicates the combination of these attributes.
|
||||
</p>
|
||||
<p>
|
||||
Its <code class="computeroutput"><span class="special">::</span><span class="identifier">value</span></code>
|
||||
is of enumeration type <a class="link" href="conversion_traits___traits_class.html#numeric_conversion_traits_udt_builtin_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">udt_builtin_mixture_enum</span></code></a>
|
||||
is of enumeration type <a href="conversion_traits___traits_class.html#numeric_conversion_traits_udt_builtin_mixture_enum"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">udt_builtin_mixture_enum</span></code></a>
|
||||
</p>
|
||||
</div>
|
||||
<a name="numeric_conversion_traits_is_subranged"></a><p>
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_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
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_is_subranged__" title="template
|
||||
class is_subranged<>">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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="identifier">is_subranged</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">bool_</span><span class="special"><</span><span class="identifier">impl</span><span class="special">-</span><span class="identifier">def</span><span class="special">-</span><span class="identifier">value</span><span class="special">></span> <span class="special">{}</span> <span class="special">;</span>
|
||||
@@ -206,7 +224,7 @@
|
||||
range.
|
||||
</p>
|
||||
<p>
|
||||
It is a boolean <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
It is a boolean <a href="../../../../../mpl/refmanual/integral-constant.html" target="_top">MPL's
|
||||
Integral Constant</a> .
|
||||
</p>
|
||||
<p>
|
||||
@@ -217,10 +235,12 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.types.template_class_conversion_traits__"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.types.template_class_conversion_traits__" title="template
|
||||
class conversion_traits<>">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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="identifier">conversion_traits</span>
|
||||
@@ -247,11 +267,11 @@
|
||||
direction: from a source type <code class="computeroutput"><span class="identifier">S</span></code>
|
||||
to a target type <code class="computeroutput"><span class="identifier">T</span></code>. It
|
||||
does not indicate the properties of a <span class="emphasis"><em>specific</em></span> conversion,
|
||||
but of the conversion direction. See <a class="link" href="definitions.html#numeric_conversion_definitions_subranged">Definitions</a>
|
||||
but of the conversion direction. See <a href="definitions.html#numeric_conversion_definitions_subranged">Definitions</a>
|
||||
for details.
|
||||
</p>
|
||||
<p>
|
||||
The traits class provides the following <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
The traits class provides the following <a href="../../../../../mpl/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):
|
||||
@@ -280,7 +300,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Same as given by the traits class <a class="link" href="conversion_traits___traits_class.html#numeric_conversion_traits_class_int_float_mixture">int_float_mixture</a>
|
||||
Same as given by the traits class <a href="conversion_traits___traits_class.html#numeric_conversion_traits_class_int_float_mixture">int_float_mixture</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -292,7 +312,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Same as given by the traits class <a class="link" href="conversion_traits___traits_class.html#numeric_conversion_traits_class_sign_mixture">sign_mixture</a>
|
||||
Same as given by the traits class <a href="conversion_traits___traits_class.html#numeric_conversion_traits_class_sign_mixture">sign_mixture</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -304,16 +324,16 @@
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Same as given by the traits class <a class="link" href="conversion_traits___traits_class.html#numeric_conversion_traits_class_udt_builtin_mixture">udt_builtin_mixture</a>
|
||||
Same as given by the traits class <a href="conversion_traits___traits_class.html#numeric_conversion_traits_class_udt_builtin_mixture">udt_builtin_mixture</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<p>
|
||||
The traits class provides the following <a href="../../../../../mpl/doc/refmanual/integral-constant.html" target="_top">MPL's
|
||||
The traits class provides the following <a href="../../../../../mpl/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#numeric_conversion_definitions_range">Definitions</a>
|
||||
the relation between the Source and Target ranges (see <a href="definitions.html#numeric_conversion_definitions_range">Definitions</a>
|
||||
for details).
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
@@ -340,7 +360,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Same as given by <a class="link" href="conversion_traits___traits_class.html#numeric_conversion_traits_is_subranged">is_subranged</a>
|
||||
Same as given by <a href="conversion_traits___traits_class.html#numeric_conversion_traits_is_subranged">is_subranged</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -421,7 +441,7 @@
|
||||
<span class="keyword">const</span><span class="special">&</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
It represents the optimal argument type for the <a class="link" href="../index.html#numeric_conversion_converter">converter</a>
|
||||
It represents the optimal argument type for the <a href="../index.html#numeric_conversion_converter">converter</a>
|
||||
member functions.
|
||||
</p>
|
||||
<p>
|
||||
@@ -442,7 +462,7 @@
|
||||
This type is either target_type or target_type const&
|
||||
</p>
|
||||
<p>
|
||||
It represents the return type of the <a class="link" href="../index.html#numeric_conversion_converter">converter</a>
|
||||
It represents the return type of the <a href="../index.html#numeric_conversion_converter">converter</a>
|
||||
member functions.
|
||||
</p>
|
||||
<p>
|
||||
@@ -484,9 +504,10 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.conversion_traits___traits_class.examples"></a><a href="conversion_traits___traits_class.html#boost_numericconversion.conversion_traits___traits_class.examples" title="Examples">Examples</a>
|
||||
</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>
|
||||
<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>
|
||||
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>converter<> function object</title>
|
||||
<title>converter<>
|
||||
function object</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="definitions.html" title="Definitions">
|
||||
<link rel="next" href="type_requirements_and_user_defined_types_support.html" title="Type Requirements and User-defined-types support">
|
||||
<link rel="next" href="type_requirements_and_user_defined_types_support.html" title="Type
|
||||
Requirements and User-defined-types support">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -24,7 +26,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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<>
|
||||
<a name="boost_numericconversion.converter___function_object"></a><a href="converter___function_object.html" title="converter<>
|
||||
function object">converter<>
|
||||
function object</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
@@ -39,9 +42,10 @@
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.converter___function_object.synopsis"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span>
|
||||
@@ -80,14 +84,15 @@
|
||||
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="../index.html#numeric_coversion_converter_policies">policies</a>
|
||||
It can optionally take some <a href="../index.html#numeric_coversion_converter_policies">policies</a>
|
||||
which can be used to customize its behavior. The <code class="computeroutput"><span class="identifier">Traits</span></code>
|
||||
parameter is not a policy but the parameter that defines the conversion.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="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
|
||||
<a name="boost_numericconversion.converter___function_object.template_parameters"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.template_parameters" title="Template
|
||||
parameters">Template
|
||||
parameters</a>
|
||||
</h3></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
@@ -114,7 +119,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The <a class="link" href="definitions.html#numeric_conversion_definitions_numeric_types">Numeric
|
||||
The <a href="definitions.html#numeric_conversion_definitions_numeric_types">Numeric
|
||||
Type</a> which is the <span class="emphasis"><em>Target</em></span> of the conversion.
|
||||
</p>
|
||||
</td>
|
||||
@@ -127,7 +132,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The <a class="link" href="definitions.html#numeric_conversion_definitions_numeric_types">Numeric
|
||||
The <a href="definitions.html#numeric_conversion_definitions_numeric_types">Numeric
|
||||
Type</a> which is the <span class="emphasis"><em>Source</em></span> of the conversion.
|
||||
</p>
|
||||
</td>
|
||||
@@ -140,7 +145,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
This must be a conversion traits class with the interface of <a class="link" href="../index.html#numeric_conversion_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span></code></a>
|
||||
This must be a conversion traits class with the interface of <a href="../index.html#numeric_conversion_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">conversion_traits</span></code></a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -219,7 +224,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.converter___function_object.member_functions"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.member_functions" title="Member
|
||||
functions">Member
|
||||
functions</a>
|
||||
</h3></div></div></div>
|
||||
<div class="blockquote"><blockquote class="blockquote">
|
||||
@@ -248,7 +254,8 @@
|
||||
The implementation of this function is actually built from the policies and
|
||||
is basically as follows:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">result_type</span> <span class="identifier">converter</span><span class="special"><>::</span><span class="identifier">convert</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
|
||||
<pre class="programlisting">
|
||||
<span class="identifier">result_type</span> <span class="identifier">converter</span><span class="special"><>::</span><span class="identifier">convert</span> <span class="special">(</span> <span class="identifier">argument_type</span> <span class="identifier">s</span> <span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">validate_range</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span> <span class="comment">// Implemented by the internal range checking logic
|
||||
</span> <span class="comment">// (which also calls the OverflowHandler policy)
|
||||
@@ -279,29 +286,29 @@
|
||||
</p>
|
||||
</blockquote></div>
|
||||
<p>
|
||||
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
|
||||
This <a href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
|
||||
static member function determines if the value <code class="computeroutput"><span class="identifier">s</span></code>
|
||||
can be represented by the target type without overflow.
|
||||
</p>
|
||||
<p>
|
||||
It does not determine if the conversion is <span class="emphasis"><em>exact</em></span>; that
|
||||
is, it does not detect <span class="emphasis"><em>inexact</em></span> conversions, only <span class="emphasis"><em>out-of-range</em></span>
|
||||
conversions (see the <a class="link" href="definitions.html#numeric_conversion_definitions_roundoff">Definitions</a>
|
||||
conversions (see the <a href="definitions.html#numeric_conversion_definitions_roundoff">Definitions</a>
|
||||
for further details).
|
||||
</p>
|
||||
<p>
|
||||
The return value is of enum type <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_converter_policies_range_check_result"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">range_check_result</span></code></a>
|
||||
The return value is of enum type <a href="numeric_converter_policy_classes.html#numeric_conversion_converter_policies_range_check_result"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">range_check_result</span></code></a>
|
||||
</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>
|
||||
returns <code class="computeroutput"><span class="identifier">cInRange</span></code> directly.
|
||||
See the following <a class="link" href="converter___function_object.html#numeric_conversion_converter_range_checking_logic">table</a>
|
||||
See the following <a href="converter___function_object.html#numeric_conversion_converter_range_checking_logic">table</a>
|
||||
for more details.
|
||||
</p>
|
||||
<p>
|
||||
If the user supplied a <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
|
||||
If the user supplied a <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">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.
|
||||
@@ -323,9 +330,9 @@
|
||||
</p>
|
||||
</blockquote></div>
|
||||
<p>
|
||||
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
|
||||
This <a 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#numeric_conversion_policy_overflow_handler">OverflowHandler</a>
|
||||
<a href="numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler">OverflowHandler</a>
|
||||
policy class.
|
||||
</p>
|
||||
<p>
|
||||
@@ -333,7 +340,7 @@
|
||||
this is an empty inline function.
|
||||
</p>
|
||||
<p>
|
||||
If the user supplied a <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
|
||||
If the user supplied a <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">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
|
||||
@@ -355,11 +362,11 @@
|
||||
</p>
|
||||
</blockquote></div>
|
||||
<p>
|
||||
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
|
||||
This <a href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
|
||||
static member function performs the actual conversion.
|
||||
</p>
|
||||
<p>
|
||||
This function is externally supplied by the <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_policy_raw_converter">RawConverter</a>
|
||||
This function is externally supplied by the <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_raw_converter">RawConverter</a>
|
||||
policy class.
|
||||
</p>
|
||||
<p>
|
||||
@@ -378,14 +385,14 @@
|
||||
</p>
|
||||
</blockquote></div>
|
||||
<p>
|
||||
This <a class="link" href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
|
||||
This <a href="converter___function_object.html#numeric_conversion_converter_internal">internal</a>
|
||||
static member function, which is <span class="underline">only used</span>
|
||||
for <code class="computeroutput"><span class="keyword">float</span></code> to <code class="computeroutput"><span class="keyword">int</span></code>
|
||||
conversions, returns an <span class="emphasis"><em>integer</em></span> value of <span class="emphasis"><em><span class="underline">floating-point type</span></em></span> according to some
|
||||
rounding direction.
|
||||
</p>
|
||||
<p>
|
||||
This function is externally supplied by the <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_policy_float_to_int_rounder">Float2IntRounder</a>
|
||||
This function is externally supplied by the <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_float_to_int_rounder">Float2IntRounder</a>
|
||||
policy class which encapsulates the specific rounding mode.
|
||||
</p>
|
||||
<p>
|
||||
@@ -394,8 +401,8 @@
|
||||
<a name="numeric_conversion_converter_internal"></a><p>
|
||||
</p>
|
||||
<a name="boost_numericconversion.converter___function_object.member_functions.internal_member_functions"></a><h5>
|
||||
<a name="id2847442"></a>
|
||||
<a class="link" href="converter___function_object.html#boost_numericconversion.converter___function_object.member_functions.internal_member_functions">Internal
|
||||
<a name="id2624118"></a>
|
||||
<a href="converter___function_object.html#boost_numericconversion.converter___function_object.member_functions.internal_member_functions">Internal
|
||||
Member Functions</a>
|
||||
</h5>
|
||||
<p>
|
||||
@@ -408,7 +415,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.converter___function_object.range_checking_logic"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.range_checking_logic" title="Range
|
||||
Checking Logic">Range
|
||||
Checking Logic</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -457,9 +465,10 @@ float_to_float |--> subranged |--> ( s >= S(LowestT) ) && (
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.converter___function_object.examples"></a><a href="converter___function_object.html#boost_numericconversion.converter___function_object.examples" title="Examples">Examples</a>
|
||||
</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>
|
||||
<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>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> <span class="special">{</span>
|
||||
|
||||
@@ -3,19 +3,20 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Definitions</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="next" href="converter___function_object.html" title="converter<> function object">
|
||||
<link rel="next" href="converter___function_object.html" title="converter<>
|
||||
function object">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -24,7 +25,7 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_numericconversion.definitions"></a><a class="link" href="definitions.html" title="Definitions">Definitions</a>
|
||||
<a name="boost_numericconversion.definitions"></a><a href="definitions.html" title="Definitions">Definitions</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="definitions.html#boost_numericconversion.definitions.introduction">Introduction</a></span></dt>
|
||||
@@ -45,14 +46,13 @@
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_numericconversion.definitions.introduction"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.introduction" title="Introduction">Introduction</a>
|
||||
<a name="boost_numericconversion.definitions.introduction"></a><a href="definitions.html#boost_numericconversion.definitions.introduction" title="Introduction">Introduction</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
This section provides definitions of terms used in the Numeric Conversion
|
||||
library.
|
||||
</p>
|
||||
<div class="sidebar">
|
||||
<p class="title"><b></b></p>
|
||||
<p>
|
||||
<span class="bold"><strong>Notation</strong></span> <span class="underline">underlined
|
||||
text</span> denotes terms defined in the C++ standard.
|
||||
@@ -65,7 +65,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_numericconversion.definitions.types_and_values"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.types_and_values" title="Types and Values">Types
|
||||
<a name="boost_numericconversion.definitions.types_and_values"></a><a href="definitions.html#boost_numericconversion.definitions.types_and_values" title="Types
|
||||
and Values">Types
|
||||
and Values</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -164,7 +165,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_numericconversion.definitions.c___arithmetic_types"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.c___arithmetic_types" title="C++ Arithmetic Types">C++
|
||||
<a name="boost_numericconversion.definitions.c___arithmetic_types"></a><a href="definitions.html#boost_numericconversion.definitions.c___arithmetic_types" title="C++
|
||||
Arithmetic Types">C++
|
||||
Arithmetic Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -224,7 +226,8 @@
|
||||
or <code class="computeroutput"><span class="keyword">long</span></code>) are required to have
|
||||
the same value representation, that is:
|
||||
</p>
|
||||
<pre class="programlisting"> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">-</span><span class="number">3</span> <span class="special">;</span> <span class="comment">// suppose value representation is: 10011 (sign bit + 4 magnitude bits)
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">-</span><span class="number">3</span> <span class="special">;</span> <span class="comment">// suppose value representation is: 10011 (sign bit + 4 magnitude bits)
|
||||
</span><span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">u</span> <span class="special">=</span> <span class="identifier">i</span> <span class="special">;</span> <span class="comment">// u is required to have the same 10011 as its value representation.
|
||||
</span></pre>
|
||||
<p>
|
||||
@@ -263,7 +266,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_numericconversion.definitions.numeric_types"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.numeric_types" title="Numeric Types">Numeric
|
||||
<a name="boost_numericconversion.definitions.numeric_types"></a><a href="definitions.html#boost_numericconversion.definitions.numeric_types" title="Numeric
|
||||
Types">Numeric
|
||||
Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -294,8 +298,8 @@
|
||||
one arithmetic type.
|
||||
</li>
|
||||
<li>
|
||||
Has <a class="link" href="definitions.html#numeric_conversion_definitions_range">range</a>
|
||||
(possibly unbounded) and <a class="link" href="definitions.html#numeric_conversion_definitions_range">precision</a>
|
||||
Has <a href="definitions.html#numeric_conversion_definitions_range">range</a>
|
||||
(possibly unbounded) and <a href="definitions.html#numeric_conversion_definitions_range">precision</a>
|
||||
(possibly dynamic or unlimited).
|
||||
</li>
|
||||
<li>
|
||||
@@ -342,7 +346,8 @@
|
||||
The following examples clarify the differences between arithmetic and numeric
|
||||
types (and values):
|
||||
</p>
|
||||
<pre class="programlisting"><span class="comment">// A numeric type which is not an arithmetic type (is user-defined)
|
||||
<pre class="programlisting">
|
||||
<span class="comment">// A numeric type which is not an arithmetic type (is user-defined)
|
||||
</span><span class="comment">// and which is intended to represent integer numbers (i.e., an 'integer' numeric type)
|
||||
</span><span class="keyword">class</span> <span class="identifier">MyInt</span>
|
||||
<span class="special">{</span>
|
||||
@@ -371,7 +376,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_numericconversion.definitions.range_and_precision"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range and Precision">Range
|
||||
<a name="boost_numericconversion.definitions.range_and_precision"></a><a href="definitions.html#boost_numericconversion.definitions.range_and_precision" title="Range
|
||||
and Precision">Range
|
||||
and Precision</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -433,7 +439,8 @@
|
||||
of numeric values (of type <code class="computeroutput"><span class="identifier">T</span></code>)
|
||||
of the form:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">REP</span><span class="special">(</span><span class="identifier">T</span><span class="special">)={</span><span class="identifier">l</span><span class="special">,</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">l</span><span class="special">),</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">l</span><span class="special">)),...,</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">h</span><span class="special">)),</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">h</span><span class="special">),</span><span class="identifier">h</span><span class="special">}</span>
|
||||
<pre class="programlisting">
|
||||
<span class="identifier">REP</span><span class="special">(</span><span class="identifier">T</span><span class="special">)={</span><span class="identifier">l</span><span class="special">,</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">l</span><span class="special">),</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">next</span><span class="special">(</span><span class="identifier">l</span><span class="special">)),...,</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">h</span><span class="special">)),</span><span class="identifier">prev</span><span class="special">(</span><span class="identifier">h</span><span class="special">),</span><span class="identifier">h</span><span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
where <code class="computeroutput"><span class="identifier">l</span></code> and <code class="computeroutput"><span class="identifier">h</span></code> are respectively the lowest and highest
|
||||
@@ -533,7 +540,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations" title="Exact, Correctly Rounded and Out-Of-Range Representations">Exact,
|
||||
<a name="boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations"></a><a href="definitions.html#boost_numericconversion.definitions.exact__correctly_rounded_and_out_of_range_representations" title="Exact,
|
||||
Correctly Rounded and Out-Of-Range Representations">Exact,
|
||||
Correctly Rounded and Out-Of-Range Representations</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -699,7 +707,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_numericconversion.definitions.standard__numeric__conversions"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.standard__numeric__conversions" title="Standard (numeric) Conversions">Standard
|
||||
<a name="boost_numericconversion.definitions.standard__numeric__conversions"></a><a href="definitions.html#boost_numericconversion.definitions.standard__numeric__conversions" title="Standard
|
||||
(numeric) Conversions">Standard
|
||||
(numeric) Conversions</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -799,7 +808,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype"></a><a class="link" href="definitions.html#boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype" title="Subranged Conversion Direction, Subtype and Supertype">Subranged
|
||||
<a name="boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype"></a><a href="definitions.html#boost_numericconversion.definitions.subranged_conversion_direction__subtype_and_supertype" title="Subranged
|
||||
Conversion Direction, Subtype and Supertype">Subranged
|
||||
Conversion Direction, Subtype and Supertype</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Improved numeric_cast<></title>
|
||||
<title>Improved
|
||||
numeric_cast<></title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="numeric_converter_policy_classes.html" title="Numeric Converter Policy Classes">
|
||||
<link rel="next" href="../numeric_conversion/history_and_acknowledgments.html" title="History and Acknowledgments">
|
||||
<link rel="prev" href="numeric_converter_policy_classes.html" title="Numeric
|
||||
Converter Policy Classes">
|
||||
<link rel="next" href="../numeric_conversion/history_and_acknowledgments.html" title="History
|
||||
and Acknowledgments">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -24,7 +27,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.improved_numeric_cast__"></a><a href="improved_numeric_cast__.html" title="Improved
|
||||
numeric_cast<>">Improved
|
||||
numeric_cast<></a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
@@ -34,12 +38,12 @@
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.improved_numeric_cast__.introduction"></a><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.introduction" title="Introduction">Introduction</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The lack of preservation of range makes conversions between numeric types
|
||||
error prone. This is true for both implicit conversions and explicit conversions
|
||||
(through <code class="computeroutput"><span class="keyword">static_cast</span></code>). <a class="link" href="improved_numeric_cast__.html#numeric_conversion_numeric_cast"><code class="computeroutput"><span class="identifier">numeric_cast</span></code></a>
|
||||
(through <code class="computeroutput"><span class="keyword">static_cast</span></code>). <a href="improved_numeric_cast__.html#numeric_conversion_numeric_cast"><code class="computeroutput"><span class="identifier">numeric_cast</span></code></a>
|
||||
detects loss of range when a numeric type is converted, and throws an exception
|
||||
if the range cannot be preserved.
|
||||
</p>
|
||||
@@ -80,9 +84,10 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.improved_numeric_cast__.numeric_cast"></a><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.numeric_cast" title="numeric_cast">numeric_cast</a>
|
||||
</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>
|
||||
<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="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">converter</span><span class="special"><</span><span class="identifier">Target</span><span class="special">,</span><span class="identifier">Source</span><span class="special">>::</span><span class="identifier">result_type</span>
|
||||
<span class="identifier">numeric_cast</span> <span class="special">(</span> <span class="identifier">Source</span> <span class="identifier">arg</span> <span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
@@ -92,15 +97,15 @@
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">numeric_cast</span></code> returns the
|
||||
result of converting a value of type Source to a value of type Target. If
|
||||
out-of-range is detected, an exception is thrown (see <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_bad_numeric_cast">bad_numeric_cast</a>,
|
||||
<a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_negative_overflow">negative_overflow</a>
|
||||
and <a class="link" href="numeric_converter_policy_classes.html#numeric_conversion_possitive_overflow">positive_overflow</a>
|
||||
out-of-range is detected, an exception is thrown (see <a href="numeric_converter_policy_classes.html#numeric_conversion_bad_numeric_cast">bad_numeric_cast</a>,
|
||||
<a href="numeric_converter_policy_classes.html#numeric_conversion_negative_overflow">negative_overflow</a>
|
||||
and <a href="numeric_converter_policy_classes.html#numeric_conversion_possitive_overflow">positive_overflow</a>
|
||||
).
|
||||
</p>
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="boost_numericconversion.improved_numeric_cast__.examples"></a><a href="improved_numeric_cast__.html#boost_numericconversion.improved_numeric_cast__.examples" title="Examples">Examples</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The following example performs some typical conversions between numeric types:
|
||||
@@ -113,7 +118,8 @@
|
||||
include <iostream>
|
||||
</li>
|
||||
</ol></div>
|
||||
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric_cast</span><span class="special">;</span>
|
||||
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Numeric Converter Policy Classes</title>
|
||||
<title>Numeric
|
||||
Converter Policy Classes</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="conversion_traits___traits_class.html" title="conversion_traits<> traits class">
|
||||
<link rel="next" href="improved_numeric_cast__.html" title="Improved numeric_cast<>">
|
||||
<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>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -24,7 +27,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.numeric_converter_policy_classes"></a><a href="numeric_converter_policy_classes.html" title="Numeric
|
||||
Converter Policy Classes">Numeric
|
||||
Converter Policy Classes</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
@@ -43,10 +47,12 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.enum_range_check_result" title="enum
|
||||
range_check_result">enum
|
||||
range_check_result</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">range_check_result</span>
|
||||
<span class="special">{</span>
|
||||
@@ -65,7 +71,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_overflowhandler" title="Policy
|
||||
OverflowHandler">Policy
|
||||
OverflowHandler</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -78,7 +85,8 @@
|
||||
<p>
|
||||
It must have the following interface (it does not has to be a template class):
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">YourOverflowHandlerPolicy</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">struct</span> <span class="identifier">YourOverflowHandlerPolicy</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">range_check_result</span> <span class="special">)</span> <span class="special">;</span> <span class="comment">// throw bad_cast or derived
|
||||
</span><span class="special">}</span> <span class="special">;</span>
|
||||
@@ -89,7 +97,8 @@
|
||||
<p>
|
||||
These are the two overflow handler classes provided by the library:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">struct</span> <span class="identifier">def_overflow_handler</span>
|
||||
<span class="special">{</span>
|
||||
@@ -112,10 +121,11 @@
|
||||
</pre>
|
||||
<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
|
||||
<a href="numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler_important_note">(see
|
||||
IMPORTANT note)</a>
|
||||
</p>
|
||||
<a name="numeric_conversion_bad_numeric_cast"></a><a name="numeric_conversion_negative_overflow"></a><a name="numeric_conversion_possitive_overflow"></a><pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<a name="numeric_conversion_bad_numeric_cast"></a><a name="numeric_conversion_negative_overflow"></a><a name="numeric_conversion_possitive_overflow"></a><pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">bad_numeric_cast</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_cast</span>
|
||||
@@ -177,7 +187,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder" title="Policy
|
||||
Float2IntRounder">Policy
|
||||
Float2IntRounder</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -190,7 +201,8 @@
|
||||
<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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="identifier">YourFloat2IntRounderPolicy</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">S</span> <span class="identifier">source_type</span> <span class="special">;</span>
|
||||
@@ -217,7 +229,8 @@
|
||||
objects.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">S</span><span class="special">></span>
|
||||
@@ -274,8 +287,8 @@
|
||||
<span class="special">}</span> <span class="special">}</span> <span class="comment">// namespace numeric, namespace boost
|
||||
</span></pre>
|
||||
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder.math_functions_used_by_the_rounder_policies"></a><h5>
|
||||
<a name="id2857201"></a>
|
||||
<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
|
||||
<a name="id2634042"></a>
|
||||
<a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_float2introunder.math_functions_used_by_the_rounder_policies">Math
|
||||
Functions used by the rounder policies</a>
|
||||
</h5>
|
||||
<p>
|
||||
@@ -293,7 +306,7 @@
|
||||
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="../index.html#numeric_conversion_requirements">User
|
||||
be visible. See also <a href="../index.html#numeric_conversion_requirements">User
|
||||
Defined Numeric Types</a> support.
|
||||
</p>
|
||||
</div>
|
||||
@@ -301,7 +314,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter" title="Policy
|
||||
RawConverter">Policy
|
||||
RawConverter</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -313,7 +327,8 @@
|
||||
<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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="identifier">YourRawConverterPolicy</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">::</span><span class="identifier">result_type</span> <span class="identifier">result_type</span> <span class="special">;</span>
|
||||
@@ -330,7 +345,8 @@
|
||||
<p>
|
||||
This is the only raw converter policy class provided by the library:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">numeric</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Traits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">raw_numeric_converter</span>
|
||||
@@ -351,7 +367,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker"></a><a href="numeric_converter_policy_classes.html#boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker" title="Policy
|
||||
UserRangeChecker">Policy
|
||||
UserRangeChecker</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -365,7 +382,8 @@
|
||||
<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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="identifier">YourRangeCheckerPolicy</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Traits</span><span class="special">::</span><span class="identifier">argument_type</span> <span class="identifier">argument_type</span> <span class="special">;</span>
|
||||
|
||||
+28
-20
@@ -1,21 +1,24 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Type Requirements and User-defined-types support</title>
|
||||
<title>Type
|
||||
Requirements and User-defined-types support</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="converter___function_object.html" title="converter<> function object">
|
||||
<link rel="next" href="bounds___traits_class.html" title="bounds<> traits class">
|
||||
<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>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -24,7 +27,8 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support"></a><a href="type_requirements_and_user_defined_types_support.html" title="Type
|
||||
Requirements and User-defined-types support">Type
|
||||
Requirements and User-defined-types support</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
@@ -37,7 +41,8 @@
|
||||
</dl></div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.type_requirements"></a><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.type_requirements" title="Type
|
||||
Requirements">Type
|
||||
Requirements</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -55,7 +60,8 @@
|
||||
policies uses unqualified calls to functions <code class="computeroutput"><span class="identifier">floor</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">ceil</span><span class="special">()</span></code>; but the standard functions are introduced
|
||||
in scope by a using directive:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">floor</span> <span class="special">;</span> <span class="keyword">return</span> <span class="identifier">floor</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span>
|
||||
<pre class="programlisting">
|
||||
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">floor</span> <span class="special">;</span> <span class="keyword">return</span> <span class="identifier">floor</span><span class="special">(</span><span class="identifier">s</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Therefore, for builtin arithmetic types, the std functions will be used.
|
||||
@@ -75,17 +81,18 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics"></a><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics" title="UDT's
|
||||
special semantics">UDT's
|
||||
special semantics</a>
|
||||
</h3></div></div></div>
|
||||
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.conversion_traits"></a><h5>
|
||||
<a name="id2848594"></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.conversion_traits">Conversion
|
||||
<a name="id2625386"></a>
|
||||
<a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.conversion_traits">Conversion
|
||||
Traits</a>
|
||||
</h5>
|
||||
<p>
|
||||
If a User Defined Type is involved in a conversion, it is <span class="emphasis"><em>assumed</em></span>
|
||||
that the UDT has <a class="link" href="definitions.html#numeric_conversion_definitions_range">wider
|
||||
that the UDT has <a href="definitions.html#numeric_conversion_definitions_range">wider
|
||||
range</a> than any built-in type, and consequently the values of some
|
||||
<code class="computeroutput"><span class="identifier">converter_traits</span><span class="special"><></span></code>
|
||||
members are hardwired regardless of the reality. The following table summarizes
|
||||
@@ -123,8 +130,8 @@
|
||||
above.
|
||||
</p>
|
||||
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.range_checking"></a><h5>
|
||||
<a name="id2848983"></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.range_checking">Range
|
||||
<a name="id2625806"></a>
|
||||
<a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.udt_s_special_semantics.range_checking">Range
|
||||
Checking</a>
|
||||
</h5>
|
||||
<p>
|
||||
@@ -134,7 +141,7 @@
|
||||
Target or Source are not built-in types, the bundled range checking of the
|
||||
<code class="computeroutput"><span class="identifier">converter</span><span class="special"><></span></code>
|
||||
function object is automatically disabled. However, it is possible to supply
|
||||
a user-defined range-checker. See <a class="link" href="type_requirements_and_user_defined_types_support.html#numeric_conversion_requirements_hooks">Special
|
||||
a user-defined range-checker. See <a href="type_requirements_and_user_defined_types_support.html#numeric_conversion_requirements_hooks">Special
|
||||
Policies</a>
|
||||
</p>
|
||||
</div>
|
||||
@@ -142,7 +149,8 @@
|
||||
</p>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies"></a><a href="type_requirements_and_user_defined_types_support.html#boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies" title="Special
|
||||
Policies">Special
|
||||
Policies</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@@ -158,7 +166,7 @@
|
||||
<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="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
|
||||
checking policy which will be used in place of the internal code. See <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
|
||||
policy for details.
|
||||
</p>
|
||||
<p>
|
||||
@@ -168,7 +176,7 @@
|
||||
<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#numeric_conversion_policy_raw_converter">RawConverter</a>
|
||||
raw converter policy. See <a href="numeric_converter_policy_classes.html#numeric_conversion_policy_raw_converter">RawConverter</a>
|
||||
policy for details
|
||||
</p>
|
||||
</div>
|
||||
|
||||
+19
-19
@@ -3,17 +3,17 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Chapter 1. Boost.NumericConversion</title>
|
||||
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" 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>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -27,7 +27,7 @@
|
||||
</h3></div></div>
|
||||
<div><p class="copyright">Copyright © 2004 -2007 Fernando Luis Cacciola Carballal</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="id2828909"></a><p>
|
||||
<a name="id2604942"></a><p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
@@ -119,49 +119,49 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="numeric_conversion.overview"></a><a href="index.html#numeric_conversion.overview" title="Overview">Overview</a>
|
||||
</h2></div></div></div>
|
||||
<p>
|
||||
The Boost Numeric Conversion library is a collection of tools to describe and
|
||||
perform conversions between values of different <a class="link" href="boost_numericconversion/definitions.html#numeric_conversion_definitions_numeric_types">numeric
|
||||
perform conversions between values of different <a href="boost_numericconversion/definitions.html#numeric_conversion_definitions_numeric_types">numeric
|
||||
types</a>.
|
||||
</p>
|
||||
<p>
|
||||
The library includes a special alternative for a subset of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><></span></code>, the <a class="link" href="index.html#numeric_conversion_bounds">bounds<></a>
|
||||
traits class, which provides a consistent way to obtain the <a class="link" href="boost_numericconversion/definitions.html#numeric_conversion_definitions_range">boundary</a>
|
||||
values for the <a class="link" href="boost_numericconversion/definitions.html#numeric_conversion_definitions_range">range</a>
|
||||
The library includes a special alternative for a subset of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><></span></code>, the <a href="index.html#numeric_conversion_bounds">bounds<></a>
|
||||
traits class, which provides a consistent way to obtain the <a href="boost_numericconversion/definitions.html#numeric_conversion_definitions_range">boundary</a>
|
||||
values for the <a href="boost_numericconversion/definitions.html#numeric_conversion_definitions_range">range</a>
|
||||
of a numeric type.
|
||||
</p>
|
||||
<p>
|
||||
It also includes a set of <a class="link" href="index.html#numeric_conversion_traits">trait classes</a>
|
||||
It also includes a set of <a href="index.html#numeric_conversion_traits">trait classes</a>
|
||||
which describes the compile-time properties of a conversion from a source to
|
||||
a target numeric type. Both <a class="link" href="boost_numericconversion/definitions.html#numeric_conversion_cpp_arithmetic_types">arithmetic</a>
|
||||
and <a class="link" href="boost_numericconversion/definitions.html#numeric_conversion_definitions_numeric_types">user-defined
|
||||
a target numeric type. Both <a href="boost_numericconversion/definitions.html#numeric_conversion_cpp_arithmetic_types">arithmetic</a>
|
||||
and <a href="boost_numericconversion/definitions.html#numeric_conversion_definitions_numeric_types">user-defined
|
||||
numeric types</a> can be used.
|
||||
</p>
|
||||
<p>
|
||||
A policy-based <a class="link" href="index.html#numeric_conversion_converter">converter</a>
|
||||
A policy-based <a href="index.html#numeric_conversion_converter">converter</a>
|
||||
object which uses <code class="computeroutput"><span class="identifier">conversion_traits</span></code>
|
||||
to select an optimized implementation is supplied. Such implementation uses
|
||||
an optimal range checking code suitable for the source/target combination.
|
||||
</p>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li>
|
||||
The converter's out-of-range behavior can be customized via an <a class="link" href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler">OverflowHandler</a>
|
||||
The converter's out-of-range behavior can be customized via an <a href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_overflow_handler">OverflowHandler</a>
|
||||
policy.
|
||||
</li>
|
||||
<li>
|
||||
For floating-point to integral conversions, the rounding mode can be selected
|
||||
via the <a class="link" href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_float_to_int_rounder">Float2IntRounder</a>
|
||||
via the <a href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_float_to_int_rounder">Float2IntRounder</a>
|
||||
policy.
|
||||
</li>
|
||||
<li>
|
||||
A custom low-level conversion routine (for UDTs for instance) can be passed
|
||||
via a <a class="link" href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_raw_converter">RawConverter</a>
|
||||
via a <a href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_raw_converter">RawConverter</a>
|
||||
policy.
|
||||
</li>
|
||||
<li>
|
||||
The optimized automatic range-checking logic can be overridden via a <a class="link" href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
|
||||
The optimized automatic range-checking logic can be overridden via a <a href="boost_numericconversion/numeric_converter_policy_classes.html#numeric_conversion_policy_user_range_checker">UserRangeChecker</a>
|
||||
policy.
|
||||
</li>
|
||||
</ul></div>
|
||||
@@ -178,7 +178,7 @@
|
||||
</p>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: October 10, 2008 at 20:47:59 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: February 12, 2008 at 22:56:38 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
||||
@@ -3,18 +3,19 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Bibliography</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="history_and_acknowledgments.html" title="History and Acknowledgments">
|
||||
<link rel="prev" href="history_and_acknowledgments.html" title="History
|
||||
and Acknowledgments">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -23,7 +24,7 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="numeric_conversion.bibliography"></a><a href="bibliography.html" title="Bibliography">Bibliography</a>
|
||||
</h2></div></div></div>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
<li>
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>History and Acknowledgments</title>
|
||||
<title>History
|
||||
and Acknowledgments</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.70.1">
|
||||
<link rel="start" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.NumericConversion">
|
||||
<link rel="prev" href="../boost_numericconversion/improved_numeric_cast__.html" title="Improved numeric_cast<>">
|
||||
<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>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -24,12 +26,13 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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
|
||||
<a name="numeric_conversion.history_and_acknowledgments"></a><a href="history_and_acknowledgments.html" title="History
|
||||
and Acknowledgments">History
|
||||
and Acknowledgments</a>
|
||||
</h2></div></div></div>
|
||||
<a name="numeric_conversion.history_and_acknowledgments.pre_formal_review"></a><h4>
|
||||
<a name="id2859653"></a>
|
||||
<a class="link" href="history_and_acknowledgments.html#numeric_conversion.history_and_acknowledgments.pre_formal_review">Pre-formal
|
||||
<a name="id2636499"></a>
|
||||
<a href="history_and_acknowledgments.html#numeric_conversion.history_and_acknowledgments.pre_formal_review">Pre-formal
|
||||
review</a>
|
||||
</h4>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
@@ -64,8 +67,8 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<a name="numeric_conversion.history_and_acknowledgments.post_formal_review"></a><h4>
|
||||
<a name="id2859805"></a>
|
||||
<a class="link" href="history_and_acknowledgments.html#numeric_conversion.history_and_acknowledgments.post_formal_review">Post-formal
|
||||
<a name="id2636651"></a>
|
||||
<a href="history_and_acknowledgments.html#numeric_conversion.history_and_acknowledgments.post_formal_review">Post-formal
|
||||
review</a>
|
||||
</h4>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
The lack of preservation of range makes conversions between numeric types
|
||||
error prone. This is true for both implicit conversions and explicit
|
||||
conversions (through `static_cast`).
|
||||
[link boost_numericconversion.improved_numeric_cast__.numeric_cast `numeric_cast`]
|
||||
[link numeric_conversion_numeric_cast `numeric_cast`]
|
||||
detects loss of range when a numeric type is converted, and throws an
|
||||
exception if the range cannot be preserved.
|
||||
|
||||
@@ -42,6 +42,8 @@ be no runtime overhead.
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_numeric_cast]
|
||||
|
||||
[section numeric_cast]
|
||||
|
||||
template<typename Target, typename Source> inline
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
]
|
||||
|
||||
[#numeric_conversion_requirements]
|
||||
|
||||
[section Type Requirements and User-defined-types support]
|
||||
|
||||
[section Type Requirements]
|
||||
@@ -47,7 +49,7 @@ is positive or not, and for this it evaluates the expression
|
||||
[heading Conversion Traits]
|
||||
|
||||
If a User Defined Type is involved in a conversion, it is ['assumed] that
|
||||
the UDT has [link boost_numericconversion.definitions.range_and_precision wider range]
|
||||
the UDT has [link numeric_conversion_definitions_range wider range]
|
||||
than any built-in type, and consequently the values
|
||||
of some `converter_traits<>` members are hardwired regardless of the reality.
|
||||
The following table summarizes this:
|
||||
@@ -78,10 +80,12 @@ checking logic when UDTs are involved in a conversion. Therefore, if either
|
||||
Target or Source are not built-in types, the bundled range checking of the
|
||||
`converter<>` function object is automatically disabled. However, it is possible
|
||||
to supply a user-defined range-checker. See
|
||||
[link boost_numericconversion.type_requirements_and_user_defined_types_support.special_policies Special Policies]
|
||||
[link numeric_conversion_requirements_hooks Special Policies]
|
||||
|
||||
[endsect]
|
||||
|
||||
[#numeric_conversion_requirements_hooks]
|
||||
|
||||
[section Special Policies]
|
||||
|
||||
There are two components of the `converter<>` class that might require special
|
||||
@@ -95,14 +99,14 @@ of the types.
|
||||
However, this internal logic is disabled when either type is User Defined.
|
||||
In this case, the user can specify an ['external] range checking policy which will be
|
||||
used in place of the internal code. See
|
||||
[link boost_numericconversion.numeric_converter_policy_classes.policy_userrangechecker UserRangeChecker] policy for details.
|
||||
[link numeric_conversion_policy_user_range_checker UserRangeChecker] policy for details.
|
||||
|
||||
The converter class performs the actual conversion using a Raw Converter policy.
|
||||
The default raw converter simply performs a `static_cast<Target>(source)`.
|
||||
|
||||
However, if the a UDT is involved, the `static_cast` might not work. In this case,
|
||||
the user can implement and pass a different raw converter policy.
|
||||
See [link boost_numericconversion.numeric_converter_policy_classes.policy_rawconverter RawConverter] policy for details
|
||||
See [link numeric_conversion_policy_raw_converter RawConverter] policy for details
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include <typeinfo> // for std::bad_cast
|
||||
|
||||
#include <boost/config/no_tr1/cmath.hpp> // for std::floor and std::ceil
|
||||
#include <cmath> // for std::floor and std::ceil
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#
|
||||
# Copyright Troy D. Straszheim
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See http://www.boost.org/LICENSE_1_0.txt
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
#-- Needed include directories for the tests
|
||||
boost_additional_test_dependencies(numeric BOOST_DEPENDS test)
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
boost_test_run(bounds_test)
|
||||
boost_test_run(traits_test)
|
||||
boost_test_run(converter_test)
|
||||
boost_test_run(udt_support_test)
|
||||
boost_test_run(numeric_conv_cast_test numeric_cast_test.cpp)
|
||||
boost_test_run(udt_example_0)
|
||||
Reference in New Issue
Block a user