Files
safe_numerics/doc/html/safe_cast.html
Robert Ramey 00e39147a4 Resolve problems with documentation
a) missing concepts
b) missing examples
c) rationalized types
2015-06-10 22:46:58 -07:00

118 lines
5.5 KiB
HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>safe_cast&lt;T, U&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="functions.html" title="Functions">
<link rel="prev" href="functions.html" title="Functions">
<link rel="next" href="safe_compare.html" title="safe_compare&lt;T, U&gt;">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="pre-boost" width="30%" height="30%" src="pre-boost.jpg"></td>
<td align="center"><a href="../../index.html">Home</a></td>
<td align="center"><a href="http://www.boost.org/doc/libs">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="functions.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="functions.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="safe_compare.html"><img src="images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="safe_numerics.safe_cast"></a>safe_cast&lt;T, U&gt;</h3></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="safe_cast.html#idm354477330048">Synopsis</a></span></dt>
<dt><span class="section"><a href="safe_cast.html#idm354477328432">Description</a></span></dt>
<dt><span class="section"><a href="safe_cast.html#idm354477325488">Type requirements</a></span></dt>
<dt><span class="section"><a href="safe_cast.html#idm354477315728">Preconditions</a></span></dt>
<dt><span class="section"><a href="safe_cast.html#idm354477312992">Header</a></span></dt>
<dt><span class="section"><a href="safe_cast.html#idm354477310896">Example of use</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm354477330048"></a>Synopsis</h4></div></div></div>
<pre class="programlisting">template&lt;class T, class U&gt;
T safe_cast(const U &amp; u);</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm354477328432"></a>Description</h4></div></div></div>
<p>Converts one <a class="link" href="numeric.html" title="Numeric&lt;T&gt;">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. This
function is part of the implementation of the safe numerics library. It's
been made publicly because it might be useful in related contexts.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm354477325488"></a>Type requirements</h4></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col align="left">
<col align="left">
</colgroup>
<thead><tr>
<th align="left">Type</th>
<th align="left">Requirements</th>
</tr></thead>
<tbody>
<tr>
<td align="left"><code class="computeroutput">T</code></td>
<td align="left"><a class="link" href="numeric.html" title="Numeric&lt;T&gt;">Numeric</a></td>
</tr>
<tr>
<td align="left"><code class="computeroutput">U </code></td>
<td align="left"><a class="link" href="numeric.html" title="Numeric&lt;T&gt;">Numeric</a></td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm354477315728"></a>Preconditions</h4></div></div></div>
<p>The value of u must be representable 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="idm354477312992"></a>Header</h4></div></div></div>
<p><code class="filename"><a href="../../include/safe_cast.hpp" target="_top">#include
&lt;boost/numeric/safe_cast.hpp&gt; </a></code></p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm354477310896"></a>Example of use</h4></div></div></div>
<pre class="programlisting">#include &lt;boost/numeric/safe_cast.hpp&gt;
#include &lt;boost/numeric/safe_integer.hpp&gt;
void f(){
safe_integer&lt;char&gt; i;
unsigned char j;
i = 1;
j = safe_cast&lt;unsigned char&gt;(i); // ok
i = -1;
j = safe_cast&lt;unsigned char&gt;(i); // throws std::out_of_range exception
i = 1024;
j = safe_cast&lt;unsigned char&gt;(i); // throws std::out_of_range exception
}</pre>
</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="functions.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="functions.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="safe_compare.html"><img src="images/next.png" alt="Next"></a>
</div>
</body>
</html>