mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-22 03:32:24 +00:00
195 lines
5.5 KiB
XML
195 lines
5.5 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN"
|
|
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
|
<section id="safe_numerics.safe_unsigned_range">
|
|
<title>safe_unsigned_range<MIN, MAX, PP, EP></title>
|
|
|
|
<section>
|
|
<title>Description</title>
|
|
|
|
<para>This type holds an unsigned integer in the closed range [MIN, MAX].
|
|
A <code>safe_unsigned_range<MIN, MAX, PP, EP></code> can be used
|
|
anywhere an arithmetic type is permitted. Any expression which uses this
|
|
type is guarenteed to return an arithmetically correct value or trap in
|
|
some way.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Notation</title>
|
|
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<colspec align="left" colwidth="2*"/>
|
|
|
|
<colspec align="left" colwidth="10*"/>
|
|
|
|
<thead>
|
|
<row>
|
|
<entry align="left">Symbol</entry>
|
|
|
|
<entry align="left">Description</entry>
|
|
</row>
|
|
</thead>
|
|
|
|
<tbody>
|
|
<row>
|
|
<entry><code>MIN, MAX</code></entry>
|
|
|
|
<entry>Minimum and maximum unsigned values that the
|
|
safe_unsigned_range can represent.</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Associated Types</title>
|
|
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<colspec align="left" colwidth="2*"/>
|
|
|
|
<colspec align="left" colwidth="10*"/>
|
|
|
|
<tbody>
|
|
<row>
|
|
<entry><code>PP</code></entry>
|
|
|
|
<entry>A type which specifes the result type of an expression
|
|
using safe types.</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>EP</code></entry>
|
|
|
|
<entry>A type containing members which are called when a correct
|
|
result cannot be returned</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Template Parameters</title>
|
|
|
|
<informaltable>
|
|
<tgroup cols="3">
|
|
<colspec align="left" colwidth="2*"/>
|
|
|
|
<colspec align="left" colwidth="4*"/>
|
|
|
|
<colspec align="left" colwidth="6*"/>
|
|
|
|
<thead>
|
|
<row>
|
|
<entry align="left">Parameter</entry>
|
|
|
|
<entry align="left">Requirements</entry>
|
|
|
|
<entry>Description</entry>
|
|
</row>
|
|
</thead>
|
|
|
|
<tbody>
|
|
<row>
|
|
<entry><code>MIN</code></entry>
|
|
|
|
<entry>must be non-integer literal</entry>
|
|
|
|
<entry>The minimum non-negative integer value that this type may
|
|
hold</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>MAX</code></entry>
|
|
|
|
<entry>must be a non-negative literal</entry>
|
|
|
|
<entry>The maximum non-negative integer value that this type may
|
|
hold</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry/>
|
|
|
|
<entry>MIN <= MAX</entry>
|
|
|
|
<entry>must be a valid closed range</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>PP</code></entry>
|
|
|
|
<entry><link linkend="safe_numerics.numeric"><link
|
|
linkend="safe_numerics.promotion_policy">PromotionPolicy<PP></link></link></entry>
|
|
|
|
<entry><para>Default value is <link
|
|
linkend="safe_numerics.promotion_policy.models.native">boost::numeric::native</link></para></entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>EP</code></entry>
|
|
|
|
<entry><link linkend="safe_numerics.numeric"><link
|
|
linkend="safe_numerics.exception_policy">Exception
|
|
Policy<EP></link></link></entry>
|
|
|
|
<entry><para>Default value is <link
|
|
linkend="safe_numerics.exception_policy.models.thow_exception">boost::throw_exception</link></para></entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Model of</title>
|
|
|
|
<para><link linkend="safe_numerics.numeric">Integer</link></para>
|
|
|
|
<para><link
|
|
linkend="safe_numerics.safe_numeric_concept">SafeNumeric</link></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Valid Expressions</title>
|
|
|
|
<para>Implements all expressions and only those expressions defined by the
|
|
<link linkend="safe_numerics.safe_numeric_concept">SafeNumeric</link> type
|
|
requirements. This, the result type of such an expression will be another
|
|
safe type. The actual type of the result of such an expression will depend
|
|
upon the specific promotion policy template parameter.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Header</title>
|
|
|
|
<para><filename><ulink url="../../include/safe_range.hpp">#include
|
|
<safe/numeric/safe_range.hpp></ulink></filename></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Example of use</title>
|
|
|
|
<programlisting>#include <safe/numeric/safe_range.hpp>
|
|
|
|
void f(){
|
|
boost::numeric::safe_unsigned_range<7, 24> i;
|
|
// since the range is included in [0,255], the underlying type of i
|
|
// will be an unsigned char.
|
|
i = 0; // throws out_of_range exception
|
|
i = 9; // ok
|
|
i *= 9; // throws out_of_range exception
|
|
i = -1; // throws out_of_range exception
|
|
std::uint8_t j = 4;
|
|
auto k = i + j;
|
|
// These types use default promotion policy so standard C++ type promotion rules
|
|
// will be used in evaluating expressions. C++ type promotion rules mandate
|
|
// that the result of k = i + j when both are unsigned char types, will be another
|
|
// unsigned char type.
|
|
}</programlisting>
|
|
</section>
|
|
</section>
|