mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-09 11:22:23 +00:00
217 lines
8.5 KiB
HTML
217 lines
8.5 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#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"> </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<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="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<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="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<class R>
|
|
checked_result<R>
|
|
constexpr modulus(
|
|
const R & t,
|
|
const R & u
|
|
) {
|
|
if(0 == u)
|
|
return checked_result<R>(
|
|
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<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>
|