mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-07-21 13:33:46 +00:00
documentation updates and corrections
due mostly to Andrzej Krzemieński
This commit is contained in:
+7
-36
@@ -17,7 +17,7 @@
|
||||
<section>
|
||||
<title>Model of</title>
|
||||
|
||||
<para><link linkend="safe_numerics.numeric">Integer</link></para>
|
||||
<para><link linkend="safe_numerics.integer">Integer</link></para>
|
||||
|
||||
<para><link
|
||||
linkend="safe_numerics.safe_numeric_concept">SafeNumeric</link></para>
|
||||
@@ -57,34 +57,6 @@
|
||||
</informaltable>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Associated Types</title>
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
<colspec align="left" colwidth="1*"/>
|
||||
|
||||
<colspec align="left" colwidth="10*"/>
|
||||
|
||||
<tbody>
|
||||
<row>
|
||||
<entry><code>PP</code></entry>
|
||||
|
||||
<entry>A type which specifies the result type of an expression
|
||||
using safe types.</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><code>EP</code></entry>
|
||||
|
||||
<entry>A type containing members which are called when a correct
|
||||
result cannot be returned</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Template Parameters</title>
|
||||
|
||||
@@ -110,8 +82,8 @@
|
||||
<row>
|
||||
<entry><code>T</code></entry>
|
||||
|
||||
<entry><ulink
|
||||
url="http://en.cppreference.com/w/cpp/types/is_integral">Integer<T></ulink></entry>
|
||||
<entry><link
|
||||
linkend="safe_numerics.integer">Integer<T></link></entry>
|
||||
|
||||
<entry><para>The underlying type. Currently only integer types are
|
||||
supported</para></entry>
|
||||
@@ -120,8 +92,8 @@
|
||||
<row>
|
||||
<entry><code>PP</code></entry>
|
||||
|
||||
<entry><link linkend="safe_numerics.numeric"><link
|
||||
linkend="safe_numerics.promotion_policy">PromotionPolicy<PP></link></link></entry>
|
||||
<entry><link
|
||||
linkend="safe_numerics.promotion_policy">PromotionPolicy<PP></link></entry>
|
||||
|
||||
<entry><para>Optional promotion policy. Default value is <link
|
||||
linkend="safe_numerics.promotion_policies.native"><code>boost::numeric::native</code></link></para></entry>
|
||||
@@ -130,9 +102,8 @@
|
||||
<row>
|
||||
<entry><code>EP</code></entry>
|
||||
|
||||
<entry><link linkend="safe_numerics.numeric"><link
|
||||
linkend="safe_numerics.exception_policy">Exception
|
||||
Policy<EP></link></link></entry>
|
||||
<entry><link linkend="safe_numerics.exception_policy">Exception
|
||||
Policy<EP></link></entry>
|
||||
|
||||
<entry><para>Optional exception policy. Default value is <link
|
||||
linkend="safe_numerics.exception_policies.default_exception_policy"><code>boost::numeric::default_exception_policy</code></link></para></entry>
|
||||
|
||||
@@ -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="idm20546794640"></a>Bibliography</h3></div></div></div>
|
||||
<a name="idm310543406832"></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#idm20547635856">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm20547634528">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm20547632528">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm20547631376">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm20547614112">Notes</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm20547612544">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm20547367936">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm20547366208">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm310544248848">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm310544247520">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm310544245520">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm310544244368">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm310544227104">Notes</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm310544225136">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm310543996720">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_arithmetic.html#idm310543994992">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20547635856"></a>Description</h4></div></div></div>
|
||||
<a name="idm310544248848"></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="idm20547634528"></a>Type requirements</h4></div></div></div>
|
||||
<a name="idm310544247520"></a>Type requirements</h4></div></div></div>
|
||||
<p>All template parameters of the functions must model <a class="link" href="integer.html" title="Integer<T>">Numeric</a> type requirements.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20547632528"></a>Complexity</h4></div></div></div>
|
||||
<a name="idm310544245520"></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="idm20547631376"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm310544244368"></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="idm20547614112"></a>Notes</h4></div></div></div>
|
||||
<a name="idm310544227104"></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="idm20547612544"></a>Synopsis</h4></div></div></div>
|
||||
<a name="idm310544225136"></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="idm20547367936"></a>See Also</h4></div></div></div>
|
||||
<a name="idm310543996720"></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="idm20547366208"></a>Header</h4></div></div></div>
|
||||
<a name="idm310543994992"></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#idm20547152928">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm20547064720">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm20547057376">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm20547053872">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm20547052640">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm20547021984">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm310543781664">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm310543676944">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm310543669600">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm310543666096">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm310543664864">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm310543634208">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20547152928"></a>Synopsis</h4></div></div></div>
|
||||
<a name="idm310543781664"></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="idm20547064720"></a>Description</h4></div></div></div>
|
||||
<a name="idm310543676944"></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="idm20547057376"></a>Type requirements</h4></div></div></div>
|
||||
<a name="idm310543669600"></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="idm20547053872"></a>Complexity</h4></div></div></div>
|
||||
<a name="idm310543666096"></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="idm20547052640"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm310543664864"></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="idm20547021984"></a>Header</h4></div></div></div>
|
||||
<a name="idm310543634208"></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#idm20547808304">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm20547790560">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm20547767968">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm20547759840">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm20547758128">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm20547709888">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm20547642784">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm20547641072">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm310544421328">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm310544403584">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm310544380992">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm310544372864">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm310544371152">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm310544322880">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm310544255776">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="checked_result.html#idm310544254064">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20547808304"></a>Description</h4></div></div></div>
|
||||
<a name="idm310544421328"></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="idm20547790560"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310544403584"></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="idm20547767968"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm310544380992"></a>Template Parameters</h4></div></div></div>
|
||||
<p>R must model the type requirements of <a class="link" href="numeric.html" title="Numeric<T>">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="idm20547759840"></a>Model of</h4></div></div></div>
|
||||
<a name="idm310544372864"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Numeric</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20547758128"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310544371152"></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="idm20547709888"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm310544322880"></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="idm20547642784"></a>See Also</h4></div></div></div>
|
||||
<a name="idm310544255776"></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="idm20547641072"></a>Header</h4></div></div></div>
|
||||
<a name="idm310544254064"></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#idm20548253456">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm310545930960">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#idm20548222512">enum class safe_numerics_actions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm20548198656">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm20548194624">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm310545900640">enum class safe_numerics_actions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm310545876784">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="exception.html#idm310545872752">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548253456"></a>Description</h4></div></div></div>
|
||||
<a name="idm310545930960"></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="idm20548222512"></a>enum class safe_numerics_actions</h4></div></div></div>
|
||||
<a name="idm310545900640"></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="idm20548198656"></a>See Also</h4></div></div></div>
|
||||
<a name="idm310545876784"></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="idm20548194624"></a>Header</h4></div></div></div>
|
||||
<a name="idm310545872752"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/exception.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/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#idm20548190880">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm20548189584">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm20548180048">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm20548164032">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm20548162320">Inherited Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm20548160208">Function Objects</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm20548115168">Policies Provided by the library</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm20548082416">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm310545869008">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm310545867712">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm310545858176">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm310545842096">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm310545840384">Inherited Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm310545838272">Function Objects</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm310544728144">Policies Provided by the library</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policies.html#idm310544695504">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548190880"></a>Description</h4></div></div></div>
|
||||
<a name="idm310545869008"></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="idm20548189584"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310545867712"></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="idm20548180048"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm310545858176"></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="idm20548164032"></a>Model of</h4></div></div></div>
|
||||
<a name="idm310545842096"></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="idm20548162320"></a>Inherited Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310545840384"></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="idm20548160208"></a>Function Objects</h4></div></div></div>
|
||||
<a name="idm310545838272"></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="idm20548115168"></a>Policies Provided by the library</h4></div></div></div>
|
||||
<a name="idm310544728144"></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
|
||||
@@ -253,7 +253,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548082416"></a>Header</h4></div></div></div>
|
||||
<a name="idm310544695504"></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#idm20548874656">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm20548873248">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm20548863920">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm20548848096">dispatch<EP>(const safe_numerics_error & e, const char *
|
||||
<dt><span class="section"><a href="exception_policy.html#idm310545266864">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm310545265456">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm310545256128">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm310545240304">dispatch<EP>(const safe_numerics_error & e, const char *
|
||||
msg)</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm20548819456">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm20548806336">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm310545211664">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="exception_policy.html#idm310545198544">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548874656"></a>Description</h4></div></div></div>
|
||||
<a name="idm310545266864"></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="idm20548873248"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310545265456"></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="idm20548863920"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310545256128"></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="idm20548848096"></a>dispatch<EP>(const safe_numerics_error & e, const char *
|
||||
<a name="idm310545240304"></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="idm20548846864"></a>Synopsis</h5></div></div></div>
|
||||
<a name="idm310545239072"></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="idm20548829104"></a>Example of use</h5></div></div></div>
|
||||
<a name="idm310545221312"></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="idm20548819456"></a>Models</h4></div></div></div>
|
||||
<a name="idm310545211664"></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/numerics/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="idm20548806336"></a>Header</h4></div></div></div>
|
||||
<a name="idm310545198544"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/concept/exception_policy.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/concepts/exception_policy.hpp>
|
||||
</code></a></p>
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@
|
||||
</h3></div></div>
|
||||
<div><p class="copyright">Copyright © 2012-2018 Robert Ramey</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="idm20555481680"></a><p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
|
||||
<a name="idm310549544416"></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>
|
||||
@@ -95,9 +95,9 @@
|
||||
<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#idm20546872816"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm20546833216">Concepts are Defined but Not Enforced.</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm20546827488">Other Pending Issues</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm310543485024"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm310543444576">Concepts are Defined but Not Enforced.</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm310543439728">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>
|
||||
|
||||
+13
-13
@@ -21,16 +21,16 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.integer"></a>Integer<T></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="integer.html#idm20549185056">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm20549177616">Refinement of</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm20549175840">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm20549168464">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm20549126384">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm20549124656">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm310545577120">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm310545569680">Refinement of</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm310545567904">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm310545560528">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm310545518448">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#idm310545516720">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549185056"></a>Description</h4></div></div></div>
|
||||
<a name="idm310545577120"></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="idm20549177616"></a>Refinement of</h4></div></div></div>
|
||||
<a name="idm310545569680"></a>Refinement of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Numeric</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549175840"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310545567904"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -72,11 +72,11 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549168464"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310545560528"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>In addition to the expressions defined in <a class="link" href="numeric.html" title="Numeric<T>">Numeric</a> the following expressions
|
||||
must be valid. </p>
|
||||
<div class="table">
|
||||
<a name="idm20549166640"></a><p class="title"><b>Table 4. General</b></p>
|
||||
<a name="idm310545558704"></a><p class="title"><b>Table 4. General</b></p>
|
||||
<div class="table-contents"><table class="table" summary="General">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -167,13 +167,13 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549126384"></a>Models</h4></div></div></div>
|
||||
<a name="idm310545518448"></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="idm20549124656"></a>Header</h4></div></div></div>
|
||||
<a name="idm310545516720"></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#idm20547358784">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm20547355840">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm20547352480">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm20547334992">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm20547329152">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm20547249536">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm20547156736">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm310543987536">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm310543984592">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm310543981232">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm310543963776">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm310543957936">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm310543878320">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="interval.html#idm310543785520">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20547358784"></a>Description</h4></div></div></div>
|
||||
<a name="idm310543987536"></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="idm20547355840"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm310543984592"></a>Template Parameters</h4></div></div></div>
|
||||
<p>R must model the type requirements of <a class="link" href="numeric.html" title="Numeric<T>">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="idm20547352480"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310543981232"></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="idm20547334992"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm310543963776"></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="idm20547329152"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310543957936"></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="idm20547249536"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm310543878320"></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="idm20547156736"></a>Header</h4></div></div></div>
|
||||
<a name="idm310543785520"></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>
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
invoke an error. Using this library, the above example would be rendered
|
||||
as:</p>
|
||||
<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</span><span class="special">.</span><span class="identifier">hpp</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">f</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">x</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">y</span><span class="special">)</span><span class="special">{</span>
|
||||
<span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">;</span> <span class="comment">// throw exception if correct result cannot be returned</span>
|
||||
<span class="special">}</span>
|
||||
@@ -125,7 +125,7 @@
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>Library code in this document resides in the namespace
|
||||
<code class="computeroutput">boost::numeric</code>. This namespace has generally been
|
||||
<code class="computeroutput">boost::safe_numerics</code>. This namespace has generally been
|
||||
eliminated from text, code and examples in order to improve
|
||||
readability of the text.</p></td></tr>
|
||||
</table></div>
|
||||
|
||||
+15
-15
@@ -22,12 +22,12 @@
|
||||
<a name="safe_numerics.numeric"></a>Numeric<T></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="numeric.html#safe_numerics.numeric.description">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm20549324496">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm20549317280">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm20549311984">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm20549212272">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm20549210464">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm20549208256">Note on Usage of <code class="computeroutput">std::numeric_limits</code></a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm310545706864">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm310545700080">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm310545695008">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm310545604384">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm310545602576">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm310545600368">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">
|
||||
@@ -46,7 +46,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549324496"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310545706864"></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="idm20549317280"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm310545700080"></a>Associated Types</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -83,13 +83,13 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549311984"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310545695008"></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. Any operations which result in
|
||||
integers which cannot be represented as some Numeric type will throw an
|
||||
exception.</p>
|
||||
<div class="table">
|
||||
<a name="idm20549310160"></a><p class="title"><b>Table 1. General</b></p>
|
||||
<a name="idm310545693328"></a><p class="title"><b>Table 1. General</b></p>
|
||||
<div class="table-contents"><table class="table" summary="General">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -135,7 +135,7 @@
|
||||
</div>
|
||||
<p><br class="table-break"></p>
|
||||
<div class="table">
|
||||
<a name="idm20549289136"></a><p class="title"><b>Table 2. Unary Operators</b></p>
|
||||
<a name="idm310545674496"></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">
|
||||
@@ -182,7 +182,7 @@
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="table">
|
||||
<a name="idm20549268448"></a><p class="title"><b>Table 3. Binary Operators</b></p>
|
||||
<a name="idm310545655488"></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">
|
||||
@@ -294,21 +294,21 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549212272"></a>Models</h4></div></div></div>
|
||||
<a name="idm310545604384"></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="idm20549210464"></a>Header</h4></div></div></div>
|
||||
<a name="idm310545602576"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/concept/numeric.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/concepts/numeric.hpp>
|
||||
</code></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549208256"></a>Note on Usage of <code class="computeroutput">std::numeric_limits</code>
|
||||
<a name="idm310545600368"></a>Note on Usage of <code class="computeroutput">std::numeric_limits</code>
|
||||
</h4></div></div></div>
|
||||
<p>We define the word "Numeric" in terms of the operations which are
|
||||
supported by "Numeric" types. This is in line with the current and
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
<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#idm20546872816"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm20546833216">Concepts are Defined but Not Enforced.</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm20546827488">Other Pending Issues</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm310543485024"><code class="computeroutput">safe_base</code> Only Works for Scalar Types</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm310543444576">Concepts are Defined but Not Enforced.</a></span></dt>
|
||||
<dt><span class="section"><a href="pending_issues.html#idm310543439728">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="idm20546872816"></a><code class="computeroutput">safe_base</code> Only Works for Scalar Types</h3></div></div></div>
|
||||
<a name="idm310543485024"></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
|
||||
@@ -75,7 +75,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="idm20546833216"></a>Concepts are Defined but Not Enforced.</h3></div></div></div>
|
||||
<a name="idm310543444576"></a>Concepts are Defined but Not Enforced.</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/46" target="_top">github
|
||||
issue</a>.</p>
|
||||
@@ -106,7 +106,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="idm20546827488"></a>Other Pending Issues</h3></div></div></div>
|
||||
<a name="idm310543439728"></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="idm20547949040"></a>Description</h5></div></div></div>
|
||||
<a name="idm310544562128"></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="idm20547932384"></a>Model of</h5></div></div></div>
|
||||
<a name="idm310544545472"></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="idm20547930704"></a>Example of use</h5></div></div></div>
|
||||
<a name="idm310544543792"></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="idm20547888656"></a>Header</h5></div></div></div>
|
||||
<a name="idm310544501744"></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/numeric/safe_numerics/automatic.hpp>
|
||||
</code></a></code></p>
|
||||
|
||||
@@ -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="idm20547884800"></a>Description</h5></div></div></div>
|
||||
<a name="idm310544497888"></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="idm20547881264"></a>Template Parameters</h5></div></div></div>
|
||||
<a name="idm310544494352"></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="idm20547864288"></a>Model of</h5></div></div></div>
|
||||
<a name="idm310544477440"></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="idm20547862576"></a>Example of Use</h5></div></div></div>
|
||||
<a name="idm310544475728"></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="idm20547859568"></a>Header</h5></div></div></div>
|
||||
<a name="idm310544472720"></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="idm20548077968"></a>Description</h5></div></div></div>
|
||||
<a name="idm310544691056"></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="idm20548075936"></a>Model of</h5></div></div></div>
|
||||
<a name="idm310544689024"></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="idm20548039568"></a>Example of use</h5></div></div></div>
|
||||
<a name="idm310544652656"></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="idm20547954000"></a>Notes</h5></div></div></div>
|
||||
<a name="idm310544567088"></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="idm20547952784"></a>Header</h5></div></div></div>
|
||||
<a name="idm310544565872"></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#idm20549018128">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm20549007536">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm20548998320">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm20548973408">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm20548878384">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm310545410192">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm310545399600">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm310545390448">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm310545365536">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="promotion_policy.html#idm310545270592">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549018128"></a>Description</h4></div></div></div>
|
||||
<a name="idm310545410192"></a>Description</h4></div></div></div>
|
||||
<p>In C++, arithmetic operations result in types which may or may not
|
||||
be the same as the constituent types. A promotion policy determines the
|
||||
type of the result of an arithmetic operation. For example, in the
|
||||
@@ -44,7 +44,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549007536"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310545399600"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -70,7 +70,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548998320"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310545390448"></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>
|
||||
@@ -143,7 +143,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548973408"></a>Models</h4></div></div></div>
|
||||
<a name="idm310545365536"></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">
|
||||
@@ -223,7 +223,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548878384"></a>Header</h4></div></div></div>
|
||||
<a name="idm310545270592"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/concept/promotion_policy.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/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="idm20547011968"></a><dl>
|
||||
<dt>1. <a href="rationale.html#idm20547011472">Is this really necessary? If I'm writing the program with the
|
||||
<a name="idm310543624176"></a><dl>
|
||||
<dt>1. <a href="rationale.html#idm310543623680">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#idm20547007968">Can safe types be used as drop-in replacements for built-in
|
||||
<dt>2. <a href="rationale.html#idm310543620176">Can safe types be used as drop-in replacements for built-in
|
||||
types?</a>
|
||||
</dt>
|
||||
<dt>3. <a href="rationale.html#idm20547005648">Why are there special types for literal such as
|
||||
<dt>3. <a href="rationale.html#idm310543617856">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#idm20547000512">Why is safe...literal needed at all? What's the matter with
|
||||
<dt>4. <a href="rationale.html#idm310543612720">Why is safe...literal needed at all? What's the matter with
|
||||
const safe<int>(42)?</a>
|
||||
</dt>
|
||||
<dt>5. <a href="rationale.html#idm20546995440">Are safe type operations constexpr? That is, can
|
||||
<dt>5. <a href="rationale.html#idm310543607648">Are safe type operations constexpr? That is, can
|
||||
they be invoked at compile time?</a>
|
||||
</dt>
|
||||
<dt>6. <a href="rationale.html#idm20546991024">Why define safe_literal?
|
||||
<dt>6. <a href="rationale.html#idm310543603232">Why define safe_literal?
|
||||
Isn't it effectively the same as
|
||||
std::integral_constant?</a>
|
||||
</dt>
|
||||
<dt>7. <a href="rationale.html#idm20546978592">Why is Boost.Convert not used?</a>
|
||||
<dt>7. <a href="rationale.html#idm310543590800">Why is Boost.Convert not used?</a>
|
||||
</dt>
|
||||
<dt>8. <a href="rationale.html#idm20546976560">Why is the library named "safe ..." rather than something like
|
||||
<dt>8. <a href="rationale.html#idm310543588768">Why is the library named "safe ..." rather than something like
|
||||
"checked ..." ?</a>
|
||||
</dt>
|
||||
<dt>9. <a href="rationale.html#idm20546974192">Given that the library is called "numerics" why is floating
|
||||
<dt>9. <a href="rationale.html#idm310543586400">Given that the library is called "numerics" why is floating
|
||||
point arithmetic not addressed?</a>
|
||||
</dt>
|
||||
<dt>10. <a href="rationale.html#idm20546969456">Isn't putting a defensive check just before any potential
|
||||
<dt>10. <a href="rationale.html#idm310543581664">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#idm20546966864">It looks like the implementation presumes two's complement
|
||||
<dt>11. <a href="rationale.html#idm310543579072">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#idm20546964544">According to C/C++ standards, unsigned integers
|
||||
<dt>12. <a href="rationale.html#idm310543576752">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#idm20546958320">Why does the library require C++14?</a>
|
||||
<dt>13. <a href="rationale.html#idm310543570528">Why does the library require C++14?</a>
|
||||
</dt>
|
||||
<dt>14. <a href="rationale.html#idm20546952448">This is a C++ library - yet you refer to C/C++. Which is
|
||||
<dt>14. <a href="rationale.html#idm310543564656">This is a C++ library - yet you refer to C/C++. Which is
|
||||
it?</a>
|
||||
</dt>
|
||||
<dt>15. <a href="rationale.html#idm20546880416">Some compilers (including gcc and clang) include builtin
|
||||
<dt>15. <a href="rationale.html#idm310543492624">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#idm20546876640">Some compilers (including gcc and clang) included a builtin
|
||||
<dt>16. <a href="rationale.html#idm310543488848">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="idm20547011472"></a><a name="idm20547011216"></a><p><b>1.</b></p>
|
||||
<a name="idm310543623680"></a><a name="idm310543623424"></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="idm20547007968"></a><a name="idm20547007712"></a><p><b>2.</b></p>
|
||||
<a name="idm310543620176"></a><a name="idm310543619920"></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="idm20547005648"></a><a name="idm20547005392"></a><p><b>3.</b></p>
|
||||
<a name="idm310543617856"></a><a name="idm310543617600"></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="idm20547000512"></a><a name="idm20547000256"></a><p><b>4.</b></p>
|
||||
<a name="idm310543612720"></a><a name="idm310543612464"></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="idm20546995440"></a><a name="idm20546995184"></a><p><b>5.</b></p>
|
||||
<a name="idm310543607648"></a><a name="idm310543607392"></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="idm20546991024"></a><a name="idm20546990768"></a><p><b>6.</b></p>
|
||||
<a name="idm310543603232"></a><a name="idm310543602976"></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="idm20546978592"></a><a name="idm20546978336"></a><p><b>7.</b></p>
|
||||
<a name="idm310543590800"></a><a name="idm310543590544"></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="idm20546976560"></a><a name="idm20546976304"></a><p><b>8.</b></p>
|
||||
<a name="idm310543588768"></a><a name="idm310543588512"></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="idm20546974192"></a><a name="idm20546973936"></a><p><b>9.</b></p>
|
||||
<a name="idm310543586400"></a><a name="idm310543586144"></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="idm20546969456"></a><a name="idm20546969200"></a><p><b>10.</b></p>
|
||||
<a name="idm310543581664"></a><a name="idm310543581408"></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="idm20546966864"></a><a name="idm20546966608"></a><p><b>11.</b></p>
|
||||
<a name="idm310543579072"></a><a name="idm310543578816"></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="idm20546964544"></a><a name="idm20546964288"></a><p><b>12.</b></p>
|
||||
<a name="idm310543576752"></a><a name="idm310543576496"></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="idm20546958320"></a><a name="idm20546958064"></a><p><b>13.</b></p>
|
||||
<a name="idm310543570528"></a><a name="idm310543570272"></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="idm20546952448"></a><a name="idm20546952192"></a><p><b>14.</b></p>
|
||||
<a name="idm310543564656"></a><a name="idm310543564400"></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="idm20546880416"></a><a name="idm20546880160"></a><p><b>15.</b></p>
|
||||
<a name="idm310543492624"></a><a name="idm310543492368"></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="idm20546876640"></a><a name="idm20546876384"></a><p><b>16.</b></p>
|
||||
<a name="idm310543488848"></a><a name="idm310543488592"></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
|
||||
|
||||
+19
-42
@@ -21,26 +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#idm20548801424">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm20548799424">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm20548795392">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm20548788096">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm20548781056">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm20548762592">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm20548756704">Examples of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm20548470736">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm310545193600">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm310545191600">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm310545187568">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm310545180272">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm310545162720">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm310545156832">Examples of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm310544887072">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548801424"></a>Description</h4></div></div></div>
|
||||
<a name="idm310545193600"></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="idm20548799424"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Integer</a></p>
|
||||
<a name="idm310545191600"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="integer.html" title="Integer<T>">Integer</a></p>
|
||||
<p><a class="link" href="safe_numeric_concept.html" title="SafeNumeric<T>">SafeNumeric</a></p>
|
||||
<p>This type inherits all the notation, associated types and template
|
||||
parameters and valid expressions of <a class="link" href="safe_numeric_concept.html" title="SafeNumeric<T>">SafeNumeric</a> types. The
|
||||
@@ -48,7 +47,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548795392"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310545187568"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -67,29 +66,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548788096"></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">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">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="idm20548781056"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm310545180272"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
@@ -104,18 +81,18 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="computeroutput">T</code></td>
|
||||
<td align="left"><a href="http://en.cppreference.com/w/cpp/types/is_integral" target="_top">Integer<T></a></td>
|
||||
<td align="left"><a class="link" href="integer.html" title="Integer<T>">Integer<T></a></td>
|
||||
<td align="left"><p>The underlying type. Currently only integer types are
|
||||
supported</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="computeroutput">PP</code></td>
|
||||
<td align="left"><a class="link" href="numeric.html" title="Numeric<T>">PromotionPolicy<PP></a></td>
|
||||
<td align="left"><a class="link" href="promotion_policy.html" title="PromotionPolicy<PP>">PromotionPolicy<PP></a></td>
|
||||
<td align="left"><p>Optional promotion policy. Default value is <a class="link" href="promotion_policies/native.html" title="native"><code class="computeroutput">boost::numeric::native</code></a></p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="computeroutput">EP</code></td>
|
||||
<td align="left"><a class="link" href="numeric.html" title="Numeric<T>">Exception
|
||||
<td align="left"><a class="link" href="exception_policy.html" title="ExceptionPolicy<EP>">Exception
|
||||
Policy<EP></a></td>
|
||||
<td align="left"><p>Optional exception policy. Default value is <a class="link" href="exception_policies.html#safe_numerics.exception_policies.default_exception_policy"><code class="computeroutput">boost::numeric::default_exception_policy</code></a></p></td>
|
||||
</tr>
|
||||
@@ -125,7 +102,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548762592"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310545162720"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Implements all expressions and only those expressions defined by the
|
||||
<a class="link" href="safe_numeric_concept.html" title="SafeNumeric<T>">SafeNumeric</a><T>
|
||||
type requirements. Note that all these expressions are
|
||||
@@ -145,7 +122,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548756704"></a>Examples of use</h4></div></div></div>
|
||||
<a name="idm310545156832"></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
|
||||
@@ -278,7 +255,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="idm20548559968"></a>Adjust type promotion rules.</h5></div></div></div>
|
||||
<a name="idm310544960048"></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
|
||||
@@ -313,7 +290,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548470736"></a>Header</h4></div></div></div>
|
||||
<a name="idm310544887072"></a>Header</h4></div></div></div>
|
||||
<p><code class="filename"><a href="../../include/boost/safe_numerics/safe_integer.hpp" target="_top">#include
|
||||
<boost/numeric/safe_numerics/safe_integer.hpp></a></code></p>
|
||||
</div>
|
||||
|
||||
+14
-14
@@ -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#idm20548335520">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm20548334016">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm20548330112">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm20548323120">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm20548305584">Inherited Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm20548273344">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm310546013008">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm310546011504">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm310546007600">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm310546000608">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm310545983072">Inherited Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm310545950832">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#idm20548256784">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_literal.html#idm310545934288">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548335520"></a>Description</h4></div></div></div>
|
||||
<a name="idm310546013008"></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,7 +42,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548334016"></a>Model of</h4></div></div></div>
|
||||
<a name="idm310546011504"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Integer</a></p>
|
||||
<p><a class="link" href="safe_numeric_concept.html" title="SafeNumeric<T>">SafeNumeric</a></p>
|
||||
<p>This type inherits all the notation, associated types and template
|
||||
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548330112"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm310546007600"></a>Associated Types</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -73,7 +73,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548323120"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm310546000608"></a>Template Parameters</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="idm20548305584"></a>Inherited Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310545983072"></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
|
||||
@@ -138,7 +138,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548273344"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm310545950832"></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">safe_integer_literal</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">constexpr</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</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 +154,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548256784"></a>Header</h4></div></div></div>
|
||||
<a name="idm310545934288"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/safe_integer_literal.hpp" target="_top">#include
|
||||
<boost/numeric/safe_numerics/safe_integer_literal.hpp></a></p>
|
||||
</div>
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.safe_numeric_concept"></a>SafeNumeric<T></h3></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm20549120864">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm20549119408">Refinement of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm20549117056">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm20549099616">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm20549027856">Invariants</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm20549026256">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm20549021920">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm310545512896">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm310545511440">Refinement of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm310545509088">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm310545491680">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm310545419920">Invariants</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm310545418320">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_numeric_concept.html#idm310545413984">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549120864"></a>Description</h4></div></div></div>
|
||||
<a name="idm310545512896"></a>Description</h4></div></div></div>
|
||||
<p>This holds an arithmetic value which can be used as a replacement
|
||||
for built-in C++ arithmetic values. These types differ from their built-in
|
||||
counter parts in that the are guaranteed not to produce invalid arithmetic
|
||||
@@ -40,12 +40,12 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549119408"></a>Refinement of</h4></div></div></div>
|
||||
<a name="idm310545511440"></a>Refinement of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Numeric</a> or <a class="link" href="integer.html" title="Integer<T>">Integer</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549117056"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310545509088"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -96,7 +96,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549099616"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310545491680"></a>Valid Expressions</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -241,7 +241,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549027856"></a>Invariants</h4></div></div></div>
|
||||
<a name="idm310545419920"></a>Invariants</h4></div></div></div>
|
||||
<p>The fundamental requirement of a SafeNumeric type is that it
|
||||
implements all C++ operations permitted on its base type in a way the
|
||||
prevents the return of an incorrect arithmetic result. Various
|
||||
@@ -251,7 +251,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549026256"></a>Models</h4></div></div></div>
|
||||
<a name="idm310545418320"></a>Models</h4></div></div></div>
|
||||
<p><code class="computeroutput">safe<T></code></p>
|
||||
<p><code class="computeroutput">safe_signed_range<-11, 11></code></p>
|
||||
<p><code class="computeroutput">safe_unsigned_range<0, 11></code></p>
|
||||
@@ -259,7 +259,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549021920"></a>Header</h4></div></div></div>
|
||||
<a name="idm310545413984"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/boost/safe_numerics/concept/safe_numeric.hpp" target="_top"><code class="computeroutput">#include
|
||||
<boost/numeric/safe_numerics/concepts/safe_numeric.hpp></code></a></p>
|
||||
</div>
|
||||
|
||||
+16
-16
@@ -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#idm20548466976">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm20548464096">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm20548456736">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm20548449648">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm20548428384">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm20548425728">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm20548423440">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm20548339280">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm310544883312">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm310544880432">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm310544873072">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm310544865984">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm310546105904">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm310546103248">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm310546100960">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_range.html#idm310546016768">Header</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548466976"></a>Description</h4></div></div></div>
|
||||
<a name="idm310544883312"></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="idm20548464096"></a>Notation</h4></div></div></div>
|
||||
<a name="idm310544880432"></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="idm20548456736"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm310544873072"></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="idm20548449648"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm310544865984"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -130,13 +130,13 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548428384"></a>Model of</h4></div></div></div>
|
||||
<a name="idm310546105904"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Integer</a></p>
|
||||
<p><a class="link" href="safe_numeric_concept.html" title="SafeNumeric<T>">SafeNumeric</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548425728"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm310546103248"></a>Valid Expressions</h4></div></div></div>
|
||||
<p>Implements all expressions and only those expressions defined by the
|
||||
<a class="link" href="safe_numeric_concept.html" title="SafeNumeric<T>">SafeNumeric</a> type
|
||||
requirements. Thus, the result type of such an expression will be another
|
||||
@@ -145,7 +145,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548423440"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm310546100960"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">type_traits</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">safe_numerics</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="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_range</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
@@ -182,7 +182,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20548339280"></a>Header</h4></div></div></div>
|
||||
<a name="idm310546016768"></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#idm20551051488">How a Stepper Motor Works</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm20551039328">Updating the Code</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm20551023056">Refactor for Testing</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm20551014272">Compiling on the Desktop</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm20550484064">Trapping Errors at Compile Time</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm20549362080">Summary</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm310546691184">How a Stepper Motor Works</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm310546679024">Updating the Code</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm310546662752">Refactor for Testing</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm310546654000">Compiling on the Desktop</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm310546140128">Trapping Errors at Compile Time</a></span></dt>
|
||||
<dt><span class="section"><a href="safety_critical_embedded_controller.html#idm310545742256">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="idm20551051488"></a>How a Stepper Motor Works</h4></div></div></div>
|
||||
<a name="idm310546691184"></a>How a Stepper Motor Works</h4></div></div></div>
|
||||
<div class="figure">
|
||||
<a name="idm20551050848"></a><p class="title"><b>Figure 1. Stepper Motor</b></p>
|
||||
<a name="idm310546690544"></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="idm20551046528"></a><p class="title"><b>Figure 2. Motion Profile</b></p>
|
||||
<a name="idm310546686224"></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="idm20551039328"></a>Updating the Code</h4></div></div></div>
|
||||
<a name="idm310546679024"></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="idm20551023056"></a>Refactor for Testing</h4></div></div></div>
|
||||
<a name="idm310546662752"></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="idm20551014272"></a>Compiling on the Desktop</h4></div></div></div>
|
||||
<a name="idm310546654000"></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="idm20550484064"></a>Trapping Errors at Compile Time</h4></div></div></div>
|
||||
<a name="idm310546140128"></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
|
||||
@@ -1096,7 +1096,7 @@ On interrupt<br>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm20549362080"></a>Summary</h4></div></div></div>
|
||||
<a name="idm310545742256"></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>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
talk</a> related to C++ expressions.</p>
|
||||
<p>The talk included a very, very simple example similar to the
|
||||
following:</p>
|
||||
<pre class="programlisting"><span class="comment">// Copyright (c) 2018Robert Ramey</span>
|
||||
<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>
|
||||
<span class="comment">// accompanying file LICENSE_1_0.txt or copy at</span>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user