mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-23 16:02:13 +00:00
corrected misc documentation errors
This commit is contained in:
0
doc/boostbook/makehtml.sh
Normal file → Executable file
0
doc/boostbook/makehtml.sh
Normal file → Executable file
@@ -2,7 +2,7 @@
|
||||
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
<section id="safe_numerics.safe_cast">
|
||||
<title>safe_cast</title>
|
||||
<title>safe_cast<T, U></title>
|
||||
|
||||
<section>
|
||||
<title>Synopsis</title>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
<section id="safe_numerics.safe_compare">
|
||||
<title>safe_compare</title>
|
||||
<title>safe_compare<T, U></title>
|
||||
|
||||
<section>
|
||||
<title>Synopsis</title>
|
||||
|
||||
@@ -205,7 +205,7 @@
|
||||
Table of contents
|
||||
=============================================================================*/
|
||||
|
||||
.toc
|
||||
div.toc
|
||||
{
|
||||
margin: 1pc 4% 0pc 4%;
|
||||
padding: 0.1pc 1pc 0.1pc 1pc;
|
||||
@@ -466,7 +466,7 @@
|
||||
}
|
||||
|
||||
/* Table of contents */
|
||||
.toc
|
||||
div.toc
|
||||
{
|
||||
border: 1px solid #DCDCDC;
|
||||
}
|
||||
@@ -534,7 +534,7 @@
|
||||
}
|
||||
|
||||
/* Table of contents */
|
||||
.toc
|
||||
div.toc
|
||||
{
|
||||
border: 1px solid gray;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<link rel="home" href="index.html" title="Safe Numerics">
|
||||
<link rel="up" href="index.html" title="Safe Numerics">
|
||||
<link rel="prev" href="safe.html" title="safe<T>">
|
||||
<link rel="next" href="safe_cast.html" title="safe_cast">
|
||||
<link rel="next" href="safe_cast.html" title="safe_cast<T, U>">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -26,8 +26,8 @@
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="safe_numerics.functions"></a>Functions</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="safe_cast.html">safe_cast</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html">safe_compare</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html">safe_cast<T, U></a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html">safe_compare<T, U></a></span></dt>
|
||||
<dt><span class="section"><a href="rationale/overflow.html">overflow</a></span></dt>
|
||||
</dl></div>
|
||||
</div>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
</h3></div></div>
|
||||
<div><p class="copyright">Copyright © 2012 Robert Ramey</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="id698095"></a><p><a href="???" target="_top">Subject to Boost Software License</a></p>
|
||||
<a name="idm412407782640"></a><p><a href="???" target="_top">Subject to Boost Software License</a></p>
|
||||
</div></div>
|
||||
</div></div>
|
||||
<div class="toc">
|
||||
@@ -46,13 +46,13 @@
|
||||
<dt><span class="section"><a href="types.html">Types</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html">safe_unsigned_range<MIN, MAX></a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html">safe_signed_range<MIN, MAX></a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html">safe_signed_range<MIN,></a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html">safe<T></a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="functions.html">Functions</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="safe_cast.html">safe_cast</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html">safe_compare</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html">safe_cast<T, U></a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html">safe_compare<T, U></a></span></dt>
|
||||
<dt><span class="section"><a href="rationale/overflow.html">overflow</a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="rationale.html">Rationale</a></span></dt>
|
||||
@@ -63,7 +63,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: , at </small></p></td>
|
||||
<td align="left"><p><small>Last revised: , </small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
tests for my embedded systems projects on my PC. Still, I had a few
|
||||
issues.</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<li class="listitem"><p>I was a lot of code in one header - 6400 lines. Very unwieldy to
|
||||
understand and modify.</p></li>
|
||||
<li class="listitem"><p>It was a lot of code in one header - 6400 lines. Very unwieldy
|
||||
to understand and modify.</p></li>
|
||||
<li class="listitem"><p>I couldn't find separate documentation other than that in the
|
||||
header file.</p></li>
|
||||
<li class="listitem"><p>I didn't use <a href="www.boost.org" target="_top">Boost</a>
|
||||
<li class="listitem"><p>It didn't use <a href="www.boost.org" target="_top">Boost</a>
|
||||
conventions for naming.</p></li>
|
||||
<li class="listitem"><p>I required porting to different compilers.</p></li>
|
||||
<li class="listitem"><p>It required porting to different compilers.</p></li>
|
||||
<li class="listitem"><p>It had a very long license associated with it.</p></li>
|
||||
<li class="listitem"><p>The package I downloaded didn't have a test suite</p></li>
|
||||
<li class="listitem"><p>I believe the original <a href="http://safeint.codeplex.com/releases/view/73792" target="_top">SafeInt</a>
|
||||
|
||||
@@ -26,16 +26,16 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.numeric"></a>Numeric<T></h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="numeric.html#id699580">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#id741994">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#id742071">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#id742130">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#id753392">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#id753413">Models</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm412407744816">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm412407739600">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm412407731680">Associated Types</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm412407725856">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm412407636528">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="numeric.html#idm412407634528">Models</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id699580"></a>Description</h4></div></div></div>
|
||||
<a name="idm412407744816"></a>Description</h4></div></div></div>
|
||||
<p>A type is Numeric if it has the properties of a number.</p>
|
||||
<p>More specifically, a type T is Numeric if there exists
|
||||
specialization of <code class="computeroutput">std::numeric_limits<T></code>. See the
|
||||
@@ -50,9 +50,9 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id741994"></a>Notation</h4></div></div></div>
|
||||
<a name="idm412407739600"></a>Notation</h4></div></div></div>
|
||||
<div class="table">
|
||||
<a name="id742000"></a><p class="title"><b>Table 1. Notation</b></p>
|
||||
<a name="idm412407738960"></a><p class="title"><b>Table 1. Notation</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Notation">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -74,9 +74,9 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id742071"></a>Associated Types</h4></div></div></div>
|
||||
<a name="idm412407731680"></a>Associated Types</h4></div></div></div>
|
||||
<div class="table">
|
||||
<a name="id742077"></a><p class="title"><b>Table 2. Associated Types</b></p>
|
||||
<a name="idm412407731040"></a><p class="title"><b>Table 2. Associated Types</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Associated Types">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -95,13 +95,13 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id742130"></a>Valid Expressions</h4></div></div></div>
|
||||
<a name="idm412407725856"></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.</p>
|
||||
<p>Any operations which result in integers which cannot be represented
|
||||
as some Numeric type will throw an exception.</p>
|
||||
<div class="table">
|
||||
<a name="id742150"></a><p class="title"><b>Table 3. General</b></p>
|
||||
<a name="idm412407723840"></a><p class="title"><b>Table 3. General</b></p>
|
||||
<div class="table-contents"><table class="table" summary="General">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -131,7 +131,7 @@
|
||||
</div>
|
||||
<p><br class="table-break"></p>
|
||||
<div class="table">
|
||||
<a name="id742245"></a><p class="title"><b>Table 4. Unary Operators</b></p>
|
||||
<a name="idm412407714368"></a><p class="title"><b>Table 4. Unary Operators</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Unary Operators">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -183,7 +183,7 @@
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="table">
|
||||
<a name="id697780"></a><p class="title"><b>Table 5. Binary Operators</b></p>
|
||||
<a name="idm412407695584"></a><p class="title"><b>Table 5. Binary Operators</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Binary Operators">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -199,12 +199,12 @@
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">t - u</code></td>
|
||||
<td align="left">V</td>
|
||||
<td align="left">Invert sign</td>
|
||||
<td align="left">subtract u from t</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">t + u</code></td>
|
||||
<td align="left">V</td>
|
||||
<td align="left">unary plus - a no op</td>
|
||||
<td align="left">add u to t</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">t * u</code></td>
|
||||
@@ -339,13 +339,13 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753392"></a>Header</h4></div></div></div>
|
||||
<a name="idm412407636528"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/concept/numeric.hpp" target="_top"><code class="computeroutput">#include
|
||||
<safe_numerics/include/concepts/numeric.hpp> </code></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753413"></a>Models</h4></div></div></div>
|
||||
<a name="idm412407634528"></a>Models</h4></div></div></div>
|
||||
<p><code class="computeroutput">int, safe_signed_integer<int>,
|
||||
safe_signed_range<int>, etc.</code></p>
|
||||
</div>
|
||||
|
||||
@@ -26,15 +26,15 @@
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="safe_numerics.rationale"></a>Rationale</h2></div></div></div>
|
||||
<div class="qandaset">
|
||||
<a name="id754861"></a><dl>
|
||||
<dt>1. <a href="rationale.html#id754866">Why does a binary operation on two
|
||||
safe<int> values not necessarily return another
|
||||
<a name="idm412404321168"></a><dl>
|
||||
<dt>1. <a href="rationale.html#idm412404320672">Why does a binary operation on two
|
||||
safe<int> values not return another
|
||||
safe type ?</a>
|
||||
</dt>
|
||||
<dt>2. <a href="rationale.html#id754917">Why is there no policy driven design for handling
|
||||
<dt>2. <a href="rationale.html#idm412404314976">Why is there no policy driven design for handling
|
||||
overflows</a>
|
||||
</dt>
|
||||
<dt>3. <a href="rationale.html#id754946">Why is Boost.Convert not used.</a>
|
||||
<dt>3. <a href="rationale.html#idm412404312016">Why is Boost.Convert not used.</a>
|
||||
</dt>
|
||||
</dl>
|
||||
<table border="0" width="100%" summary="Q and A Set">
|
||||
@@ -43,10 +43,10 @@
|
||||
<tbody>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="id754866"></a><a name="id754868"></a><p><b>1.</b></p>
|
||||
<a name="idm412404320672"></a><a name="idm412404320416"></a><p><b>1.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top"><p>Why does a binary operation on two
|
||||
<code class="computeroutput">safe<int></code> values not necessarily return another
|
||||
<code class="computeroutput">safe<int></code> values not return another
|
||||
<code class="computeroutput">safe</code> type ?</p></td>
|
||||
</tr>
|
||||
<tr class="answer">
|
||||
@@ -54,7 +54,7 @@
|
||||
<td align="left" valign="top">
|
||||
<p>There are a number of</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<li class="listitem"><p>it was hard to implement.</p></li>
|
||||
<li class="listitem"><p>it was too hard to implement.</p></li>
|
||||
<li class="listitem"><p>it doesn't really seem necessary. We always do SOMETHING
|
||||
with result of the operation. This will result in an assignment
|
||||
or a conversion to some other type where the result will be
|
||||
@@ -64,7 +64,7 @@
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="id754917"></a><a name="id754920"></a><p><b>2.</b></p>
|
||||
<a name="idm412404314976"></a><a name="idm412404314720"></a><p><b>2.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<p>Why is there no policy driven design for handling
|
||||
@@ -78,7 +78,7 @@ unsigned int x = t1 - t2; // which policy should be invoked?</pre>
|
||||
</tr>
|
||||
<tr class="question">
|
||||
<td align="left" valign="top">
|
||||
<a name="id754946"></a><a name="id754948"></a><p><b>3.</b></p>
|
||||
<a name="idm412404312016"></a><a name="idm412404311760"></a><p><b>3.</b></p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<p>Why is Boost.Convert not used.</p>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
||||
<link rel="home" href="../index.html" title="Safe Numerics">
|
||||
<link rel="up" href="../functions.html" title="Functions">
|
||||
<link rel="prev" href="../safe_compare.html" title="safe_compare">
|
||||
<link rel="prev" href="../safe_compare.html" title="safe_compare<T, U>">
|
||||
<link rel="next" href="../rationale.html" title="Rationale">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
@@ -26,22 +26,22 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.rationale.overflow"></a>overflow</h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="../overflow.html#id754741">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#id754761">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#id754796">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#id754817">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#id754831">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#idm412404334512">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#idm412404332368">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#idm412404328608">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#idm412404326400">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="../overflow.html#idm412404324496">See Also</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754741"></a>Synopsis</h4></div></div></div>
|
||||
<a name="idm412404334512"></a>Synopsis</h4></div></div></div>
|
||||
<p>This function is invoked by the library whenever it is not possible
|
||||
to produce a result for an arithmetic operation.</p>
|
||||
<pre class="programlisting">void overflow(char const * const msg);</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754761"></a>Description</h4></div></div></div>
|
||||
<a name="idm412404332368"></a>Description</h4></div></div></div>
|
||||
<p>If evironment supports C++ exceptions, this function throws the
|
||||
exception .</p>
|
||||
<p>If the environment does not support C++ exceptions, the user should
|
||||
@@ -55,13 +55,13 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754796"></a>Header</h4></div></div></div>
|
||||
<a name="idm412404328608"></a>Header</h4></div></div></div>
|
||||
<p><a href="../include/safe_numerics/overflow" target="_top"><code class="computeroutput">#include
|
||||
<boost/safe_numerics/overflow.hpp> </code></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754817"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm412404326400"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting">#include <cstdio>
|
||||
|
||||
void overflow(char const * const msg){
|
||||
@@ -72,7 +72,7 @@ void overflow(char const * const msg){
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754831"></a>See Also</h4></div></div></div>
|
||||
<a name="idm412404324496"></a>See Also</h4></div></div></div>
|
||||
<p>See <a class="link" href="rationale/overflow.html" title="overflow">rationale</a> for more
|
||||
information on this function</p>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
||||
<link rel="home" href="index.html" title="Safe Numerics">
|
||||
<link rel="up" href="types.html" title="Types">
|
||||
<link rel="prev" href="safe_signed_range.html" title="safe_signed_range<MIN, MAX>">
|
||||
<link rel="prev" href="safe_signed_range.html" title="safe_signed_range<boost::intmax_t MIN, boost::intmax_tMAX>">
|
||||
<link rel="next" href="functions.html" title="Functions">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
@@ -26,26 +26,49 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.safe"></a>safe<T></h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="safe.html#id753980">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#id753999">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#id754085">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#id754099">Derived From</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#id754139">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#id754225">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#id754246">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#id754272">Notes</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#id754284">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404421072">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404419200">Notation</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404410400">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404401264">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404398944">Valid Expressions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404387424">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404385424">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404382672">Notes</a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html#idm412404381440">See Also</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753980"></a>Description</h4></div></div></div>
|
||||
<a name="idm412404421072"></a>Description</h4></div></div></div>
|
||||
<p>A <code class="computeroutput">safe<T></code> can be used anywhere a type T is used.
|
||||
When T is used in operation which overflows, a exception is thrown</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753999"></a>Template Parameters</h4></div></div></div>
|
||||
<p></p>
|
||||
<a name="idm412404419200"></a>Notation</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
<col align="left">
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th align="left">Symbol</th>
|
||||
<th align="left">Description</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">T, U, V</code></td>
|
||||
<td align="left">Types which model the <a class="link" href="numeric.html" title="Numeric<T>">Numeric</a> concept</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">t, u, v</td>
|
||||
<td align="left">objects of types T and U respectively</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="idm412404410400"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -59,58 +82,60 @@
|
||||
</tr></thead>
|
||||
<tbody><tr>
|
||||
<td align="left"><code class="computeroutput">T</code></td>
|
||||
<td align="left"><a class="link" href="numeric.html" title="Numeric<T>">Numeric</a></td>
|
||||
<td align="left"><p>The underlying integer type</p></td>
|
||||
<td align="left"><a class="link" href="numeric.html" title="Numeric<T>">boost::is_integer<T>::value
|
||||
== true</a></td>
|
||||
<td align="left"><p>The underlying intrinsic integer type</p></td>
|
||||
</tr></tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754085"></a>Model of</h4></div></div></div>
|
||||
<a name="idm412404401264"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Numeric</a></p>
|
||||
<p>If the resulting type of the operation t op u is V, the resulting
|
||||
type of the operations st op su, t op su and st op u will be
|
||||
safe<V>;</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754099"></a>Derived From</h4></div></div></div>
|
||||
<p><code class="computeroutput"><a class="link" href="safe_signed_range.html" title="safe_signed_range<MIN, MAX>">safe_signed_range<T></a></code>
|
||||
(if std::numeric_limits<T>::is_signed == ftrue)</p>
|
||||
<p><code class="computeroutput"><a class="link" href="safe_unsigned_range.html" title="safe_unsigned_range<MIN, MAX>">safe_unsigned_range<T></a></code>
|
||||
(if std::numeric_limits<T>::is_signed == ftrue)</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754139"></a>Notation</h4></div></div></div>
|
||||
<a name="idm412404398944"></a>Valid Expressions</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
<col align="left">
|
||||
<col align="left">
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th align="left">Symbol</th>
|
||||
<th align="left">Parameter</th>
|
||||
<th align="left">Result</th>
|
||||
<th align="left">Description</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left"><code class="computeroutput">T</code></td>
|
||||
<td align="left">A type that models the <a class="link" href="numeric.html" title="Numeric<T>">Numeric</a> concept</td>
|
||||
<td align="left"><code class="computeroutput">st op u</code></td>
|
||||
<td align="left"><a class="link" href="numeric.html" title="Numeric<T>">safe<decltype(t
|
||||
op u)></a></td>
|
||||
<td align="left"><p>op is any valid binary operator for types T and
|
||||
U</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">t</td>
|
||||
<td align="left">An object of type <code class="computeroutput">T</code>
|
||||
</td>
|
||||
<td align="left"><code class="computeroutput">T * U</code></td>
|
||||
<td align="left"><a class="link" href="numeric.html" title="Numeric<T>">typeof(T *
|
||||
U)</a></td>
|
||||
<td align="left"><p>The underlying integer type</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754225"></a>Header</h4></div></div></div>
|
||||
<a name="idm412404387424"></a>Header</h4></div></div></div>
|
||||
<p><code class="filename"><a href="../../include/safe_integer.hpp" target="_top">#include
|
||||
<boost/safe_numerics/safe_integer.hpp></a></code></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754246"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm412404385424"></a>Example of use</h4></div></div></div>
|
||||
<p>The following program will emit an error message on a machine where
|
||||
int is only 16 bits but run without problem on a machine where int is 32
|
||||
bits.</p>
|
||||
@@ -131,13 +156,13 @@ void f(){
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754272"></a>Notes</h4></div></div></div>
|
||||
<a name="idm412404382672"></a>Notes</h4></div></div></div>
|
||||
<p>Footnotes (if any) that are referred to by other parts of the
|
||||
page.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754284"></a>See Also</h4></div></div></div>
|
||||
<a name="idm412404381440"></a>See Also</h4></div></div></div>
|
||||
<p>Footnotes (if any) that are referred to by other parts of the
|
||||
page.</p>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>safe_cast</title>
|
||||
<title>safe_cast<T, U></title>
|
||||
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
||||
<link rel="home" href="index.html" title="Safe Numerics">
|
||||
<link rel="up" href="functions.html" title="Functions">
|
||||
<link rel="prev" href="functions.html" title="Functions">
|
||||
<link rel="next" href="safe_compare.html" title="safe_compare">
|
||||
<link rel="next" href="safe_compare.html" title="safe_compare<T, U>">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -24,32 +24,32 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.safe_cast"></a>safe_cast</h3></div></div></div>
|
||||
<a name="safe_numerics.safe_cast"></a>safe_cast<T, U></h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="safe_cast.html#id754315">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#id754330">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#id754354">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#id754441">Preconditions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#id754467">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#id754483">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#id754503">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#idm412404378160">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#idm412404376544">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#idm412404373872">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#idm412404364368">Preconditions</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#idm412404361616">Complexity</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#idm412404359952">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_cast.html#idm412404357856">Example of use</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754315"></a>Synopsis</h4></div></div></div>
|
||||
<a name="idm412404378160"></a>Synopsis</h4></div></div></div>
|
||||
<pre class="programlisting">template<class T, class U>
|
||||
T safe_cast(const U & u);</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754330"></a>Description</h4></div></div></div>
|
||||
<a name="idm412404376544"></a>Description</h4></div></div></div>
|
||||
<p>Converts one <a href="numeric_concept.xml" target="_top">Numeric</a> type
|
||||
to another. Throws an <code class="computeroutput">std::out_of_range</code> exception if such a
|
||||
conversion is not possible without changing the value.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754354"></a>Type requirements</h4></div></div></div>
|
||||
<a name="idm412404373872"></a>Type requirements</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -73,27 +73,27 @@ T safe_cast(const U & u);</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754441"></a>Preconditions</h4></div></div></div>
|
||||
<a name="idm412404364368"></a>Preconditions</h4></div></div></div>
|
||||
<p>The value of u can be represented by the type <code class="computeroutput">T</code>. If
|
||||
this is not true, an <code class="computeroutput">std::out_of_range</code> exception will be
|
||||
thrown.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754467"></a>Complexity</h4></div></div></div>
|
||||
<a name="idm412404361616"></a>Complexity</h4></div></div></div>
|
||||
<p>[Example:]</p>
|
||||
<p>O(N log(N)) comparisons (both average and worst-case), where N is
|
||||
last - first. [2]</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754483"></a>Header</h4></div></div></div>
|
||||
<a name="idm412404359952"></a>Header</h4></div></div></div>
|
||||
<p><code class="filename"><a href="../../include/safe_cast.hpp" target="_top">#include
|
||||
<boost/numeric/safe_cast.hpp> </a></code></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754503"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm412404357856"></a>Example of use</h4></div></div></div>
|
||||
<p>[A code fragment that illustrates how to use the function.]</p>
|
||||
<pre class="programlisting">#include <boost/numeric/safe_cast.hpp>
|
||||
#include <boost/numeric/safe_integer.hpp>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>safe_compare</title>
|
||||
<title>safe_compare<T, U></title>
|
||||
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
||||
<link rel="home" href="index.html" title="Safe Numerics">
|
||||
<link rel="up" href="functions.html" title="Functions">
|
||||
<link rel="prev" href="safe_cast.html" title="safe_cast">
|
||||
<link rel="prev" href="safe_cast.html" title="safe_cast<T, U>">
|
||||
<link rel="next" href="rationale/overflow.html" title="overflow">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
@@ -24,27 +24,39 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.safe_compare"></a>safe_compare</h3></div></div></div>
|
||||
<a name="safe_numerics.safe_compare"></a>safe_compare<T, U></h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="safe_compare.html#id754544">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#id754567">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#id754586">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#id754679">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#id754704">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#idm412404354128">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#idm412404352032">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#idm412404349632">Type requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#idm412404340080">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_compare.html#idm412404338016">Example of use</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754544"></a>Synopsis</h4></div></div></div>
|
||||
<p>safe_compare is really two functions:.</p>
|
||||
<a name="idm412404354128"></a>Synopsis</h4></div></div></div>
|
||||
<p>safe_compare is several functions:.</p>
|
||||
<pre class="programlisting">template<class T, class U>
|
||||
bool safe_compare::less_than(const T & lhs, const U & rhs);
|
||||
|
||||
template<class T, class U>
|
||||
bool safe_compare::greater_than(const T & lhs, const U & rhs);</pre>
|
||||
bool safe_compare::less_than_equal(const T & lhs, const U & rhs);
|
||||
|
||||
template<class T, class U>
|
||||
bool safe_compare::greater_than(const T & lhs, const U & rhs);
|
||||
|
||||
template<class T, class U>
|
||||
bool safe_compare::greater_than_equal(const T & lhs, const U & rhs);
|
||||
|
||||
template<class T, class U>
|
||||
bool safe_compare::equa(const T & lhs, const U & rhs);
|
||||
|
||||
template<class T, class U>
|
||||
bool safe_compare::not_equal(const T & lhs, const U & rhs);</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754567"></a>Description</h4></div></div></div>
|
||||
<a name="idm412404352032"></a>Description</h4></div></div></div>
|
||||
<p>With normal comparison operators, comparison of unsigned types to
|
||||
signed types will be done by converting the unsigned type to a signed type
|
||||
before comparing. Unfortunately this is not always possible. Most C++
|
||||
@@ -54,10 +66,7 @@ bool safe_compare::greater_than(const T & lhs, const U & rhs);</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754586"></a>Type requirements</h4></div></div></div>
|
||||
<p>[This section lists the requirements that must be satisfied by the
|
||||
function's template parameters. If the function has no template
|
||||
parameters, this section can be skipped. Example:]</p>
|
||||
<a name="idm412404349632"></a>Type requirements</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -81,15 +90,13 @@ bool safe_compare::greater_than(const T & lhs, const U & rhs);</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754679"></a>Header</h4></div></div></div>
|
||||
<p>[A link to the source code where the function header is
|
||||
defined.]</p>
|
||||
<a name="idm412404340080"></a>Header</h4></div></div></div>
|
||||
<p><a href="../../include/safe_compare.hpp" target="_top"><code class="filename">#include
|
||||
<boost/numeric/safe_compare.hpp> </code></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id754704"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm412404338016"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting">#include <boost/numeric/safe_compare.hpp>
|
||||
|
||||
void f(){
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>safe_signed_range<MIN, MAX></title>
|
||||
<title>safe_signed_range<boost::intmax_t MIN, boost::intmax_tMAX></title>
|
||||
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
||||
<link rel="home" href="index.html" title="Safe Numerics">
|
||||
@@ -24,25 +24,26 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.safe_signed_range"></a>safe_signed_range<MIN, MAX></h3></div></div></div>
|
||||
<a name="safe_numerics.safe_signed_range"></a>safe_signed_range<boost::intmax_t MIN,
|
||||
boost::intmax_tMAX></h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#id753773">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#id753791">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#id753908">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#id753922">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#id753942">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#id753956">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#idm412404445456">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#idm412404443504">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#idm412404431568">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#idm412404428512">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#idm412404426528">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html#idm412404424208">See Also</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753773"></a>Description</h4></div></div></div>
|
||||
<a name="idm412404445456"></a>Description</h4></div></div></div>
|
||||
<p>This type holds a integer in the range [MIN, MAX]. It will throw a
|
||||
<code class="computeroutput">std::out_of_range</code> exception for operation which would result
|
||||
in assigning an integer value outside of this range.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753791"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm412404443504"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -75,18 +76,21 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753908"></a>Model of</h4></div></div></div>
|
||||
<a name="idm412404431568"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Numeric</a></p>
|
||||
<p>The usage of this type in an arithmetic expression will result in
|
||||
another type fulfilling the <a class="link" href="numeric.html" title="Numeric<T>">Numeric</a> concept. </p>
|
||||
<p>Operations on safe_signed_range will result in the same</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753922"></a>Header</h4></div></div></div>
|
||||
<a name="idm412404428512"></a>Header</h4></div></div></div>
|
||||
<p><code class="filename"><a href="../../include/safe_range.hpp" target="_top">#include
|
||||
<boost/safe_numerics/safe_range.hpp></a></code></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753942"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm412404426528"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting">#include <safe/numeric/safe_range.hpp>
|
||||
|
||||
void f(){
|
||||
@@ -94,12 +98,19 @@ void f(){
|
||||
i = 0; // error
|
||||
i = 9; // ok
|
||||
i *= 9; // throws overflow exception
|
||||
|
||||
std::int8_t j = 4;
|
||||
auto k = i + j;
|
||||
// since i can vary between 7 and 24 and j can vary between 0 and 255
|
||||
// the smallest unsigned integer which can hold the result std::int16_t
|
||||
// j will be of type std::int16_t
|
||||
}</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753956"></a>See Also</h4></div></div></div>
|
||||
<a name="idm412404424208"></a>See Also</h4></div></div></div>
|
||||
<p><code class="computeroutput">std::out_of_range</code></p>
|
||||
<p><code class="computeroutput">safe_unsigned_range</code></p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<link rel="home" href="index.html" title="Safe Numerics">
|
||||
<link rel="up" href="types.html" title="Types">
|
||||
<link rel="prev" href="types.html" title="Types">
|
||||
<link rel="next" href="safe_signed_range.html" title="safe_signed_range<MIN, MAX>">
|
||||
<link rel="next" href="safe_signed_range.html" title="safe_signed_range<boost::intmax_t MIN, boost::intmax_tMAX>">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -26,23 +26,23 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="safe_numerics.safe_unsigned_range"></a>safe_unsigned_range<MIN, MAX></h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#id753452">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#id753471">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#id753587">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#id753704">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#id753724">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#id753746">See Also</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#idm412407630816">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#idm412407628864">Template Parameters</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#idm412404454992">Model of</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#idm412404452224">Header</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#idm412404450240">Example of use</a></span></dt>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html#idm412404448752">See Also</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753452"></a>Description</h4></div></div></div>
|
||||
<a name="idm412407630816"></a>Description</h4></div></div></div>
|
||||
<p>This type holds a integer in the range [MIN, MAX]. It will throw a
|
||||
<code class="computeroutput">std::out_of_range</code> exception for any operation which would
|
||||
result in assigning an integer value outside of this range.</p>
|
||||
result in assigning an integer value outside of this range. </p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753471"></a>Template Parameters</h4></div></div></div>
|
||||
<a name="idm412407628864"></a>Template Parameters</h4></div></div></div>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col align="left">
|
||||
@@ -75,18 +75,22 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753587"></a>Model of</h4></div></div></div>
|
||||
<a name="idm412404454992"></a>Model of</h4></div></div></div>
|
||||
<p><a class="link" href="numeric.html" title="Numeric<T>">Numeric</a></p>
|
||||
<p>The usage of this type in an arithmetic expression with another
|
||||
unsigned type will result in another unsigned type fulfilling the <a class="link" href="numeric.html" title="Numeric<T>">Numeric</a> concept. This will be the
|
||||
smallest unsigned integer type of sufficient size to hold the result of
|
||||
the operation. </p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753704"></a>Header</h4></div></div></div>
|
||||
<a name="idm412404452224"></a>Header</h4></div></div></div>
|
||||
<p><code class="filename"><a href="../../include/safe_range.hpp" target="_top">#include
|
||||
<safe/numeric/safe_range.hpp></a></code></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753724"></a>Example of use</h4></div></div></div>
|
||||
<a name="idm412404450240"></a>Example of use</h4></div></div></div>
|
||||
<pre class="programlisting">#include <safe/numeric/safe_range.hpp>
|
||||
|
||||
void f(){
|
||||
@@ -95,12 +99,20 @@ void f(){
|
||||
i = 9; // ok
|
||||
i *= 9; // throws out_of_range exception
|
||||
i = -1; // throws out_of_range exception
|
||||
|
||||
std::uint8_t j = 4;
|
||||
auto k = i + j;
|
||||
// since i can vary between 7 and 24 and j can vary between 0 and 255
|
||||
// the smallest unsigned integer which can hold the result std::uint16_t
|
||||
// j will be of type std::uint16_t
|
||||
|
||||
}</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="id753746"></a>See Also</h4></div></div></div>
|
||||
<a name="idm412404448752"></a>See Also</h4></div></div></div>
|
||||
<p><code class="computeroutput">std::out_of_range</code></p>
|
||||
<p><code class="computeroutput">safe_signed_range</code></p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
|
||||
@@ -36,8 +36,21 @@
|
||||
<p>This program demonstrates this problem. The solution is to replace
|
||||
instances of <code class="computeroutput">char</code> type with <code class="computeroutput">safe<char></code>
|
||||
type.</p>
|
||||
<pre class="programlisting">void example1(){
|
||||
// problem: undetected erroneous expression evaluation
|
||||
<pre class="programlisting">#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include "../include/safe_integer.hpp"
|
||||
//#include "../include/safe_compare.hpp"
|
||||
|
||||
void detected_msg(bool detected){
|
||||
std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[]){
|
||||
std::cout << "example 1:";
|
||||
std::cout << "undetected erroneous expression evaluation" << std::endl;
|
||||
std::cout << "Not using safe numerics" << std::endl;
|
||||
try{
|
||||
char x = 127;
|
||||
char y = 2;
|
||||
@@ -49,13 +62,14 @@
|
||||
// but assert fails to detect it since C++ implicitly
|
||||
// converts variables to int before evaluating he expression!
|
||||
assert(z != x + y);
|
||||
std::cout << static_cast<int>(z) << " != " << x + y;
|
||||
std::cout << static_cast<int>(z) << " != " << x + y << std::endl;
|
||||
detected_msg(false);
|
||||
}
|
||||
catch(...){
|
||||
assert(false); // never arrive here
|
||||
}
|
||||
// solution: replace char with safe<char>
|
||||
std::cout << "Using safe numerics" << std::endl;
|
||||
try{
|
||||
using namespace boost::numeric;
|
||||
safe<char> x = 127;
|
||||
@@ -67,9 +81,10 @@
|
||||
}
|
||||
catch(std::range_error & e){
|
||||
// which can catch here
|
||||
std::cout << e.what();
|
||||
std::cout << e.what() << std::endl;
|
||||
detected_msg(true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@@ -27,30 +27,44 @@
|
||||
<a name="safe_numerics.tutorial.2"></a>Problem:Undetected overflow</h3></div></div></div>
|
||||
<p>A variation of the above is when a value is incremented/decremented
|
||||
beyond it's domain. This is a common problem with for loops.</p>
|
||||
<pre class="programlisting">void example3(){
|
||||
// problem: undetected overflow in data type
|
||||
<pre class="programlisting">#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include "../include/safe_integer.hpp"
|
||||
//#include "../include/safe_compare.hpp"
|
||||
|
||||
void detected_msg(bool detected){
|
||||
std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[]){
|
||||
std::cout << "example 3: ";
|
||||
std::cout << "implicit conversions change data values" << std::endl;
|
||||
std::cout << "Not using safe numerics" << std::endl;
|
||||
try{
|
||||
int x = INT_MAX;
|
||||
int x = -1000;
|
||||
// the following silently produces an incorrect result
|
||||
++x;
|
||||
//std::cout << x << " != " << -1;
|
||||
char y = x;
|
||||
detected_msg(false);
|
||||
}
|
||||
catch(...){
|
||||
assert(false); // never arrive here
|
||||
}
|
||||
// solution: replace int with safe<int>
|
||||
// solution: replace int with safe<int> and char with safe<char>
|
||||
std::cout << "Using safe numerics" << std::endl;
|
||||
try{
|
||||
using namespace boost::numeric;
|
||||
safe<int> x = INT_MAX;
|
||||
// throws exception when result is past maximum possible
|
||||
++x;
|
||||
safe<int> x = -1000;
|
||||
// throws exception when conversion change data value
|
||||
safe<char> y = x;
|
||||
assert(false); // never arrive here
|
||||
}
|
||||
catch(std::range_error & e){
|
||||
std::cout << e.what();
|
||||
std::cout << e.what() << std::endl;
|
||||
detected_msg(true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@@ -45,13 +45,25 @@
|
||||
</ul></div>
|
||||
<p>This solution is the same as the above, Just replace instances of
|
||||
the <code class="computeroutput">int </code>with <code class="computeroutput">safe<int></code>.</p>
|
||||
<pre class="programlisting">void example2(){
|
||||
// problem: undetected overflow in data type
|
||||
<pre class="programlisting">#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include "../include/safe_integer.hpp"
|
||||
//#include "../include/safe_compare.hpp"
|
||||
|
||||
void detected_msg(bool detected){
|
||||
std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[]){
|
||||
std::cout << "example 2:";
|
||||
std::cout << "undetected overflow in data type" << std::endl;
|
||||
try{
|
||||
int x = INT_MAX;
|
||||
// the following silently produces an incorrect result
|
||||
++x;
|
||||
//std::cout << x << " != " << -1;
|
||||
std::cout << x << " != " << INT_MAX << " + 1" << std::endl;
|
||||
detected_msg(false);
|
||||
}
|
||||
catch(...){
|
||||
@@ -69,6 +81,7 @@
|
||||
std::cout << e.what();
|
||||
detected_msg(true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
<a name="safe_numerics.types"></a>Types</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="safe_unsigned_range.html">safe_unsigned_range<MIN, MAX></a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html">safe_signed_range<MIN, MAX></a></span></dt>
|
||||
<dt><span class="section"><a href="safe_signed_range.html">safe_signed_range<boost::intmax_t MIN,
|
||||
boost::intmax_tMAX></a></span></dt>
|
||||
<dt><span class="section"><a href="safe.html">safe<T></a></span></dt>
|
||||
</dl></div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user