Files
safe_numerics/doc/html/safe_compare.html
2013-11-04 11:44:56 -08:00

116 lines
5.3 KiB
HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>safe_compare</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="safe_cast.html" title="safe_cast">
<link rel="next" href="rationale/overflow.html" title="overflow">
</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_cast.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="rationale/overflow.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_compare"></a>safe_compare</h3></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="safe_compare.html#id754544">Synopsis</a></span></dt>
<dt><span class="section"><a href="safe_compare.html#id754567">Description</a></span></dt>
<dt><span class="section"><a href="safe_compare.html#id754586">Type requirements</a></span></dt>
<dt><span class="section"><a href="safe_compare.html#id754679">Header</a></span></dt>
<dt><span class="section"><a href="safe_compare.html#id754704">Example of use</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="id754544"></a>Synopsis</h4></div></div></div>
<p>safe_compare is really two functions:.</p>
<pre class="programlisting">template&lt;class T, class U&gt;
bool safe_compare::less_than(const T &amp; lhs, const U &amp; rhs);
template&lt;class T, class U&gt;
bool safe_compare::greater_than(const T &amp; lhs, const U &amp; rhs);</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="id754567"></a>Description</h4></div></div></div>
<p>With normal comparison operators, comparison of unsigned types to
signed types will be done by converting the unsigned type to a signed type
before comparing. Unfortunately this is not always possible. Most C++
compilers will emit an warning message when this is possible but won't
check that an error is made in the conversion. This function guarentees a
correct result regardless of the types of the arguments.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="id754586"></a>Type requirements</h4></div></div></div>
<p>[This section lists the requirements that must be satisfied by the
function's template parameters. If the function has no template
parameters, this section can be skipped. Example:]</p>
<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="id754679"></a>Header</h4></div></div></div>
<p>[A link to the source code where the function header is
defined.]</p>
<p><a href="../../include/safe_compare.hpp" target="_top"><code class="filename">#include
&lt;boost/numeric/safe_compare.hpp&gt; </code></a></p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="id754704"></a>Example of use</h4></div></div></div>
<pre class="programlisting">#include &lt;boost/numeric/safe_compare.hpp&gt;
void f(){
int i = -1;
unsigned char i = 0x129;
unsigned int j = 1;
bool result;
result = j &lt; i; // incorrect result
result = safe_compare::less_than(j &lt; i); // correct result
}</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="???" target="_top">Subject to Boost Software License</a></p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="safe_cast.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="rationale/overflow.html"><img src="images/next.png" alt="Next"></a>
</div>
</body>
</html>