Files
safe_numerics/doc/html/checked_result.html
2015-12-21 23:17:05 -08:00

217 lines
8.5 KiB
HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>checked_result&lt;typename R&gt;</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&lt;typename R&gt;</h3></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="checked_result.html#idm473861388880">Description</a></span></dt>
<dt><span class="section"><a href="checked_result.html#idm473861387376">Template Parameters</a></span></dt>
<dt><span class="section"><a href="checked_result.html#idm473861376656">Notation</a></span></dt>
<dt><span class="section"><a href="checked_result.html#idm473861362240">Valid Expressions</a></span></dt>
<dt><span class="section"><a href="checked_result.html#idm473861334528">Header</a></span></dt>
<dt><span class="section"><a href="checked_result.html#idm473861332864">Example of use</a></span></dt>
<dt><span class="section"><a href="checked_result.html#idm473861330416">See Also</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm473861388880"></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="idm473861387376"></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">&#160;</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="idm473861376656"></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&lt;R&gt;</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">c</code></td>
<td align="left">an instance of checked_result&lt;R&gt;</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">t</code></td>
<td align="left">an instance of checked_result&lt;T&gt; 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&lt;EP&gt;">ExceptionPolicy</a></td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm473861362240"></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&lt;R&gt;</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&lt;R&gt;</code></td>
<td align="left">constructor with error information</td>
</tr>
<tr>
<td align="left"><code class="computeroutput">static_cast&lt;R&gt;(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&lt;const char *&gt;(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 &lt; t</td></tr>
<tr><td>c &gt;= t</td></tr>
<tr><td>c &gt; t</td></tr>
<tr><td>c &lt;= 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&lt;EP&gt;(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="idm473861334528"></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="idm473861332864"></a>Example of use</h4></div></div></div>
<pre class="programlisting">#include "checked_result.hpp"
template&lt;class R&gt;
checked_result&lt;R&gt;
constexpr modulus(
const R &amp; t,
const R &amp; u
) {
if(0 == u)
return checked_result&lt;R&gt;(
exception_type::domain_error,
"denominator is zero"
);
return t % u;
}</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm473861330416"></a>See Also</h4></div></div></div>
<p><a class="link" href="exception_policy.html" title="ExceptionPolicy&lt;EP&gt;">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 &#169; 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>