mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-07-21 13:33:46 +00:00
fix issues and PRs
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?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.integer_concept">
|
||||
<section id="safe_numerics.integer">
|
||||
<title>Integer<T></title>
|
||||
|
||||
<?dbhtml stop-chunking?>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?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.numeric_concept">
|
||||
<section id="safe_numerics.numeric">
|
||||
<title>Numeric<T></title>
|
||||
|
||||
<?dbhtml stop-chunking?>
|
||||
@@ -18,9 +18,36 @@
|
||||
numeric types. Note that this concept is distinct from the C++ standard
|
||||
library type traits <code>is_integral</code> and
|
||||
<code>is_arithmetic</code>. These latter fulfill the requirement of the
|
||||
concept Numeric. But there are types T which fulfill this concept for
|
||||
which <code>is_arithmetic<T>::value == false</code>. For example see
|
||||
<code>safe_signed_integer<int></code>.</para>
|
||||
concept Numeric. But there may types which fulfill the concept of Numeric
|
||||
for which <code>std::is_arithmetic<T> == false</code>.</para>
|
||||
|
||||
<para>There are multiple reasons that we cannot use
|
||||
std::is_arithmetic<T> to identify number-like types for our
|
||||
purposes:</para>
|
||||
|
||||
<para><itemizedlist>
|
||||
<listitem>
|
||||
<para>The main purpose of our concept of Numeric<T> is to
|
||||
indicate that the range of type T is available to be queried. Since
|
||||
all specializations of Numeric<T> have a member in
|
||||
std::numeric_limits<T> we have access to this information when
|
||||
needed through the members std::numeric_limits<T>::min() and
|
||||
std::numeric_limits<T>::max().</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>There are types which do not fulfill std::arithmetic<T>
|
||||
(that is are not built-in numeric types) but still fulfill the
|
||||
concept of Numeric<T> (number like "things").</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>The library creates new result types for every expression
|
||||
which should also fulfill this concept Numeric. But
|
||||
is_arithmetic<T> cannot be specialized for user types.</para>
|
||||
</listitem>
|
||||
</itemizedlist>So is_arithmetic<T> does not correspond to the same
|
||||
set of types as Numeric<T> does.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
@@ -123,7 +150,7 @@
|
||||
|
||||
<entry><code>true_type</code></entry>
|
||||
|
||||
<entry><code>true</code> or <code>false</code></entry>
|
||||
<entry/>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
@@ -131,7 +158,7 @@
|
||||
|
||||
<entry><code>bool</code></entry>
|
||||
|
||||
<entry><code>true</code> or <code>false</code></entry>
|
||||
<entry>true</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
|
||||
+45
-24
@@ -14,19 +14,6 @@
|
||||
an arithmetically correct value or to trap in some way.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Model of</title>
|
||||
|
||||
<para><link linkend="safe_numerics.numeric_concept">Numeric</link></para>
|
||||
|
||||
<para><link linkend="safe_numerics.integer_concept">Integer</link></para>
|
||||
|
||||
<para>This type inherits all the notation, associated types and template
|
||||
parameters and valid expressions of <link
|
||||
linkend="safe_numerics.safe_numeric_concept">SafeNumeric</link> types. The
|
||||
following specify additional features of this type.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Notation</title>
|
||||
|
||||
@@ -56,6 +43,34 @@
|
||||
</informaltable>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Associated Types</title>
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
<colspec align="left" colwidth="1*"/>
|
||||
|
||||
<colspec align="left" colwidth="8*"/>
|
||||
|
||||
<tbody>
|
||||
<row>
|
||||
<entry><code>PP</code></entry>
|
||||
|
||||
<entry>Promotion Policy. A type which specifies the result type of
|
||||
an expression using safe types.</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><code>EP</code></entry>
|
||||
|
||||
<entry>Exception Policy. 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>
|
||||
|
||||
@@ -82,10 +97,10 @@
|
||||
<entry><code>T</code></entry>
|
||||
|
||||
<entry><link
|
||||
linkend="safe_numerics.integer_concept">Integer<T></link></entry>
|
||||
linkend="safe_numerics.integer_concept">std::is_integer<T></link></entry>
|
||||
|
||||
<entry><para>The underlying type. Currently only integer types are
|
||||
supported</para></entry>
|
||||
<entry><para>The underlying type. Currently only built-in integer
|
||||
types are supported</para></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
@@ -114,19 +129,25 @@
|
||||
<para>See examples below.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Model of</title>
|
||||
|
||||
<para><link linkend="safe_numerics.numeric_concept">Numeric</link></para>
|
||||
|
||||
<para><link linkend="safe_numerics.numeric_concept">Integer</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><T>
|
||||
type requirements. Note that all these expressions are
|
||||
<code>constexpr</code>. Thus, the result type of such an expression will
|
||||
be another safe type. The actual type of the result of such an expression
|
||||
<para>Implements all expressions and only those expressions supported by
|
||||
the base type T. Note that all these expressions are
|
||||
<code>constexpr</code>. 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>
|
||||
|
||||
<para>When a binary operand is applied to two instances of safe<T, PP,
|
||||
EP>on of the following must be true:<itemizedlist>
|
||||
EP>one of the following must be true:<itemizedlist>
|
||||
<listitem>
|
||||
<para>The promotion policies of the two operands must be the same or
|
||||
one of them must be void</para>
|
||||
@@ -174,7 +195,7 @@
|
||||
#include <safe_integer.hpp>
|
||||
|
||||
void f(){
|
||||
using namespace boost::numeric;
|
||||
using namespace boost::safe_numerics;
|
||||
safe<int> j;
|
||||
try {
|
||||
safe<int> i;
|
||||
|
||||
@@ -17,19 +17,6 @@
|
||||
be used in any constexpr expression.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Model of</title>
|
||||
|
||||
<para><link linkend="safe_numerics.numeric_concept">Numeric</link></para>
|
||||
|
||||
<para><link linkend="safe_numerics.integer_concept">Integer</link></para>
|
||||
|
||||
<para>This type inherits all the notation, associated types and template
|
||||
parameters and valid expressions of <link
|
||||
linkend="safe_numerics.safe_numeric_concept">SafeNumeric</link> types. The
|
||||
following specify additional features of this type.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Associated Types</title>
|
||||
|
||||
@@ -114,21 +101,28 @@
|
||||
</informaltable>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Model of</title>
|
||||
|
||||
<para><link linkend="safe_numerics.numeric_concept">Numeric</link></para>
|
||||
|
||||
<para><link linkend="safe_numerics.integer_concept">Integer</link></para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Inherited Valid Expressions</title>
|
||||
|
||||
<para>safe literal types are immutable. Hence they only inherit those
|
||||
valid expressions which don't change the value. <emphasis>This excludes
|
||||
assignment, increment, and decrement and all unary operators except unary
|
||||
-, + and ~</emphasis>. Other than that, they can be used anywhere a <link
|
||||
linkend="safe_numerics.safe_numeric_concept">SafeNumeric</link> type can
|
||||
be used. Note that the default promotion and exception policies are void.
|
||||
This is usually convenient since when a safe literal is used in a binary
|
||||
operation, this will inherit the policies of the other type. On the other
|
||||
hand, this can be inconvenient when operands of a binary expression are
|
||||
both safe literals. This will fail to compile since there are no
|
||||
designated promotion and exception policies. The way to address this to
|
||||
assign specific policies as in this example.</para>
|
||||
-, + and ~</emphasis>. Other than that, they can be used anywhere a Value
|
||||
type can be used. Note that the default promotion and exception policies
|
||||
are void. This is usually convenient since when a safe literal is used in
|
||||
a binary operation, this will inherit the policies of the other type. On
|
||||
the other hand, this can be inconvenient when operands of a binary
|
||||
expression are both safe literals. This will fail to compile since there
|
||||
are no designated promotion and exception policies. The way to address
|
||||
this to assign specific policies as in this example.</para>
|
||||
|
||||
<para><programlisting>template<typename T>
|
||||
using compile_time_value = safe_signed_literal<T>;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
</author>
|
||||
|
||||
<copyright>
|
||||
<year>2012-2018</year>
|
||||
<year>2012-2021</year>
|
||||
|
||||
<holder>Robert Ramey</holder>
|
||||
</copyright>
|
||||
|
||||
@@ -97,6 +97,16 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<row>
|
||||
<entry><code>T</code></entry>
|
||||
|
||||
<entry><link
|
||||
linkend="safe_numerics.integer_concept">std::is_integer<T></link></entry>
|
||||
|
||||
<entry><para>The underlying type. Currently only built-in integer
|
||||
types are supported</para></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><code>MIN</code></entry>
|
||||
|
||||
@@ -159,11 +169,27 @@
|
||||
<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. Thus, 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>
|
||||
<para>Implements all expressions and only those expressions supported by
|
||||
the base type T. Note that all these expressions are
|
||||
<code>constexpr</code>. 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>
|
||||
|
||||
<para>When a binary operand is applied to two instances of A
|
||||
<code>safe_signed_range<MIN, MAX, PP, EP></code> or
|
||||
<code>safe_unsigned_range<MIN, MAX, PP, EP></code> one of the
|
||||
following must be true:<itemizedlist>
|
||||
<listitem>
|
||||
<para>The promotion policies of the two operands must be the same or
|
||||
one of them must be void</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>The exception policies of the two operands must be the same or
|
||||
one of them must be void</para>
|
||||
</listitem>
|
||||
</itemizedlist>If either of the above is not true, a compile error will
|
||||
result.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<a name="safe_numerics.bibliography"></a>Bibliography</h2></div></div></div>
|
||||
<div class="bibliography">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="idm446913557584"></a>Bibliography</h3></div></div></div>
|
||||
<a name="idm462682823936"></a>Bibliography</h3></div></div></div>
|
||||
<div class="biblioentry">
|
||||
<a name="coker"></a><p>[<abbr class="abbrev">Coker</abbr>] <span class="author"><span class="firstname">Zack</span> <span class="surname">Coker</span>. </span><span class="author"><span class="firstname">Samir</span> <span class="surname">Hasan</span>. </span><span class="author"><span class="firstname">Jeffrey</span> <span class="surname">Overbey</span>. </span><span class="author"><span class="firstname">Munawar</span> <span class="surname">Hafiz</span>. </span><span class="author"><span class="firstname">Christian</span> <span class="surname">Kästner</span>. </span><span class="title"><i>
|
||||
<a href="http://www.cert.org/secure-coding/publications/books/secure-coding-c-c-second-edition.cfm?" target="_top">
|
||||
|
||||
@@ -21,35 +21,35 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.checked_arithmetic"></a>Checked Arithmetic</h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm446914376672">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm446914375344">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm446914373344">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm446914372192">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm446914354928">Notes</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm446914353360">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm446914124944">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm446914123216">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm462683643008">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm462683641680">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm462683639680">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm462683638528">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm462683621264">Notes</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm462683619696">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm462683391280">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm462683389552">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914376672"></a>Description</h4></div></div></div>
|
||||
<a name="idm462683643008"></a>Description</h4></div></div></div>
|
||||
<p>Perform binary operations on arithmetic types. Return either a valid
|
||||
result or an error code. Under no circumstances should an incorrect result
|
||||
be returned.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914375344"></a>Type requirements</h4></div></div></div>
|
||||
<a name="idm462683641680"></a>Type requirements</h4></div></div></div>
|
||||
<p>All template parameters of the functions must model <a class="link" href="">Numeric</a> type requirements.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914373344"></a>Complexity</h4></div></div></div>
|
||||
<a name="idm462683639680"></a>Complexity</h4></div></div></div>
|
||||
<p>Each function performs one and only one arithmetic operation.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914372192"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm462683638528"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting"><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">safe_numerics</span><span class="special">/</span><span class="identifier">checked_default</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="identifier">checked_result</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">checked</span><span class="special">::</span><span class="identifier">multiply</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span><span class="special">(</span><span class="number">24</span><span class="special">,</span> <span class="number">42</span><span class="special">)</span><span class="special">;</span>
|
||||
@@ -57,7 +57,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914354928"></a>Notes</h4></div></div></div>
|
||||
<a name="idm462683621264"></a>Notes</h4></div></div></div>
|
||||
<p>Some compilers have command line switches (e.g. -ftrapv) which
|
||||
enable special behavior such that erroneous integer operations are
|
||||
detected at run time. The library has been implemented in such a way that
|
||||
@@ -67,7 +67,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914353360"></a>Synopsis</h4></div></div></div>
|
||||
<a name="idm462683619696"></a>Synopsis</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="comment">// safe casting on primitive types</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="identifier">checked_result</span><span class="special"><</span><span class="identifier">R</span><span class="special">></span> <span class="keyword">constexpr</span> <span class="identifier">checked</span><span class="special">::</span><span class="identifier">cast</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span> <span class="special">&</span> <span class="identifier">t</span><span class="special">)</span><span class="special">;</span>
|
||||
@@ -133,12 +133,12 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914124944"></a>See Also</h4></div></div></div>
|
||||
<a name="idm462683391280"></a>See Also</h4></div></div></div>
|
||||
<p><a class="link" href="checked_result.html" title="checked_result<R>">checked_result<R></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914123216"></a>Header</h4></div></div></div>
|
||||
<a name="idm462683389552"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/checked_default.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/checked_default.hpp>
|
||||
</code></a></p>
|
||||
|
||||
@@ -21,16 +21,16 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.checked_integer_arithmetic"></a>safe_compare<T, U></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm446913909824">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm446913821616">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm446913814272">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm446913810768">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm446913809536">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm446913778880">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm462683176256">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm462683088080">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm462683080736">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm462683077232">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm462683076000">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm462683045344">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446913909824"></a>Synopsis</h4></div></div></div>
|
||||
<a name="idm462683176256"></a>Synopsis</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="comment">// compare any pair of integers</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">U</span><span class="special">></span>
|
||||
<span class="keyword">bool</span> <span class="keyword">constexpr</span> <span class="identifier">safe_compare</span><span class="special">::</span><span class="identifier">less_than</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span> <span class="special">&</span> <span class="identifier">lhs</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span> <span class="special">&</span> <span class="identifier">rhs</span><span class="special">)</span><span class="special">;</span>
|
||||
@@ -52,7 +52,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446913821616"></a>Description</h4></div></div></div>
|
||||
<a name="idm462683088080"></a>Description</h4></div></div></div>
|
||||
<p>Compare two primitive integers. These functions will return a
|
||||
correct result regardless of the type of the operands. Specifically it is
|
||||
guaranteed to return the correct arithmetic result when comparing signed
|
||||
@@ -67,19 +67,19 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446913814272"></a>Type requirements</h4></div></div></div>
|
||||
<a name="idm462683080736"></a>Type requirements</h4></div></div></div>
|
||||
<p>All template parameters of the functions must be C/C++ built-in
|
||||
integer types, <code class="computeroutput"><code class="computeroutput">char</code></code>,
|
||||
<code class="computeroutput"><code class="computeroutput">int</code></code> ....</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446913810768"></a>Complexity</h4></div></div></div>
|
||||
<a name="idm462683077232"></a>Complexity</h4></div></div></div>
|
||||
<p>Each function performs one and only one arithmetic operation.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446913809536"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm462683076000"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cassert</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">safe_compare</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446913778880"></a>Header</h4></div></div></div>
|
||||
<a name="idm462683045344"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/safe_compare.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/safe_compare.hpp>
|
||||
</code></a></p>
|
||||
|
||||
@@ -21,18 +21,18 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safenumerics.checked_result"></a>checked_result<R></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="checked_result.html#idm446914565632">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm446914547888">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm446914508784">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm446914500656">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm446914498944">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm446914450704">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm446914383600">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm446914381888">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm462683815536">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm462683797792">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm462683775200">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm462683767072">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm462683765360">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm462683717088">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm462683649984">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm462683648272">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914565632"></a>Description</h4></div></div></div>
|
||||
<a name="idm462683815536"></a>Description</h4></div></div></div>
|
||||
<p>checked_result is a special kind of variant class designed to hold
|
||||
the result of some operation. It can hold either the result of the
|
||||
operation or information on why the operation failed to produce a valid
|
||||
@@ -64,7 +64,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914547888"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462683797792"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -116,7 +116,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914508784"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm462683775200"></a>Template Parameters</h4></div></div></div>
|
||||
<p>R must model the type requirements of <a class="link" href="">Numeric</a></p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
@@ -135,12 +135,12 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914500656"></a>Model of</h4></div></div></div>
|
||||
<a name="idm462683767072"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="">Numeric</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914498944"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm462683765360"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>All expressions are <code class="computeroutput">constexpr</code>.</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
@@ -240,7 +240,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914450704"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm462683717088"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="comment">// Copyright (c) 2018 Robert Ramey</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Distributed under the Boost Software License, Version 1.0. (See</span>
|
||||
@@ -274,12 +274,12 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914383600"></a>See Also</h4></div></div></div>
|
||||
<a name="idm462683649984"></a>See Also</h4></div></div></div>
|
||||
<p><a class="link" href="exception_policy.html" title="ExceptionPolicy<EP>">ExceptionPolicy</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914381888"></a>Header</h4></div></div></div>
|
||||
<a name="idm462683648272"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/checked_result.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/checked_result.hpp></code></a></p>
|
||||
<p><a href="../../include/boost/safe_numerics/checked_result_operations.hpp" target="_top"><code class="computeroutput">#include
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.exception"></a>exception</h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="exception.html#idm446915010112">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm462684275680">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#safe_numerics.safe_numerics_error">enum class safe_numerics_error</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm446914979168">enum class safe_numerics_actions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm446914955312">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm446914951280">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm462684244736">enum class safe_numerics_actions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm462684220880">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm462684216848">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915010112"></a>Description</h4></div></div></div>
|
||||
<a name="idm462684275680"></a>Description</h4></div></div></div>
|
||||
<p>Here we describe the data types used to refer to exceptional
|
||||
conditions which might occur. Note that when we use the word "exception",
|
||||
we don't mean the C++ term which refers to a data type, but rather the
|
||||
@@ -115,7 +115,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914979168"></a>enum class safe_numerics_actions</h4></div></div></div>
|
||||
<a name="idm462684244736"></a>enum class safe_numerics_actions</h4></div></div></div>
|
||||
<p>The above error codes are classified into groups according to how
|
||||
such exceptions should be handled. The following table shows the possible
|
||||
actions that an error could be mapped to.</p>
|
||||
@@ -162,7 +162,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914955312"></a>See Also</h4></div></div></div>
|
||||
<a name="idm462684220880"></a>See Also</h4></div></div></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem"><p><a href="http://en.cppreference.com/w/cpp/error" target="_top">C++ Standard
|
||||
Library version</a> The C++ standard error handling
|
||||
@@ -174,7 +174,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914951280"></a>Header</h4></div></div></div>
|
||||
<a name="idm462684216848"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/exception.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/safe_numerics/exception.hpp></code></a></p>
|
||||
</div>
|
||||
|
||||
@@ -21,25 +21,25 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numeric.exception_policies"></a>exception_policy<AE, IDB, UB, UV></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="exception_policies.html#idm446914947552">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm446914946256">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm446914936720">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm446914920672">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm446914918960">Inherited Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm446914916848">Function Objects</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm446914871392">Policies Provided by the library</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm446914838304">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm462684213120">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm462684211824">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm462684202288">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm462684186240">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm462684184528">Inherited Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm462684182416">Function Objects</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm462684137376">Policies Provided by the library</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm462684104288">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914947552"></a>Description</h4></div></div></div>
|
||||
<a name="idm462684213120"></a>Description</h4></div></div></div>
|
||||
<p>Create a valid exception policy from 4 function objects. This
|
||||
specifies the actions to be taken for different types of invalid
|
||||
results.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914946256"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462684211824"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -64,7 +64,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914936720"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm462684202288"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -109,19 +109,19 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914920672"></a>Model of</h4></div></div></div>
|
||||
<a name="idm462684186240"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="exception_policy.html" title="ExceptionPolicy<EP>">ExceptionPolicy</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914918960"></a>Inherited Valid Expressions</h4></div></div></div>
|
||||
<a name="idm462684184528"></a>Inherited Valid Expressions</h4></div></div></div>
|
||||
<p>This class implements all the valid operations from the type
|
||||
requirements <a class="link" href="promotion_policy.html" title="PromotionPolicy<PP>">ExceptionPolicy</a>. Aside
|
||||
from these, there are no other operations implemented.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914916848"></a>Function Objects</h4></div></div></div>
|
||||
<a name="idm462684182416"></a>Function Objects</h4></div></div></div>
|
||||
<p>In order to create an exception policy, one needs some function
|
||||
objects. The library includes some appropriate examples of these:</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
@@ -176,7 +176,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914871392"></a>Policies Provided by the library</h4></div></div></div>
|
||||
<a name="idm462684137376"></a>Policies Provided by the library</h4></div></div></div>
|
||||
<p>The above function object can be composed into an exception policy
|
||||
by this class. The library provides common policies all ready to use. In
|
||||
the table below, the word "loose" is used to indicate that implementation
|
||||
@@ -254,7 +254,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914838304"></a>Header</h4></div></div></div>
|
||||
<a name="idm462684104288"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/exception_policies.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/exception_policies.hpp></code></a></p>
|
||||
</div>
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.exception_policy"></a>ExceptionPolicy<EP></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="exception_policy.html#idm446919896032">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm446919894624">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm446919885328">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm446919869536">dispatch<EP>(const safe_numerics_error & e, const char *
|
||||
<dt><span class="section"><a href="exception_policy.html#idm462684977056">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm462684975648">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm462684966288">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm462684950432">dispatch<EP>(const safe_numerics_error & e, const char *
|
||||
msg)</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm446919840864">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm446919827760">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm462684921760">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm462684892144">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919896032"></a>Description</h4></div></div></div>
|
||||
<a name="idm462684977056"></a>Description</h4></div></div></div>
|
||||
<p>The exception policy specifies what is to occur when a safe
|
||||
operation cannot return a valid result. A type is an ExceptionPolicy if it
|
||||
has functions for handling exceptional events that occur in the course of
|
||||
@@ -39,7 +39,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919894624"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462684975648"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -66,7 +66,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919885328"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm462684966288"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Whenever an operation yield an invalid result, one of the following
|
||||
functions will be invoked.</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
@@ -111,20 +111,20 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919869536"></a>dispatch<EP>(const safe_numerics_error & e, const char *
|
||||
<a name="idm462684950432"></a>dispatch<EP>(const safe_numerics_error & e, const char *
|
||||
msg)</h4></div></div></div>
|
||||
<p>This function is used to invoke the exception handling policy for a
|
||||
particular exception code.</p>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446919868304"></a>Synopsis</h5></div></div></div>
|
||||
<a name="idm462684949200"></a>Synopsis</h5></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">EP</span><span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="keyword">void</span>
|
||||
<span class="identifier">dispatch</span><span class="special"><</span><span class="identifier">EP</span><span class="special">></span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">safe_numerics_error</span> <span class="special">&</span> <span class="identifier">e</span><span class="special">,</span> <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">msg</span><span class="special">)</span><span class="special">;</span></pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446919850544"></a>Example of use</h5></div></div></div>
|
||||
<a name="idm462684931440"></a>Example of use</h5></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">safe_numerics</span><span class="special">/</span><span class="identifier">exception_policies</span><span class="special">.</span><span class="identifier">hpp</span><span class="string">"
|
||||
|
||||
dispatch<boost::numeric::loose_exception_policy>(
|
||||
@@ -135,7 +135,7 @@ dispatch<boost::numeric::loose_exception_policy>(
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919840864"></a>Models</h4></div></div></div>
|
||||
<a name="idm462684921760"></a>Models</h4></div></div></div>
|
||||
<p>The library header <a href="../../include/boost/safe_numerics/exception_policies.hpp" target="_top"><code class="computeroutput"><boost/safe_numerics/exception_policies.hpp>
|
||||
</code></a>contains a number of pre-made exception policies:</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
@@ -176,7 +176,7 @@ dispatch<boost::numeric::loose_exception_policy>(
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919827760"></a>Header</h4></div></div></div>
|
||||
<a name="idm462684892144"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/concept/exception_policy.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/safe_numerics/concepts/exception_policy.hpp>
|
||||
</code></a></p>
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@
|
||||
</h3></div></div>
|
||||
<div><p class="copyright">Copyright © 2012-2018 Robert Ramey</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="idm446925327472"></a><p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
|
||||
<a name="idm462689398624"></a><p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
|
||||
Software License</a></p>
|
||||
</div></div>
|
||||
</div></div>
|
||||
@@ -94,8 +94,8 @@
|
||||
<dt><span class="section"><a href="rationale.html">Rationale and FAQ</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html">Pending Issues</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm446913630256"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm446913589808">Other Pending Issues</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm462682896128"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm462682856528">Other Pending Issues</a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="acknowledgements.html">Acknowledgements</a></span></dt>
|
||||
<dt><span class="section"><a href="change_log.html">Release Log</a></span></dt>
|
||||
|
||||
@@ -21,16 +21,16 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.integer_concept"></a>Integer<T></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="integer_concept.html#idm446920110256">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm446920103728">Refinement of</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm446920102224">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm446920092080">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm446920039984">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm446920038384">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm462685202896">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm462685195456">Refinement of</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm462685193680">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm462685182912">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm462685126272">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="integer_concept.html#idm462685124544">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920110256"></a>Description</h4></div></div></div>
|
||||
<a name="idm462685202896"></a>Description</h4></div></div></div>
|
||||
<p>A type fulfills the requirements of an Integer if it has the
|
||||
properties of a integer.</p>
|
||||
<p>More specifically, a type T is Integer if there exists a
|
||||
@@ -47,12 +47,12 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920103728"></a>Refinement of</h4></div></div></div>
|
||||
<a name="idm462685195456"></a>Refinement of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric_concept.html" title="Numeric<T>">Numeric</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920102224"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462685193680"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -80,11 +80,11 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920092080"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm462685182912"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>In addition to the expressions defined in Integer, the following
|
||||
expression must be true. </p>
|
||||
<div class="table">
|
||||
<a name="idm446920091088"></a><p class="title"><b>Table 4. General</b></p>
|
||||
<a name="idm462685181888"></a><p class="title"><b>Table 4. General</b></p>
|
||||
<div class="table-contents"><table class="table" summary="General">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -104,7 +104,7 @@
|
||||
such defined operators shall implement the semantics as described
|
||||
below</p>
|
||||
<div class="table">
|
||||
<a name="idm446920084512"></a><p class="title"><b>Table 5. Unary Operator</b></p>
|
||||
<a name="idm462685175040"></a><p class="title"><b>Table 5. Unary Operator</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Unary Operator">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -126,7 +126,7 @@
|
||||
<p><br class="table-break">Any or all of the following binary operators MAY be defined. Any
|
||||
defined operators shall implement the semantics as described bellow</p>
|
||||
<div class="table">
|
||||
<a name="idm446920076112"></a><p class="title"><b>Table 6. Binary Operators</b></p>
|
||||
<a name="idm462685166224"></a><p class="title"><b>Table 6. Binary Operators</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Binary Operators">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -213,13 +213,13 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920039984"></a>Models</h4></div></div></div>
|
||||
<a name="idm462685126272"></a>Models</h4></div></div></div>
|
||||
<p><code class="computeroutput">int, safe<int>, safe_unsigned_range<0, 11>,
|
||||
checked_result<int> etc.</code></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920038384"></a>Header</h4></div></div></div>
|
||||
<a name="idm462685124544"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/concept/numeric.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/safe_numerics/concepts/integer.hpp> </code></a></p>
|
||||
</div>
|
||||
|
||||
+14
-14
@@ -21,17 +21,17 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.interval"></a>interval<R></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="interval.html#idm446914115760">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm446914112816">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm446914109456">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm446914092000">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm446914086160">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm446914006512">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm446913913680">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm462683382096">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm462683379152">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm462683375792">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm462683358336">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm462683352496">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm462683272880">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm462683180080">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914115760"></a>Description</h4></div></div></div>
|
||||
<a name="idm462683382096"></a>Description</h4></div></div></div>
|
||||
<p>A closed arithmetic interval represented by a pair of elements of
|
||||
type R. In principle, one should be able to use Boost.Interval library for
|
||||
this. But the functions in this library are not <code class="computeroutput">constexpr</code>.
|
||||
@@ -42,14 +42,14 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914112816"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm462683379152"></a>Template Parameters</h4></div></div></div>
|
||||
<p>R must model the type requirements of <a class="link" href="">Numeric</a>. Note this in principle
|
||||
includes any numeric type including floating point numbers and instances
|
||||
of <a class="link" href="checked_result.html" title="checked_result<R>"><code class="computeroutput">checked_result<R></code></a>.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914109456"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462683375792"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -94,7 +94,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914092000"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm462683358336"></a>Associated Types</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -109,7 +109,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914086160"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm462683352496"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Note that all expressions are constexpr.</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
@@ -284,7 +284,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446914006512"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm462683272880"></a>Example of use</h4></div></div></div>
|
||||
<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">cstdint</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cassert</span><span class="special">></span>
|
||||
@@ -304,7 +304,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446913913680"></a>Header</h4></div></div></div>
|
||||
<a name="idm462683180080"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/interval.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/interval.hpp></code></a></p>
|
||||
</div>
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
<a name="safe_numerics.numeric_concept"></a>Numeric<T></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="numeric_concept.html#safe_numerics.numeric.description">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm446916378768">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm446916368128">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm446916362832">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm446920121952">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm446920120272">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm446920118272">Note on Usage of <code class="computeroutput">std::numeric_limits</code></a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm462685337104">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm462685326464">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm462685321168">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm462685215760">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm462685213952">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric_concept.html#idm462685211760">Note on Usage of <code class="computeroutput">std::numeric_limits</code></a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
@@ -40,13 +40,31 @@
|
||||
numeric types. Note that this concept is distinct from the C++ standard
|
||||
library type traits <code class="computeroutput">is_integral</code> and
|
||||
<code class="computeroutput">is_arithmetic</code>. These latter fulfill the requirement of the
|
||||
concept Numeric. But there are types T which fulfill this concept for
|
||||
which <code class="computeroutput">is_arithmetic<T>::value == false</code>. For example see
|
||||
<code class="computeroutput">safe_signed_integer<int></code>.</p>
|
||||
concept Numeric. But there may types which fulfill the concept of Numeric
|
||||
for which <code class="computeroutput">std::is_arithmetic<T> == false</code>.</p>
|
||||
<p>There are multiple reasons that we cannot use
|
||||
std::is_arithmetic<T> to identify number-like types for our
|
||||
purposes:</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem"><p>The main purpose of our concept of Numeric<T> is to
|
||||
indicate that the range of type T is available to be queried. Since
|
||||
all specializations of Numeric<T> have a member in
|
||||
std::numeric_limits<T> we have access to this information when
|
||||
needed through the members std::numeric_limits<T>::min() and
|
||||
std::numeric_limits<T>::max().</p></li>
|
||||
<li class="listitem"><p>There are types which do not fulfill std::arithmetic<T>
|
||||
(that is are not built-in numeric types) but still fulfill the
|
||||
concept of Numeric<T> (number like "things"). </p></li>
|
||||
<li class="listitem"><p>The library creates new result types for every expression
|
||||
which should also fulfill this concept Numeric. But
|
||||
is_arithmetic<T> cannot be specialized for user types. </p></li>
|
||||
</ul></div>
|
||||
<p>So is_arithmetic<T> does not correspond to the same
|
||||
set of types as Numeric<T> does.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446916378768"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462685337104"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -74,7 +92,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446916368128"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm462685326464"></a>Associated Types</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -91,7 +109,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446916362832"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm462685321168"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>In addition to the expressions defined in <a href="http://www.sgi.com/tech/stl/Assignable.html" target="_top">Assignable</a> the
|
||||
following expressions must be valid. In the safe_numerics library, a type
|
||||
is considered Numeric if and only if it it has an entry in the
|
||||
@@ -103,7 +121,7 @@
|
||||
defined for built in numeric types while Numeric applies to any user types
|
||||
which "look like" a number.</p>
|
||||
<div class="table">
|
||||
<a name="idm446916361184"></a><p class="title"><b>Table 1. General</b></p>
|
||||
<a name="idm462685318880"></a><p class="title"><b>Table 1. General</b></p>
|
||||
<div class="table-contents"><table class="table" summary="General">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -119,16 +137,12 @@
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">Numeric<T></code></td>
|
||||
<td align="left"><code class="computeroutput">true_type</code></td>
|
||||
<td align="left">
|
||||
<code class="computeroutput">true</code> or <code class="computeroutput">false</code>
|
||||
</td>
|
||||
<td align="left"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">Numeric<T>()</code></td>
|
||||
<td align="left"><code class="computeroutput">bool</code></td>
|
||||
<td align="left">
|
||||
<code class="computeroutput">true</code> or <code class="computeroutput">false</code>
|
||||
</td>
|
||||
<td align="left">true</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">std::numeric_limits<T>::is_specialized</code></td>
|
||||
@@ -156,7 +170,7 @@
|
||||
<p>Any or all of the following unary operators MAY be defined. Any such
|
||||
defined operators shall implement the semantics as described below</p>
|
||||
<div class="table">
|
||||
<a name="idm446916336144"></a><p class="title"><b>Table 2. Unary Operators</b></p>
|
||||
<a name="idm462685296576"></a><p class="title"><b>Table 2. Unary Operators</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Unary Operators">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -205,7 +219,7 @@
|
||||
<br class="table-break"><p>Any or all of the following binary operators MAY be defined. Any
|
||||
defined operators shall implement the semantics as described bellow</p>
|
||||
<div class="table">
|
||||
<a name="idm447009860608"></a><p class="title"><b>Table 3. Binary Operators</b></p>
|
||||
<a name="idm462685275296"></a><p class="title"><b>Table 3. Binary Operators</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Binary Operators">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -322,20 +336,20 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920121952"></a>Models</h4></div></div></div>
|
||||
<a name="idm462685215760"></a>Models</h4></div></div></div>
|
||||
<p><code class="computeroutput">int, float, safe_signed_integer<int>,
|
||||
safe_signed_range<int>, checked_result<int>,
|
||||
etc.</code></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920120272"></a>Header</h4></div></div></div>
|
||||
<a name="idm462685213952"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/concept/numeric.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/safe_numerics/concepts/numeric.hpp> </code></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920118272"></a>Note on Usage of <code class="computeroutput">std::numeric_limits</code>
|
||||
<a name="idm462685211760"></a>Note on Usage of <code class="computeroutput">std::numeric_limits</code>
|
||||
</h4></div></div></div>
|
||||
<p>This in turn raises another question: Is it "legal" to specialize
|
||||
<code class="computeroutput">std::numeric_limits</code> for one's own types such as
|
||||
|
||||
@@ -21,14 +21,14 @@
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="safe_numerics.pending_issues"></a>Pending Issues</h2></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="pending_issues.html#idm446913630256"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm446913589808">Other Pending Issues</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm462682896128"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm462682856528">Other Pending Issues</a></span></dt>
|
||||
</dl></div>
|
||||
<p>The library is under development. There are a number of issues still
|
||||
pending.</p>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="idm446913630256"></a><code class="computeroutput">safe_base</code> Only Works for Scalar Types</h3></div></div></div>
|
||||
<a name="idm462682896128"></a><code class="computeroutput">safe_base</code> Only Works for Scalar Types</h3></div></div></div>
|
||||
<p>The following is paraphrased from an issue raised by Andrzej
|
||||
Krzemieński as a <a href="https://github.com/robertramey/safe_numerics/issues/44" target="_top">github
|
||||
issue</a>. It touches upon fundamental ideas behind the library and
|
||||
@@ -74,7 +74,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="idm446913589808"></a>Other Pending Issues</h3></div></div></div>
|
||||
<a name="idm462682856528"></a>Other Pending Issues</h3></div></div></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem"><p>The library is currently limited to integers. If there is
|
||||
interest, it could be extended to floats and possible to user
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<a name="safe_numerics.promotion_policies.automatic"></a>automatic</h4></div></div></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914706944"></a>Description</h5></div></div></div>
|
||||
<a name="idm462683972928"></a>Description</h5></div></div></div>
|
||||
<p>This type contains the meta-functions to return a type with
|
||||
sufficient capacity to hold the result of a given binary arithmetic
|
||||
operation.</p>
|
||||
@@ -73,12 +73,12 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914690288"></a>Model of</h5></div></div></div>
|
||||
<a name="idm462683956272"></a>Model of</h5></div></div></div>
|
||||
<p><a class="link" href="promotion_policy.html" title="PromotionPolicy<PP>">PromotionPolicy</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914688608"></a>Example of use</h5></div></div></div>
|
||||
<a name="idm462683954592"></a>Example of use</h5></div></div></div>
|
||||
<p>The following example illustrates the <code class="computeroutput">automatic</code> type
|
||||
being passed as a template parameter for the type
|
||||
<code class="computeroutput">safe<int></code>.</p>
|
||||
@@ -101,7 +101,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914646528"></a>Header</h5></div></div></div>
|
||||
<a name="idm462683912512"></a>Header</h5></div></div></div>
|
||||
<p><code class="computeroutput"><a href="../../include/boost/safe_numerics/automatic.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/safe_numerics/automatic.hpp> </code></a></code></p>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<a name="safe_numerics.promotion_policies.cpp"></a>cpp<int C, int S, int I, int L, int LL></h4></div></div></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914642720"></a>Description</h5></div></div></div>
|
||||
<a name="idm462683908672"></a>Description</h5></div></div></div>
|
||||
<p>This policy is used to promote safe types in arithmetic expressions
|
||||
according to the rules in the C++ standard. But rather than using the
|
||||
native C++ standard types supported by the compiler, it uses types whose
|
||||
@@ -38,7 +38,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914639184"></a>Template Parameters</h5></div></div></div>
|
||||
<a name="idm462683905136"></a>Template Parameters</h5></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -81,12 +81,12 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914622176"></a>Model of</h5></div></div></div>
|
||||
<a name="idm462683888096"></a>Model of</h5></div></div></div>
|
||||
<p><a class="link" href="promotion_policy.html" title="PromotionPolicy<PP>">PromotionPolicy</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914620464"></a>Example of Use</h5></div></div></div>
|
||||
<a name="idm462683886384"></a>Example of Use</h5></div></div></div>
|
||||
<p>Consider the following problem. One is developing software which
|
||||
uses a very small microprocessor and a very limited C compiler. The chip
|
||||
is so small, you can't print anything from the code, log, debug or
|
||||
@@ -113,7 +113,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914616960"></a>Header</h5></div></div></div>
|
||||
<a name="idm462683883376"></a>Header</h5></div></div></div>
|
||||
<p><code class="computeroutput"><a href="../../include/boost/safe_numerics/cpp.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/cpp.hpp> </code></a></code></p>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<a name="safe_numerics.promotion_policies.native"></a>native</h4></div></div></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914833856"></a>Description</h5></div></div></div>
|
||||
<a name="idm462684099840"></a>Description</h5></div></div></div>
|
||||
<p>This type contains the functions to return a safe type corresponding
|
||||
to the C++ type resulting from a given arithmetic operation.</p>
|
||||
<p>Usage of this policy with safe types will produce the exact same
|
||||
@@ -33,7 +33,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914831824"></a>Model of</h5></div></div></div>
|
||||
<a name="idm462684097808"></a>Model of</h5></div></div></div>
|
||||
<p><a class="link" href="promotion_policy.html" title="PromotionPolicy<PP>">PromotionPolicy</a></p>
|
||||
<p>As an example of how this works consider C++ rules from section 5 of
|
||||
the standard - "usual arithmetic conversions".</p>
|
||||
@@ -52,7 +52,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914795456"></a>Example of use</h5></div></div></div>
|
||||
<a name="idm462684061440"></a>Example of use</h5></div></div></div>
|
||||
<p>The following example illustrates the <code class="computeroutput">native</code> type being
|
||||
passed as a template parameter for the type <code class="computeroutput">safe<int></code>.
|
||||
This example is slightly contrived in that <code class="computeroutput">safe<int></code>
|
||||
@@ -92,12 +92,12 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914711904"></a>Notes</h5></div></div></div>
|
||||
<a name="idm462683977888"></a>Notes</h5></div></div></div>
|
||||
<p>See Chapter 5, Expressions, C++ Standard</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446914710688"></a>Header</h5></div></div></div>
|
||||
<a name="idm462683976672"></a>Header</h5></div></div></div>
|
||||
<p><code class="computeroutput"><a href="../../include/boost/safe_numerics/native.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/native.hpp>
|
||||
</code></a></code></p>
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.promotion_policy"></a>PromotionPolicy<PP></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm446920034960">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm446920024656">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm446920015952">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm446919992768">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm446919899744">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm462685120784">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm462685110000">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm462685100784">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm462685075872">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm462684980816">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920034960"></a>Description</h4></div></div></div>
|
||||
<a name="idm462685120784"></a>Description</h4></div></div></div>
|
||||
<p>In C++ expressions, arguments must be of the same type. If they are
|
||||
not, all arguments are converted to a common type in accordance with rules
|
||||
of the C++ standard. For some applications of the safe numerics library,
|
||||
@@ -46,7 +46,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920024656"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462685110000"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -72,7 +72,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446920015952"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm462685100784"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Any operations which result in integers which cannot be represented
|
||||
as some Numeric type will throw an exception.These expressions return a
|
||||
type which can be used as the basis create a SafeNumeric type.</p>
|
||||
@@ -145,7 +145,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919992768"></a>Models</h4></div></div></div>
|
||||
<a name="idm462685075872"></a>Models</h4></div></div></div>
|
||||
<p>The library contains a number of pre-made promotion policies:</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
@@ -225,7 +225,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919899744"></a>Header</h4></div></div></div>
|
||||
<a name="idm462684980816"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/concept/promotion_policy.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/safe_numerics/concepts/promotion_policy.hpp>
|
||||
</code></a></p>
|
||||
|
||||
+33
-33
@@ -21,59 +21,59 @@
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="safe_numerics.rationale"></a>Rationale and FAQ</h2></div></div></div>
|
||||
<div class="qandaset">
|
||||
<a name="idm446913768896"></a><dl>
|
||||
<dt>1. <a href="rationale.html#idm446913768400">Is this really necessary? If I'm writing the program with the
|
||||
<a name="idm462683035312"></a><dl>
|
||||
<dt>1. <a href="rationale.html#idm462683034816">Is this really necessary? If I'm writing the program with the
|
||||
requisite care and competence, problems noted in the introduction will
|
||||
never arise. Should they arise, they should be fixed "at the source"
|
||||
and not with a "band aid" to cover up bad practice.</a>
|
||||
</dt>
|
||||
<dt>2. <a href="rationale.html#idm446913764896">Can safe types be used as drop-in replacements for built-in
|
||||
<dt>2. <a href="rationale.html#idm462683031312">Can safe types be used as drop-in replacements for built-in
|
||||
types?</a>
|
||||
</dt>
|
||||
<dt>3. <a href="rationale.html#idm446913762576">Why are there special types for literal such as
|
||||
<dt>3. <a href="rationale.html#idm462683028992">Why are there special types for literal such as
|
||||
safe_signed_literal<42>? Why not just use
|
||||
std::integral_const<int, 42>?</a>
|
||||
</dt>
|
||||
<dt>4. <a href="rationale.html#idm446913757440">Why is safe...literal needed at all? What's the matter with
|
||||
<dt>4. <a href="rationale.html#idm462683023856">Why is safe...literal needed at all? What's the matter with
|
||||
const safe<int>(42)?</a>
|
||||
</dt>
|
||||
<dt>5. <a href="rationale.html#idm446913752368">Are safe type operations constexpr? That is, can
|
||||
<dt>5. <a href="rationale.html#idm462683018784">Are safe type operations constexpr? That is, can
|
||||
they be invoked at compile time?</a>
|
||||
</dt>
|
||||
<dt>6. <a href="rationale.html#idm446913747952">Why define safe_literal?
|
||||
<dt>6. <a href="rationale.html#idm462683014368">Why define safe_literal?
|
||||
Isn't it effectively the same as
|
||||
std::integral_constant?</a>
|
||||
</dt>
|
||||
<dt>7. <a href="rationale.html#idm446913735520">Why is Boost.Convert not used?</a>
|
||||
<dt>7. <a href="rationale.html#idm462683001936">Why is Boost.Convert not used?</a>
|
||||
</dt>
|
||||
<dt>8. <a href="rationale.html#idm446913733488">Why is the library named "safe ..." rather than something like
|
||||
<dt>8. <a href="rationale.html#idm462682999904">Why is the library named "safe ..." rather than something like
|
||||
"checked ..." ?</a>
|
||||
</dt>
|
||||
<dt>9. <a href="rationale.html#idm446913731120">Given that the library is called "numerics" why is floating
|
||||
<dt>9. <a href="rationale.html#idm462682997536">Given that the library is called "numerics" why is floating
|
||||
point arithmetic not addressed?</a>
|
||||
</dt>
|
||||
<dt>10. <a href="rationale.html#idm446913726384">Isn't putting a defensive check just before any potential
|
||||
<dt>10. <a href="rationale.html#idm462682992800">Isn't putting a defensive check just before any potential
|
||||
undefined behavior often considered a bad practice?</a>
|
||||
</dt>
|
||||
<dt>11. <a href="rationale.html#idm446913723792">It looks like the implementation presumes two's complement
|
||||
<dt>11. <a href="rationale.html#idm462682990208">It looks like the implementation presumes two's complement
|
||||
arithmetic at the hardware level. So this library is not portable -
|
||||
correct? What about other hardware architectures?</a>
|
||||
</dt>
|
||||
<dt>12. <a href="rationale.html#idm446913721472">According to C/C++ standards, unsigned integers
|
||||
<dt>12. <a href="rationale.html#idm462682987888">According to C/C++ standards, unsigned integers
|
||||
cannot overflow - they are modular integers which "wrap around". Yet
|
||||
the safe numerics library detects and traps this behavior as errors.
|
||||
Why is that?</a>
|
||||
</dt>
|
||||
<dt>13. <a href="rationale.html#idm446913715248">Why does the library require C++14?</a>
|
||||
<dt>13. <a href="rationale.html#idm462682981664">Why does the library require C++14?</a>
|
||||
</dt>
|
||||
<dt>14. <a href="rationale.html#idm446913709376">This is a C++ library - yet you refer to C/C++. Which is
|
||||
<dt>14. <a href="rationale.html#idm462682975792">This is a C++ library - yet you refer to C/C++. Which is
|
||||
it?</a>
|
||||
</dt>
|
||||
<dt>15. <a href="rationale.html#idm446913637344">Some compilers (including gcc and clang) include builtin
|
||||
<dt>15. <a href="rationale.html#idm462682903760">Some compilers (including gcc and clang) include builtin
|
||||
functions for checked addition, multiplication, etc. Does this library
|
||||
use these intrinsics?</a>
|
||||
</dt>
|
||||
<dt>16. <a href="rationale.html#idm446913633568">Some compilers (including gcc and clang) included a builtin
|
||||
<dt>16. <a href="rationale.html#idm462682899984">Some compilers (including gcc and clang) included a builtin
|
||||
function for detecting constants. This seemed attractive to eliminate
|
||||
the requirement for the safe_literal type. Alas, these builtin
|
||||
functions are defined as macros. Constants passed through functions
|
||||
@@ -91,7 +91,7 @@
|
||||
<tbody>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913768400"></a><a name="idm446913768144"></a><p><b>1.</b></p>
|
||||
<a name="idm462683034816"></a><a name="idm462683034560"></a><p><b>1.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Is this really necessary? If I'm writing the program with the
|
||||
requisite care and competence, problems noted in the introduction will
|
||||
@@ -109,7 +109,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913764896"></a><a name="idm446913764640"></a><p><b>2.</b></p>
|
||||
<a name="idm462683031312"></a><a name="idm462683031056"></a><p><b>2.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Can safe types be used as drop-in replacements for built-in
|
||||
types?</p></td>
|
||||
@@ -124,7 +124,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913762576"></a><a name="idm446913762320"></a><p><b>3.</b></p>
|
||||
<a name="idm462683028992"></a><a name="idm462683028736"></a><p><b>3.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Why are there special types for literal such as
|
||||
<code class="computeroutput">safe_signed_literal<42></code>? Why not just use
|
||||
@@ -142,7 +142,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913757440"></a><a name="idm446913757184"></a><p><b>4.</b></p>
|
||||
<a name="idm462683023856"></a><a name="idm462683023600"></a><p><b>4.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Why is safe...literal needed at all? What's the matter with
|
||||
<code class="computeroutput">const safe<int>(42)</code>?</p></td>
|
||||
@@ -163,7 +163,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913752368"></a><a name="idm446913752112"></a><p><b>5.</b></p>
|
||||
<a name="idm462683018784"></a><a name="idm462683018528"></a><p><b>5.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Are safe type operations <code class="computeroutput">constexpr</code>? That is, can
|
||||
they be invoked at compile time?</p></td>
|
||||
@@ -177,7 +177,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913747952"></a><a name="idm446913747696"></a><p><b>6.</b></p>
|
||||
<a name="idm462683014368"></a><a name="idm462683014112"></a><p><b>6.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Why define <a class="link" href="safe_literal.html" title="safe_signed_literal<Value, PP , EP> and safe_unsigned_literal<Value, PP, EP>"><code class="computeroutput">safe_literal</code></a>?
|
||||
Isn't it effectively the same as
|
||||
@@ -209,7 +209,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913735520"></a><a name="idm446913735264"></a><p><b>7.</b></p>
|
||||
<a name="idm462683001936"></a><a name="idm462683001680"></a><p><b>7.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Why is Boost.Convert not used?</p></td>
|
||||
</tr>
|
||||
@@ -220,7 +220,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913733488"></a><a name="idm446913733232"></a><p><b>8.</b></p>
|
||||
<a name="idm462682999904"></a><a name="idm462682999648"></a><p><b>8.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Why is the library named "safe ..." rather than something like
|
||||
"checked ..." ?</p></td>
|
||||
@@ -235,7 +235,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913731120"></a><a name="idm446913730864"></a><p><b>9.</b></p>
|
||||
<a name="idm462682997536"></a><a name="idm462682997280"></a><p><b>9.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Given that the library is called "numerics" why is floating
|
||||
point arithmetic not addressed?</p></td>
|
||||
@@ -252,7 +252,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913726384"></a><a name="idm446913726128"></a><p><b>10.</b></p>
|
||||
<a name="idm462682992800"></a><a name="idm462682992544"></a><p><b>10.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Isn't putting a defensive check just before any potential
|
||||
undefined behavior often considered a bad practice?</p></td>
|
||||
@@ -267,7 +267,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913723792"></a><a name="idm446913723536"></a><p><b>11.</b></p>
|
||||
<a name="idm462682990208"></a><a name="idm462682989952"></a><p><b>11.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>It looks like the implementation presumes two's complement
|
||||
arithmetic at the hardware level. So this library is not portable -
|
||||
@@ -281,7 +281,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913721472"></a><a name="idm446913721216"></a><p><b>12.</b></p>
|
||||
<a name="idm462682987888"></a><a name="idm462682987632"></a><p><b>12.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>According to C/C++ standards, <code class="computeroutput">unsigned integers</code>
|
||||
cannot overflow - they are modular integers which "wrap around". Yet
|
||||
@@ -307,7 +307,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913715248"></a><a name="idm446913714992"></a><p><b>13.</b></p>
|
||||
<a name="idm462682981664"></a><a name="idm462682981408"></a><p><b>13.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Why does the library require C++14?</p></td>
|
||||
</tr>
|
||||
@@ -332,7 +332,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913709376"></a><a name="idm446913709120"></a><p><b>14.</b></p>
|
||||
<a name="idm462682975792"></a><a name="idm462682975536"></a><p><b>14.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>This is a C++ library - yet you refer to C/C++. Which is
|
||||
it?</p></td>
|
||||
@@ -395,7 +395,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913637344"></a><a name="idm446913637088"></a><p><b>15.</b></p>
|
||||
<a name="idm462682903760"></a><a name="idm462682903504"></a><p><b>15.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Some compilers (including gcc and clang) include builtin
|
||||
functions for checked addition, multiplication, etc. Does this library
|
||||
@@ -410,7 +410,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="idm446913633568"></a><a name="idm446913633312"></a><p><b>16.</b></p>
|
||||
<a name="idm462682899984"></a><a name="idm462682899728"></a><p><b>16.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Some compilers (including gcc and clang) included a builtin
|
||||
function for detecting constants. This seemed attractive to eliminate
|
||||
|
||||
+52
-33
@@ -21,33 +21,25 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.safe"></a>safe<T, PP, EP></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="safe.html#idm446919822832">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm446919820832">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm446919816720">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm446919809392">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm446919791840">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm446919785952">Examples of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm446915292192">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm462684887216">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm462684885248">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm462684877872">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm462684870784">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm462684853168">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm462684850560">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm462684845584">Examples of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm462684562640">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919822832"></a>Description</h4></div></div></div>
|
||||
<a name="idm462684887216"></a>Description</h4></div></div></div>
|
||||
<p>A <code class="computeroutput">safe<T, PP , EP></code> can be used anywhere a type T
|
||||
can be used. Any expression which uses this type is guaranteed to return
|
||||
an arithmetically correct value or to trap in some way.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919820832"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric_concept.html" title="Numeric<T>">Numeric</a></p>
|
||||
<p><a class="link" href="integer_concept.html" title="Integer<T>">Integer</a></p>
|
||||
<p>This type inherits all the notation, associated types and template
|
||||
parameters and valid expressions of <a class="link" href="">SafeNumeric</a> types. The
|
||||
following specify additional features of this type.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919816720"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462684885248"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -66,7 +58,29 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919809392"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm462684877872"></a>Associated Types</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
<col align="left">
|
||||
</colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">PP</code></td>
|
||||
<td align="left">Promotion Policy. A type which specifies the result type of
|
||||
an expression using safe types.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">EP</code></td>
|
||||
<td align="left">Exception Policy. A type containing members which are
|
||||
called when a correct result cannot be returned</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm462684870784"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
@@ -81,9 +95,9 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="computeroutput">T</code></td>
|
||||
<td align="left"><a class="link" href="integer_concept.html" title="Integer<T>">Integer<T></a></td>
|
||||
<td align="left"><p>The underlying type. Currently only integer types are
|
||||
supported</p></td>
|
||||
<td align="left"><a class="link" href="integer_concept.html" title="Integer<T>">std::is_integer<T></a></td>
|
||||
<td align="left"><p>The underlying type. Currently only built-in integer
|
||||
types are supported</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="computeroutput">PP</code></td>
|
||||
@@ -102,15 +116,20 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919791840"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Implements all expressions and only those expressions defined by the
|
||||
<a class="link" href="">SafeNumeric</a><T>
|
||||
type requirements. Note that all these expressions are
|
||||
<code class="computeroutput">constexpr</code>. Thus, the result type of such an expression will
|
||||
be another safe type. The actual type of the result of such an expression
|
||||
<a name="idm462684853168"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric_concept.html" title="Numeric<T>">Numeric</a></p>
|
||||
<p><a class="link" href="numeric_concept.html" title="Numeric<T>">Integer</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm462684850560"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Implements all expressions and only those expressions supported by
|
||||
the base type T. Note that all these expressions are
|
||||
<code class="computeroutput">constexpr</code>. 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.</p>
|
||||
<p>When a binary operand is applied to two instances of safe<T, PP,
|
||||
EP>on of the following must be true:</p>
|
||||
EP>one of the following must be true:</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem"><p>The promotion policies of the two operands must be the same or
|
||||
one of them must be void</p></li>
|
||||
@@ -122,7 +141,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446919785952"></a>Examples of use</h4></div></div></div>
|
||||
<a name="idm462684845584"></a>Examples of use</h4></div></div></div>
|
||||
<p>The most common usage would be safe<T> which uses the default
|
||||
promotion and exception policies. This type is meant to be a "drop-in"
|
||||
replacement of the intrinsic integer types. That is, expressions involving
|
||||
@@ -151,7 +170,7 @@
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">safe_integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="special">)</span><span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">safe_numerics</span><span class="special">;</span>
|
||||
<span class="identifier">safe</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">j</span><span class="special">;</span>
|
||||
<span class="keyword">try</span> <span class="special">{</span>
|
||||
<span class="identifier">safe</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">i</span><span class="special">;</span>
|
||||
@@ -276,7 +295,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm446915365168"></a>Adjust type promotion rules.</h5></div></div></div>
|
||||
<a name="idm462684635584"></a>Adjust type promotion rules.</h5></div></div></div>
|
||||
<p>Another way to avoid arithmetic errors like overflow is to promote
|
||||
types to larger sizes before doing the arithmetic.</p>
|
||||
<p>Stepping back, we can see that many of the cases of invalid
|
||||
@@ -311,7 +330,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915292192"></a>Header</h4></div></div></div>
|
||||
<a name="idm462684562640"></a>Header</h4></div></div></div>
|
||||
<p><code class="filename"><a href="../../include/boost/safe_numerics/safe_integer.hpp" target="_top">#include
|
||||
<boost/safe_numerics/safe_integer.hpp></a></code></p>
|
||||
</div>
|
||||
|
||||
+27
-30
@@ -22,18 +22,18 @@
|
||||
<a name="safe_numerics.safe_literal"></a>safe_signed_literal<Value, PP , EP> and
|
||||
safe_unsigned_literal<Value, PP, EP></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="safe_literal.html#idm446915091184">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm446915089680">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm446915085808">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm446915078816">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm446915061280">Inherited Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm446915029040">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm462684354608">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm462684353104">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm462684346192">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm462684328656">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm462684326048">Inherited Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm462684294608">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#safe_numerics.safe_literal.make_safe_literal"><code class="computeroutput">make_safe_literal(n, PP, EP) </code></a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm446915013424">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm462684279040">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915091184"></a>Description</h4></div></div></div>
|
||||
<a name="idm462684354608"></a>Description</h4></div></div></div>
|
||||
<p>A safe type which holds a literal value. This is required to be able
|
||||
to initialize other safe types in such a way that an exception code is not
|
||||
generated. It is also useful when creating constexpr versions of safe
|
||||
@@ -42,16 +42,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915089680"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric_concept.html" title="Numeric<T>">Numeric</a></p>
|
||||
<p><a class="link" href="integer_concept.html" title="Integer<T>">Integer</a></p>
|
||||
<p>This type inherits all the notation, associated types and template
|
||||
parameters and valid expressions of <a class="link" href="">SafeNumeric</a> types. The
|
||||
following specify additional features of this type.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915085808"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm462684353104"></a>Associated Types</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -73,7 +64,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915078816"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm462684346192"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -109,18 +100,24 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915061280"></a>Inherited Valid Expressions</h4></div></div></div>
|
||||
<a name="idm462684328656"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric_concept.html" title="Numeric<T>">Numeric</a></p>
|
||||
<p><a class="link" href="integer_concept.html" title="Integer<T>">Integer</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm462684326048"></a>Inherited Valid Expressions</h4></div></div></div>
|
||||
<p>safe literal types are immutable. Hence they only inherit those
|
||||
valid expressions which don't change the value. <span class="emphasis"><em>This excludes
|
||||
assignment, increment, and decrement and all unary operators except unary
|
||||
-, + and ~</em></span>. Other than that, they can be used anywhere a <a class="link" href="">SafeNumeric</a> type can
|
||||
be used. Note that the default promotion and exception policies are void.
|
||||
This is usually convenient since when a safe literal is used in a binary
|
||||
operation, this will inherit the policies of the other type. On the other
|
||||
hand, this can be inconvenient when operands of a binary expression are
|
||||
both safe literals. This will fail to compile since there are no
|
||||
designated promotion and exception policies. The way to address this to
|
||||
assign specific policies as in this example.</p>
|
||||
-, + and ~</em></span>. Other than that, they can be used anywhere a Value
|
||||
type can be used. Note that the default promotion and exception policies
|
||||
are void. This is usually convenient since when a safe literal is used in
|
||||
a binary operation, this will inherit the policies of the other type. On
|
||||
the other hand, this can be inconvenient when operands of a binary
|
||||
expression are both safe literals. This will fail to compile since there
|
||||
are no designated promotion and exception policies. The way to address
|
||||
this to assign specific policies as in this example.</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="keyword">using</span> <span class="identifier">compile_time_value</span> <span class="special">=</span> <span class="identifier">safe_signed_literal</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span><span class="special">;</span>
|
||||
|
||||
@@ -138,7 +135,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915029040"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm462684294608"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">safe_numerics</span><span class="special">/</span><span class="identifier">safe_integer_literal</span><span class="special">.</span><span class="identifier">hp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">constexpr</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">safe_numerics</span><span class="special">::</span><span class="identifier">safe_signed_literal</span><span class="special"><</span><span class="number">42</span><span class="special">></span> <span class="identifier">x</span><span class="special">;</span>
|
||||
@@ -154,7 +151,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915013424"></a>Header</h4></div></div></div>
|
||||
<a name="idm462684279040"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/safe_integer_literal.hpp" target="_top">#include
|
||||
<boost/safe_numerics/safe_integer_literal.hpp></a></p>
|
||||
</div>
|
||||
|
||||
+39
-21
@@ -22,18 +22,18 @@
|
||||
<a name="safe_numerics.safe_range"></a>safe_signed_range<MIN, MAX, PP, EP> and
|
||||
safe_unsigned_range<MIN, MAX, PP, EP></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="safe_range.html#idm446915288448">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm446915285568">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm446915278176">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm446915271088">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm446915249760">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm446915247152">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm446915244848">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm446915094944">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm462684558896">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm462684556016">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm462684548656">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm462684541568">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm462684517440">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm462684514832">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm462684508320">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm462684358368">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915288448"></a>Description</h4></div></div></div>
|
||||
<a name="idm462684558896"></a>Description</h4></div></div></div>
|
||||
<p>This type holds a signed or unsigned integer in the closed range
|
||||
[MIN, MAX]. A <code class="computeroutput">safe_signed_range<MIN, MAX, PP, EP></code> or
|
||||
<code class="computeroutput">safe_unsigned_range<MIN, MAX, PP, EP></code> can be used
|
||||
@@ -43,7 +43,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915285568"></a>Notation</h4></div></div></div>
|
||||
<a name="idm462684556016"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -62,7 +62,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915278176"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm462684548656"></a>Associated Types</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -84,7 +84,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915271088"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm462684541568"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -98,6 +98,12 @@
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">T</code></td>
|
||||
<td align="left"><a class="link" href="integer_concept.html" title="Integer<T>">std::is_integer<T></a></td>
|
||||
<td align="left"><p>The underlying type. Currently only built-in integer
|
||||
types are supported</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">MIN</code></td>
|
||||
<td align="left">must be a non-negative literal</td>
|
||||
<td align="left">The minimum non-negative integer value that this type may
|
||||
@@ -130,22 +136,34 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915249760"></a>Model of</h4></div></div></div>
|
||||
<a name="idm462684517440"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric_concept.html" title="Numeric<T>">Numeric</a></p>
|
||||
<p><a class="link" href="integer_concept.html" title="Integer<T>">Integer</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915247152"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Implements all expressions and only those expressions defined by the
|
||||
<a class="link" href="">SafeNumeric</a> type
|
||||
requirements. Thus, 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.</p>
|
||||
<a name="idm462684514832"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Implements all expressions and only those expressions supported by
|
||||
the base type T. Note that all these expressions are
|
||||
<code class="computeroutput">constexpr</code>. 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.</p>
|
||||
<p>When a binary operand is applied to two instances of A
|
||||
<code class="computeroutput">safe_signed_range<MIN, MAX, PP, EP></code> or
|
||||
<code class="computeroutput">safe_unsigned_range<MIN, MAX, PP, EP></code> one of the
|
||||
following must be true:</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem"><p>The promotion policies of the two operands must be the same or
|
||||
one of them must be void</p></li>
|
||||
<li class="listitem"><p>The exception policies of the two operands must be the same or
|
||||
one of them must be void</p></li>
|
||||
</ul></div>
|
||||
<p>If either of the above is not true, a compile error will
|
||||
result.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915244848"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm462684508320"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="comment">// Copyright (c) 2018 Robert Ramey</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Distributed under the Boost Software License, Version 1.0. (See</span>
|
||||
@@ -214,7 +232,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446915094944"></a>Header</h4></div></div></div>
|
||||
<a name="idm462684358368"></a>Header</h4></div></div></div>
|
||||
<p><code class="filename"><a href="../../include/boost/safe_numerics/safe_integer_range.hpp" target="_top">#include
|
||||
<boost/numeric/safe_numerics/safe_range.hpp></a></code></p>
|
||||
</div>
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.safety_critical_embedded_controller"></a>Safety Critical Embedded Controller</h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm446918105792">How a Stepper Motor Works</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm446918093664">Updating the Code</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm446918077392">Refactor for Testing</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm446918068640">Compiling on the Desktop</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm446917538160">Trapping Errors at Compile Time</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm446916416464">Summary</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm462687067936">How a Stepper Motor Works</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm462687055776">Updating the Code</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm462687039504">Refactor for Testing</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm462687030752">Compiling on the Desktop</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm462686500272">Trapping Errors at Compile Time</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm462685378640">Summary</a></span></dt>
|
||||
</dl></div>
|
||||
<p>Suppose we are given the task of creating stepper motor driver
|
||||
software to drive a robotic hand to be used in robotic micro surgery. The
|
||||
@@ -42,9 +42,9 @@
|
||||
and test the code on the desktop.</p>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446918105792"></a>How a Stepper Motor Works</h4></div></div></div>
|
||||
<a name="idm462687067936"></a>How a Stepper Motor Works</h4></div></div></div>
|
||||
<div class="figure">
|
||||
<a name="idm446918105152"></a><p class="title"><b>Figure 1. Stepper Motor</b></p>
|
||||
<a name="idm462687067296"></a><p class="title"><b>Figure 1. Stepper Motor</b></p>
|
||||
<div class="figure-contents"><div class="mediaobject" align="left"><table border="0" summary="manufactured viewport for HTML img" style="cellpadding: 0; cellspacing: 0;" width="50%"><tr><td align="left"><img src="StepperMotor.gif" align="left" width="216" alt="Stepper Motor"></td></tr></table></div></div>
|
||||
</div>
|
||||
<br class="figure-break"><p>A stepper motor controller emits a pulse which causes the motor to
|
||||
@@ -56,7 +56,7 @@
|
||||
motor is under load. Similarly, a loaded motor must be slowly decelerated
|
||||
down to a stop.</p>
|
||||
<div class="figure">
|
||||
<a name="idm446918100864"></a><p class="title"><b>Figure 2. Motion Profile</b></p>
|
||||
<a name="idm462687062976"></a><p class="title"><b>Figure 2. Motion Profile</b></p>
|
||||
<div class="figure-contents"><div class="mediaobject"><table border="0" summary="manufactured viewport for HTML img" style="cellpadding: 0; cellspacing: 0;" width="100%"><tr><td><img src="stepper_profile.png" width="100%" alt="Motion Profile"></td></tr></table></div></div>
|
||||
</div>
|
||||
<p><br class="figure-break"></p>
|
||||
@@ -86,7 +86,7 @@ On interrupt<br>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446918093664"></a>Updating the Code</h4></div></div></div>
|
||||
<a name="idm462687055776"></a>Updating the Code</h4></div></div></div>
|
||||
<p>Inspecting this <a href="../../example/motor.c" target="_top">code</a>, we
|
||||
find that it is written in a dialect of C rather than C itself. At the
|
||||
time this code was written, conforming versions of the C compiler were not
|
||||
@@ -123,7 +123,7 @@ On interrupt<br>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446918077392"></a>Refactor for Testing</h4></div></div></div>
|
||||
<a name="idm462687039504"></a>Refactor for Testing</h4></div></div></div>
|
||||
<p>In order to develop our test suite and execute the same code on the
|
||||
desktop and the target system we factor out the shared code as a separate
|
||||
module which will used in both environments without change. The shared
|
||||
@@ -143,7 +143,7 @@ On interrupt<br>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446918068640"></a>Compiling on the Desktop</h4></div></div></div>
|
||||
<a name="idm462687030752"></a>Compiling on the Desktop</h4></div></div></div>
|
||||
<p>Using the target environment to run tests is often very difficult or
|
||||
impossible due to limited resources. So software unit testing for embedded
|
||||
systems is very problematic and often skipped. The C language on our
|
||||
@@ -464,7 +464,7 @@ On interrupt<br>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446917538160"></a>Trapping Errors at Compile Time</h4></div></div></div>
|
||||
<a name="idm462686500272"></a>Trapping Errors at Compile Time</h4></div></div></div>
|
||||
<p>We can test the same code we're going to load into our target system
|
||||
on the desktop. We could build and execute a complete unit test suite. We
|
||||
could capture the output and graph it. We have the ability to make are
|
||||
@@ -1097,7 +1097,7 @@ On interrupt<br>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm446916416464"></a>Summary</h4></div></div></div>
|
||||
<a name="idm462685378640"></a>Summary</h4></div></div></div>
|
||||
<p>The intent of this case study is to show that the Safe Numerics
|
||||
Library can be an essential tool in validating the correctness of C/C++
|
||||
programs in all environments - including the most restricted.</p>
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="special">[</span><span class="special">]</span><span class="special">)</span><span class="special">{</span>
|
||||
<span class="comment">// problem: cannot recover from arithmetic errors</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"example 8: "</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"example 14: "</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"cannot detect compile time arithmetic errors"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Not using safe numerics"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
|
||||
Binary file not shown.
@@ -11,7 +11,7 @@
|
||||
|
||||
int main(int, const char *[]){
|
||||
// problem: cannot recover from arithmetic errors
|
||||
std::cout << "example 8: ";
|
||||
std::cout << "example 14: ";
|
||||
std::cout << "cannot detect compile time arithmetic errors" << std::endl;
|
||||
std::cout << "Not using safe numerics" << std::endl;
|
||||
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Boost Library Status Error Log</title>
|
||||
</head>
|
||||
<body bgcolor="#ffffff" text="#000000">
|
||||
<table border="0">
|
||||
<h1>Library Status: safe_numerics/example</h1>
|
||||
<b>Run Date:</b> 15:12:29 UTC, Saturday 07 November 2020
|
||||
<br></table>
|
||||
<br>
|
||||
<h2><a name="bin.v2/libs/safe_numerics/example/example91.test/clang-darwin-14/debug/threading-multi/visibility-hidden">bin.v2/libs/safe_numerics/example/example91.test/clang-darwin-14/debug/threading-multi/visibility-hidden</a></h2>
|
||||
<h3>Compiler output:</h3><pre>
|
||||
In file included from example91.cpp:47:
|
||||
./motor1.c:26:1: error: unknown type name 'int16'
|
||||
int16 motor_pos = 0; // absolute step number
|
||||
^
|
||||
./motor1.c:27:1: error: unknown type name 'int16'
|
||||
int16 pos_inc=0; // motor_pos increment
|
||||
^
|
||||
./motor1.c:28:1: error: unknown type name 'uint16'
|
||||
uint16 phase=0; // ccpPhase[phase_ix]
|
||||
^
|
||||
./motor1.c:29:1: error: unknown type name 'uint8'; did you mean 'uint'?
|
||||
uint8 phase_ix=0; // index to ccpPhase[]
|
||||
^~~~~
|
||||
uint
|
||||
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/types.h:92:33: note: 'uint' declared here
|
||||
typedef unsigned int uint; /* Sys V compatibility */
|
||||
^
|
||||
In file included from example91.cpp:47:
|
||||
./motor1.c:30:1: error: unknown type name 'uint8'; did you mean 'uint'?
|
||||
uint8 phase_inc; // phase_ix increment
|
||||
^~~~~
|
||||
uint
|
||||
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/types.h:92:33: note: 'uint' declared here
|
||||
typedef unsigned int uint; /* Sys V compatibility */
|
||||
^
|
||||
In file included from example91.cpp:47:
|
||||
./motor1.c:31:1: error: unknown type name 'uint8'; did you mean 'uint'?
|
||||
uint8 run_flg; // true while motor is running
|
||||
^~~~~
|
||||
uint
|
||||
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/types.h:92:33: note: 'uint' declared here
|
||||
typedef unsigned int uint; /* Sys V compatibility */
|
||||
^
|
||||
In file included from example91.cpp:47:
|
||||
./motor1.c:32:1: error: unknown type name 'uint16'
|
||||
uint16 ccpr; // copy of CCPR1&amp;2
|
||||
^
|
||||
./motor1.c:33:1: error: unknown type name 'uint16'
|
||||
uint16 c; // integer delay count
|
||||
^
|
||||
./motor1.c:34:1: error: unknown type name 'uint16'
|
||||
uint16 step_no; // progress of move
|
||||
^
|
||||
./motor1.c:35:1: error: unknown type name 'uint16'
|
||||
uint16 step_down; // start of down-ramp
|
||||
^
|
||||
./motor1.c:36:1: error: unknown type name 'uint16'
|
||||
uint16 move; // total steps to move
|
||||
^
|
||||
./motor1.c:37:1: error: unknown type name 'uint16'
|
||||
uint16 midpt; // midpoint of move
|
||||
^
|
||||
./motor1.c:38:1: error: unknown type name 'uint32'
|
||||
uint32 c32; // 24.8 fixed point delay count
|
||||
^
|
||||
./motor1.c:39:1: error: unknown type name 'int16'
|
||||
int16 denom; // 4.n+1 in ramp algo
|
||||
^
|
||||
./motor1.c:43:1: error: unknown type name 'uint16'
|
||||
uint16 const ccpPhase[] = {0x909, 0x908, 0x808, 0x809}; // 00,01,11,10
|
||||
^
|
||||
./motor1.c:48:1: error: unknown type name 'uint16'
|
||||
uint16 make16(uint8 l, uint8 r) {
|
||||
^
|
||||
./motor1.c:48:15: error: unknown type name 'uint8'; did you mean 'uint'?
|
||||
uint16 make16(uint8 l, uint8 r) {
|
||||
^~~~~
|
||||
uint
|
||||
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/types.h:92:33: note: 'uint' declared here
|
||||
typedef unsigned int uint; /* Sys V compatibility */
|
||||
^
|
||||
In file included from example91.cpp:47:
|
||||
./motor1.c:48:24: error: unknown type name 'uint8'; did you mean 'uint'?
|
||||
uint16 make16(uint8 l, uint8 r) {
|
||||
^~~~~
|
||||
uint
|
||||
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/types.h:92:33: note: 'uint' declared here
|
||||
typedef unsigned int uint; /* Sys V compatibility */
|
||||
^
|
||||
In file included from example91.cpp:47:
|
||||
./motor1.c:49:13: error: use of undeclared identifier 'uint16'
|
||||
return (uint16) l &lt;&lt; 8 + r;
|
||||
^
|
||||
./motor1.c:49:28: warning: operator '&lt;&lt;' has lower precedence than '+'; '+' will be evaluated first [-Wshift-op-parentheses]
|
||||
return (uint16) l &lt;&lt; 8 + r;
|
||||
~~ ~~^~~
|
||||
./motor1.c:49:28: note: place parentheses around the '+' expression to silence this warning
|
||||
return (uint16) l &lt;&lt; 8 + r;
|
||||
^
|
||||
( )
|
||||
./motor1.c:49:23: warning: expression result unused [-Wunused-value]
|
||||
return (uint16) l &lt;&lt; 8 + r;
|
||||
~ ^ ~~~~~
|
||||
fatal error: too many errors emitted, stopping now [-ferror-limit=]
|
||||
2 warnings and 20 errors generated.
|
||||
|
||||
"clang++" -x c++ -fvisibility-inlines-hidden -std=c++14 -Wall -Wc++0x-narrowing -fPIC -m64 -O0 -fno-inline -Wall -g -fvisibility=hidden -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/safe_numerics/example/example91.test/clang-darwin-14/debug/threading-multi/visibility-hidden/example91.o" "example91.cpp"
|
||||
|
||||
</pre>
|
||||
<h2><a name="bin.v2/libs/safe_numerics/example/example81.test/clang-darwin-14/debug/threading-multi/visibility-hidden">bin.v2/libs/safe_numerics/example/example81.test/clang-darwin-14/debug/threading-multi/visibility-hidden</a></h2>
|
||||
<h3>Compiler output:</h3><pre>
|
||||
In file included from example81.cpp:9:
|
||||
In file included from ../../../boost/safe_numerics/safe_integer.hpp:15:
|
||||
In file included from ../../../boost/safe_numerics/safe_base.hpp:17:
|
||||
../../../boost/safe_numerics/exception_policies.hpp:28:9: error: type 'boost::safe_numerics::trap_exception' does not provide a call operator
|
||||
AE()(e, msg);
|
||||
^~~~
|
||||
../../../boost/safe_numerics/exception_policies.hpp:138:17: note: in instantiation of member function 'boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;::on_arithmetic_error' requested here
|
||||
EP::on_arithmetic_error(e, msg);
|
||||
^
|
||||
../../../boost/safe_numerics/exception_policies.hpp:160:44: note: in instantiation of member function 'boost::safe_numerics::dispatch_switch::dispatch_case&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, boost::safe_numerics::safe_numerics_actions::arithmetic_error&gt;::invoke' requested here
|
||||
dispatch_switch::dispatch_case&lt;EP, a&gt;::invoke(E, msg);
|
||||
^
|
||||
../../../boost/safe_numerics/exception_policies.hpp:170:9: note: in instantiation of function template specialization 'boost::safe_numerics::dispatch&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, boost::safe_numerics::safe_numerics_error::positive_overflow_error&gt;' requested here
|
||||
dispatch&lt;EP, E&gt;(msg);
|
||||
^
|
||||
../../../boost/safe_numerics/checked_integer.hpp:68:29: note: in instantiation of function template specialization 'boost::safe_numerics::dispatch_and_return&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, int&gt;::invoke&lt;boost::safe_numerics::safe_numerics_error::positive_overflow_error&gt;' requested here
|
||||
F::template invoke&lt;safe_numerics_error::positive_overflow_error&gt;(
|
||||
^
|
||||
../../../boost/safe_numerics/checked_integer.hpp:148:31: note: in instantiation of member function 'boost::safe_numerics::heterogeneous_checked_operation&lt;int, -2147483648, 2147483647, int, boost::safe_numerics::dispatch_and_return&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, int&gt;, void&gt;::cast_impl_detail::cast_impl' requested here
|
||||
cast_impl_detail::cast_impl(
|
||||
^
|
||||
../../../boost/safe_numerics/safe_base_operations.hpp:269:8: note: in instantiation of member function 'boost::safe_numerics::heterogeneous_checked_operation&lt;int, -2147483648, 2147483647, int, boost::safe_numerics::dispatch_and_return&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, int&gt;, void&gt;::cast' requested here
|
||||
&gt;::cast(base_value(t));
|
||||
^
|
||||
../../../boost/safe_numerics/safe_base_operations.hpp:315:65: note: in instantiation of function template specialization 'boost::safe_numerics::casting_helper&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, int, boost::safe_numerics::safe_base&lt;int, -2147483648, 2147483647, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt;, boost::safe_numerics::safe_base&lt;int, -2147483648, 2147483647, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt; &gt;' requested here
|
||||
const std::pair&lt;result_base_type, result_base_type&gt; r = casting_helper&lt;
|
||||
^
|
||||
../../../boost/safe_numerics/safe_base_operations.hpp:380:13: note: in instantiation of member function 'boost::safe_numerics::addition_result&lt;boost::safe_numerics::safe_base&lt;int, -2147483648, 2147483647, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt;, boost::safe_numerics::safe_base&lt;int, -2147483648, 2147483647, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt; &gt;::return_value' requested here
|
||||
return_value(
|
||||
^
|
||||
../../../boost/safe_numerics/safe_base_operations.hpp:396:35: note: in instantiation of member function 'boost::safe_numerics::addition_result&lt;boost::safe_numerics::safe_base&lt;int, -2147483648, 2147483647, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt;, boost::safe_numerics::safe_base&lt;int, -2147483648, 2147483647, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt; &gt;::return_value' requested here
|
||||
return addition_result&lt;T, U&gt;::return_value(t, u);
|
||||
^
|
||||
example81.cpp:22:18: note: in instantiation of function template specialization 'boost::safe_numerics::operator+&lt;boost::safe_numerics::safe_base&lt;int, -2147483648, 2147483647, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt;, boost::safe_numerics::safe_base&lt;int, -2147483648, 2147483647, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt; &gt;' requested here
|
||||
safe_t z = x + y; // will fail to compile !
|
||||
^
|
||||
1 error generated.
|
||||
(failed-as-expected) ../../../bin.v2/libs/safe_numerics/example/example81.test/clang-darwin-14/debug/threading-multi/visibility-hidden/example81.o
|
||||
</pre>
|
||||
<h2><a name="bin.v2/libs/safe_numerics/example/example14.test/clang-darwin-14/debug/threading-multi/visibility-hidden">bin.v2/libs/safe_numerics/example/example14.test/clang-darwin-14/debug/threading-multi/visibility-hidden</a></h2>
|
||||
<h3>Compiler output:</h3><pre>
|
||||
example14.cpp:23:24: warning: division by zero is undefined [-Wdivision-by-zero]
|
||||
std::cout &lt;&lt; x / y; // will display "0"!
|
||||
^ ~
|
||||
1 warning generated.
|
||||
</pre>
|
||||
<h2><a name="bin.v2/libs/safe_numerics/example/example17.test/clang-darwin-14/debug/threading-multi/visibility-hidden">bin.v2/libs/safe_numerics/example/example17.test/clang-darwin-14/debug/threading-multi/visibility-hidden</a></h2>
|
||||
<h3>Compiler output:</h3><pre>
|
||||
In file included from example17.cpp:7:
|
||||
In file included from ../../../boost/safe_numerics/safe_integer.hpp:15:
|
||||
In file included from ../../../boost/safe_numerics/safe_base.hpp:17:
|
||||
../../../boost/safe_numerics/exception_policies.hpp:28:9: error: type 'boost::safe_numerics::trap_exception' does not provide a call operator
|
||||
AE()(e, msg);
|
||||
^~~~
|
||||
../../../boost/safe_numerics/exception_policies.hpp:138:17: note: in instantiation of member function 'boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;::on_arithmetic_error' requested here
|
||||
EP::on_arithmetic_error(e, msg);
|
||||
^
|
||||
../../../boost/safe_numerics/exception_policies.hpp:160:44: note: in instantiation of member function 'boost::safe_numerics::dispatch_switch::dispatch_case&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, boost::safe_numerics::safe_numerics_actions::arithmetic_error&gt;::invoke' requested here
|
||||
dispatch_switch::dispatch_case&lt;EP, a&gt;::invoke(E, msg);
|
||||
^
|
||||
../../../boost/safe_numerics/exception_policies.hpp:170:9: note: in instantiation of function template specialization 'boost::safe_numerics::dispatch&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, boost::safe_numerics::safe_numerics_error::positive_overflow_error&gt;' requested here
|
||||
dispatch&lt;EP, E&gt;(msg);
|
||||
^
|
||||
../../../boost/safe_numerics/checked_integer.hpp:68:29: note: in instantiation of function template specialization 'boost::safe_numerics::dispatch_and_return&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, int&gt;::invoke&lt;boost::safe_numerics::safe_numerics_error::positive_overflow_error&gt;' requested here
|
||||
F::template invoke&lt;safe_numerics_error::positive_overflow_error&gt;(
|
||||
^
|
||||
../../../boost/safe_numerics/checked_integer.hpp:148:31: note: in instantiation of member function 'boost::safe_numerics::heterogeneous_checked_operation&lt;int, -2147483648, 2147483647, long, boost::safe_numerics::dispatch_and_return&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, int&gt;, void&gt;::cast_impl_detail::cast_impl' requested here
|
||||
cast_impl_detail::cast_impl(
|
||||
^
|
||||
../../../boost/safe_numerics/safe_base_operations.hpp:51:16: note: in instantiation of member function 'boost::safe_numerics::heterogeneous_checked_operation&lt;int, -2147483648, 2147483647, long, boost::safe_numerics::dispatch_and_return&lt;boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt;, int&gt;, void&gt;::cast' requested here
|
||||
&gt;::cast(t);
|
||||
^
|
||||
../../../boost/safe_numerics/safe_base_operations.hpp:81:18: note: in instantiation of function template specialization 'boost::safe_numerics::validate_detail&lt;int, -2147483648, 2147483647, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt;::exception_possible::return_value&lt;long&gt;' requested here
|
||||
&gt;::type::return_value(t);
|
||||
^
|
||||
../../../boost/safe_numerics/safe_base_operations.hpp:169:8: note: in instantiation of function template specialization 'boost::safe_numerics::validate_detail&lt;int, -2147483648, 2147483647, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt;::return_value&lt;long&gt;' requested here
|
||||
&gt;::return_value(m_t);
|
||||
^
|
||||
example17.cpp:20:7: note: in instantiation of function template specialization 'boost::safe_numerics::safe_base&lt;long, -9223372036854775808, 9223372036854775807, boost::safe_numerics::native, boost::safe_numerics::exception_policy&lt;boost::safe_numerics::trap_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception, boost::safe_numerics::ignore_exception&gt; &gt;::operator int&lt;int, 0&gt;' requested here
|
||||
f(y); // could overflow so trap at compile time
|
||||
^
|
||||
1 error generated.
|
||||
(failed-as-expected) ../../../bin.v2/libs/safe_numerics/example/example17.test/clang-darwin-14/debug/threading-multi/visibility-hidden/example17.o
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -107,6 +107,12 @@ class safe_literal_impl;
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Main implementation
|
||||
|
||||
// note in the current version of the library, it is a requirement than type
|
||||
// type "Stored" be a scalar type. Problem is when violates this rule, the error message (on clang)
|
||||
// is "A non-type template parameter cannot have type ... " where ... is some non-scalar type
|
||||
// The example which triggered this investigation is safe<safe<int>> . It was difficult to make
|
||||
// the trip from the error message to the source of the problem, hence we're including this
|
||||
// comment here.
|
||||
template<
|
||||
class Stored,
|
||||
Stored Min,
|
||||
@@ -120,17 +126,6 @@ private:
|
||||
BOOST_CONCEPT_ASSERT((ExceptionPolicy<E>));
|
||||
Stored m_t;
|
||||
|
||||
template<
|
||||
class StoredX,
|
||||
StoredX MinX,
|
||||
StoredX MaxX,
|
||||
class PX, // promotion polic
|
||||
class EX // exception policy
|
||||
>
|
||||
friend class safe_base;
|
||||
|
||||
friend class std::numeric_limits<safe_base>;
|
||||
|
||||
template<class T>
|
||||
constexpr Stored validated_cast(const T & t) const;
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ template<class Stored, Stored Min, Stored Max, class P, class E>
|
||||
constexpr inline /*explicit*/ safe_base<Stored, Min, Max, P, E>::safe_base(){
|
||||
static_assert(
|
||||
std::is_arithmetic<Stored>(),
|
||||
"currently, safe numeric base types must be arithmetic types"
|
||||
"currently, safe numeric base types must currently be arithmetic types"
|
||||
);
|
||||
dispatch<E, safe_numerics_error::uninitialized_value>(
|
||||
"safe values must be initialized"
|
||||
@@ -175,7 +175,12 @@ constexpr inline /*explicit*/ safe_base<Stored, Min, Max, P, E>::safe_base(
|
||||
skip_validation
|
||||
) :
|
||||
m_t(rhs)
|
||||
{}
|
||||
{
|
||||
static_assert(
|
||||
std::is_arithmetic<Stored>(),
|
||||
"currently, safe numeric base types must currently be arithmetic types"
|
||||
);
|
||||
}
|
||||
|
||||
// construct an instance from an instance of a convertible underlying type.
|
||||
template<class Stored, Stored Min, Stored Max, class P, class E>
|
||||
@@ -188,7 +193,12 @@ template<class Stored, Stored Min, Stored Max, class P, class E>
|
||||
>
|
||||
constexpr inline /*explicit*/ safe_base<Stored, Min, Max, P, E>::safe_base(const T &t) :
|
||||
m_t(validated_cast(t))
|
||||
{}
|
||||
{
|
||||
static_assert(
|
||||
std::is_arithmetic<Stored>(),
|
||||
"currently, safe numeric base types must currently be arithmetic types"
|
||||
);
|
||||
}
|
||||
|
||||
// construct an instance of a safe type from a literal value
|
||||
template<class Stored, Stored Min, Stored Max, class P, class E>
|
||||
@@ -197,7 +207,11 @@ constexpr inline /*explicit*/ safe_base<Stored, Min, Max, P, E>::safe_base(
|
||||
const safe_literal_impl<T, N, Px, Ex> & t
|
||||
) :
|
||||
m_t(validated_cast(t))
|
||||
{}
|
||||
{ static_assert(
|
||||
std::is_arithmetic<Stored>(),
|
||||
"currently, safe numeric base types must currently be arithmetic types"
|
||||
);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// casting operators
|
||||
|
||||
@@ -76,7 +76,7 @@ constexpr inline less_than(const T & lhs, const U & rhs) {
|
||||
return safe_compare_detail::less_than<
|
||||
std::is_signed<T>::value,
|
||||
std::is_signed<U>::value
|
||||
>::template invoke(lhs, rhs);
|
||||
>:: invoke(lhs, rhs);
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
@@ -156,7 +156,7 @@ constexpr inline equal(const T & lhs, const U & rhs) {
|
||||
return safe_compare_detail::equal<
|
||||
std::numeric_limits<T>::is_signed,
|
||||
std::numeric_limits<U>::is_signed
|
||||
>::template invoke(lhs, rhs);
|
||||
>:: invoke(lhs, rhs);
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
|
||||
@@ -900,6 +900,7 @@ int main(){
|
||||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <utility> // declval
|
||||
@@ -942,4 +943,10 @@ int main() {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// #include <boost/safe_numerics/safe_integer.hpp>
|
||||
|
||||
// boost::safe_numerics::safe<boost::safe_numerics::safe<int>> y;
|
||||
|
||||
int main() {}
|
||||
|
||||
Reference in New Issue
Block a user