mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-22 15:42:30 +00:00
improved TOC and chunking. This is complicated by the fact we that we desire different depths. put copies of boost logo in subdirectories
217 lines
9.9 KiB
HTML
217 lines
9.9 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>checked_result<typename R></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="library_implementation.html" title="Library Implementation">
|
|
<link rel="prev" href="exception_type.html" title="exception_type">
|
|
<link rel="next" href="checked_integer_arithmetic.html" title="Checked Integer Arithmetic">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr>
|
|
<td valign="top"><img href="index.html" height="164px" src="pre-boost.jpg" alt="Library Documentation Index"></td>
|
|
<td><h2>Safe Numerics</h2></td>
|
|
</tr></table>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="exception_type.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="library_implementation.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="checked_integer_arithmetic.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="safenumerics.checked_result"></a>checked_result<typename R></h3></div></div></div>
|
|
<div class="toc"><dl>
|
|
<dt><span class="section"><a href="checked_result.html#idm413203079520">Description</a></span></dt>
|
|
<dt><span class="section"><a href="checked_result.html#idm413203078000">Template Parameters</a></span></dt>
|
|
<dt><span class="section"><a href="checked_result.html#idm413203067424">Notation</a></span></dt>
|
|
<dt><span class="section"><a href="checked_result.html#idm413203053008">Valid Expressions</a></span></dt>
|
|
<dt><span class="section"><a href="checked_result.html#idm413203025296">Header</a></span></dt>
|
|
<dt><span class="section"><a href="checked_result.html#idm413203023632">Example of use</a></span></dt>
|
|
<dt><span class="section"><a href="checked_result.html#idm413202993408">See Also</a></span></dt>
|
|
</dl></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm413203079520"></a>Description</h4></div></div></div>
|
|
<p>checked_result is a wrapper class designed to hold result of some
|
|
operation. It can hold either the result of the operation or information
|
|
on why the operation failed to produce a valid result. Note that this type
|
|
is an internal feature of the library and shouldn't be exposed to library
|
|
users because it has some unsafe behavior.</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm413203078000"></a>Template Parameters</h4></div></div></div>
|
|
<p>The sole template parameter is the return type of some
|
|
operation.</p>
|
|
<div class="informaltable"><table class="table">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<thead><tr>
|
|
<th align="left">Parameter</th>
|
|
<th align="left">Default</th>
|
|
<th align="left">Type Requirements</th>
|
|
<th align="left">Description</th>
|
|
</tr></thead>
|
|
<tbody><tr>
|
|
<td align="left"><code class="computeroutput">R</code></td>
|
|
<td align="left"><code class="computeroutput"></code></td>
|
|
<td align="left"> </td>
|
|
<td align="left"><p>The value type. </p></td>
|
|
</tr></tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm413203067424"></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">C</code></td>
|
|
<td align="left">checked_result<R></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">c</code></td>
|
|
<td align="left">an instance of checked_result<R></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t</code></td>
|
|
<td align="left">an instance of checked_result<T> for some type T not
|
|
necessarily the same as R</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">r</code></td>
|
|
<td align="left">An object of type R</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">EP</code></td>
|
|
<td align="left"><a class="link" href="exception_policy.html" title="ExceptionPolicy<EP>">ExceptionPolicy</a></td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm413203053008"></a>Valid Expressions</h4></div></div></div>
|
|
<p>All expressions are constexpr.</p>
|
|
<div class="informaltable"><table class="table">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<thead><tr>
|
|
<th align="left">Expression</th>
|
|
<th align="left">Return Type</th>
|
|
<th align="left">Semantics</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">checked_result(r)</code></td>
|
|
<td align="left"><code class="computeroutput">checked_result<R></code></td>
|
|
<td align="left">constructor with valid instance of R</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">checked_result(e, msg)</code></td>
|
|
<td align="left"><code class="computeroutput">checked_result<R></code></td>
|
|
<td align="left">constructor with error information</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">static_cast<R>(c)</code></td>
|
|
<td align="left">R</td>
|
|
<td align="left">extract wrapped value - asserts if not possible</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">static_cast<const char *>(c)</code></td>
|
|
<td align="left">R</td>
|
|
<td align="left">extract wrapped value - asserts if not possible</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput"><table border="0" summary="Simple list" class="simplelist">
|
|
<tr><td>c < t</td></tr>
|
|
<tr><td>c >= t</td></tr>
|
|
<tr><td>c > t</td></tr>
|
|
<tr><td>c <= t</td></tr>
|
|
<tr><td>c == t</td></tr>
|
|
<tr><td>c != t</td></tr>
|
|
</table></code></td>
|
|
<td align="left">boost::logic::tribool</td>
|
|
<td align="left">compare the wrapped values of two checked_result
|
|
instances. If either one contains an invalid value, return
|
|
boost::logic::tribool::indeterminant.</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">c.no_exception()</code></td>
|
|
<td align="left">bool</td>
|
|
<td align="left">true if checked_result contains a valid result</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">c.exception()</code></td>
|
|
<td align="left">bool</td>
|
|
<td align="left">true if checked_result contains an error
|
|
condition</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">dispatch<EP>(c)</code></td>
|
|
<td align="left">void</td>
|
|
<td align="left">invoke exception in accordance exception_type
|
|
value</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm413203025296"></a>Header</h4></div></div></div>
|
|
<p><code class="computeroutput">#include "checked_result.hpp" </code></p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm413203023632"></a>Example of use</h4></div></div></div>
|
|
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"checked_result.hpp"</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="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">modulus</span><span class="special">(</span>
|
|
<span class="keyword">const</span> <span class="identifier">R</span> <span class="special">&</span> <span class="identifier">t</span><span class="special">,</span>
|
|
<span class="keyword">const</span> <span class="identifier">R</span> <span class="special">&</span> <span class="identifier">u</span>
|
|
<span class="special">)</span> <span class="special">{</span>
|
|
<span class="keyword">if</span><span class="special">(</span><span class="number">0</span> <span class="special">==</span> <span class="identifier">u</span><span class="special">)</span>
|
|
<span class="keyword">return</span> <span class="identifier">checked_result</span><span class="special"><</span><span class="identifier">R</span><span class="special">></span><span class="special">(</span>
|
|
<span class="identifier">exception_type</span><span class="special">::</span><span class="identifier">domain_error</span><span class="special">,</span>
|
|
<span class="string">"denominator is zero"</span>
|
|
<span class="special">)</span><span class="special">;</span>
|
|
|
|
<span class="keyword">return</span> <span class="identifier">t</span> <span class="special">%</span> <span class="identifier">u</span><span class="special">;</span>
|
|
<span class="special">}</span></pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm413202993408"></a>See Also</h4></div></div></div>
|
|
<p><a class="link" href="exception_policy.html" title="ExceptionPolicy<EP>">ExceptionPolicy</a></p>
|
|
</div>
|
|
</div>
|
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
|
<td align="left"></td>
|
|
<td align="right"><div class="copyright-footer">Copyright © 2012 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
|
|
Software License</a></p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="exception_type.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="library_implementation.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="checked_integer_arithmetic.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|