mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-09 23:32:37 +00:00
186 lines
8.5 KiB
HTML
186 lines
8.5 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>safe_signed_range<MIN, MAX, PP, EP></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="types.html" title="Types">
|
|
<link rel="prev" href="safe.html" title="safe<T, PP, EP>">
|
|
<link rel="next" href="safe_unsigned_range.html" title="safe_unsigned_range<MIN, MAX, PP, EP>">
|
|
</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="safe.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="types.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_unsigned_range.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_signed_range"></a>safe_signed_range<MIN, MAX, PP, EP></h3></div></div></div>
|
|
<div class="toc"><dl>
|
|
<dt><span class="section"><a href="safe_signed_range.html#idm305379936640">Description</a></span></dt>
|
|
<dt><span class="section"><a href="safe_signed_range.html#idm305379934768">Notation</a></span></dt>
|
|
<dt><span class="section"><a href="safe_signed_range.html#idm305379927248">Associated Types</a></span></dt>
|
|
<dt><span class="section"><a href="safe_signed_range.html#idm305379920496">Template Parameters</a></span></dt>
|
|
<dt><span class="section"><a href="safe_signed_range.html#idm305379902032">Model of</a></span></dt>
|
|
<dt><span class="section"><a href="safe_signed_range.html#idm305379899792">Valid Expressions</a></span></dt>
|
|
<dt><span class="section"><a href="safe_signed_range.html#idm305379897728">Header</a></span></dt>
|
|
<dt><span class="section"><a href="safe_signed_range.html#idm305379895744">Example of use</a></span></dt>
|
|
</dl></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm305379936640"></a>Description</h4></div></div></div>
|
|
<p>This type holds a signed 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="idm305379934768"></a>Notation</h4></div></div></div>
|
|
<p>In addition</p>
|
|
<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">MIN, MAX</code></td>
|
|
<td align="left">Minimum and maximum signed values that the
|
|
safe_signed_range can represent.</td>
|
|
</tr></tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm305379927248"></a>Associated Types</h4></div></div></div>
|
|
<div class="informaltable"><table class="table">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">PP</code></td>
|
|
<td align="left">A type which specifes the result type of an expression
|
|
using safe types.</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">EP</code></td>
|
|
<td align="left">A type containing members which are called when a correct
|
|
result cannot be returned</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm305379920496"></a>Template Parameters</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">Parameter</th>
|
|
<th align="left">Requirements</th>
|
|
<th align="left">Description</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">MIN</code></td>
|
|
<td align="left">must be an integer literal</td>
|
|
<td align="left">The minimum integer value that this type may hold</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">MAX</code></td>
|
|
<td align="left">must be a negative literal</td>
|
|
<td align="left">The maximum integer value that this type may hold</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"> </td>
|
|
<td align="left">MIN <= MAX</td>
|
|
<td align="left">must be a valid closed range</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">PP</code></td>
|
|
<td align="left"><a class="link" href="numeric.html" title="Numeric<T>"><a class="link" href="promotion_policy.html" title="PromotionPolicy<PP>">PromotionPolicy<PP></a></a></td>
|
|
<td align="left"><p>Default value is <a class="link" href="promotion_policy.html#safe_numerics.promotion_policy.models.native">boost::numeric::native</a></p></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">EP</code></td>
|
|
<td align="left"><a class="link" href="numeric.html" title="Numeric<T>"><a class="link" href="exception_policy.html" title="ExceptionPolicy<EP>">Exception
|
|
Policy<EP></a></a></td>
|
|
<td align="left"><p>Default value is <a class="link" href="exception_policy.html#safe_numerics.exception_policy.models.thow_exception">boost::throw_exception</a></p></td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm305379902032"></a>Model of</h4></div></div></div>
|
|
<p><a class="link" href="numeric.html" title="Numeric<T>">Integer</a></p>
|
|
<p><a class="link" href="safe_numeric_concept.html" title="SafeNumeric<T>">SafeNumeric</a></p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm305379899792"></a>Valid Expressions</h4></div></div></div>
|
|
<p>Implements all expressions and only those expressions defined by the
|
|
<a class="link" href="safe_numeric_concept.html" title="SafeNumeric<T>">SafeNumeric</a> type
|
|
requirements. This, the result type of such an expression will be another
|
|
safe type. The actual type of the result of such an expression will depend
|
|
upon the specific promotion policy template parameter.</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm305379897728"></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="idm305379895744"></a>Example of use</h4></div></div></div>
|
|
<pre class="programlisting">#include <safe/numeric/safe_range.hpp>
|
|
|
|
void f(){
|
|
boost::numeric::safe_signed_range<-7, 24> i;
|
|
// since the range is included in [-128,127], the underlying type of i
|
|
// will be a char.
|
|
i = -41; // throws out_of_range exception
|
|
i = 9; // ok
|
|
i = -1; // ok
|
|
i *= 9; // throws out_of_range exception
|
|
std::int8_t j = 4;
|
|
auto k = i + j;
|
|
// These types use default promotion policy so standard C++ type promotion rules
|
|
// will be used in evaluating expressions. C++ type promotion rules mandate
|
|
// that the result of k = i + j when both are signed char types, will be another
|
|
// signed char type.
|
|
}</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 © 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="safe.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="types.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_unsigned_range.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|