1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> 4<title>Integer<T></title> 5<link rel="stylesheet" href="boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="index.html" title="Safe Numerics"> 8<link rel="up" href="concepts.html" title="Type Requirements"> 9<link rel="prev" href="numeric.html" title="Numeric<T>"> 10<link rel="next" href="safe_numeric_concept.html" title="SafeNumeric<T>"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img href="index.html" height="164px" src="pre-boost.jpg" alt="Library Documentation Index"></td> 15<td><h2>Safe Numerics</h2></td> 16</tr></table> 17<div class="spirit-nav"> 18<a accesskey="p" href="numeric.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="concepts.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_numeric_concept.html"><img src="images/next.png" alt="Next"></a> 19</div> 20<div class="section"> 21<div class="titlepage"><div><div><h3 class="title"> 22<a name="safe_numerics.integer"></a>Integer<T></h3></div></div></div> 23<div class="toc"><dl class="toc"> 24<dt><span class="section"><a href="integer.html#idm130203945888">Description</a></span></dt> 25<dt><span class="section"><a href="integer.html#idm130203938448">Refinement of</a></span></dt> 26<dt><span class="section"><a href="integer.html#idm130203936672">Notation</a></span></dt> 27<dt><span class="section"><a href="integer.html#idm130203929296">Valid Expressions</a></span></dt> 28<dt><span class="section"><a href="integer.html#idm130203887248">Models</a></span></dt> 29<dt><span class="section"><a href="integer.html#idm130203885520">Header</a></span></dt> 30</dl></div> 31<div class="section"> 32<div class="titlepage"><div><div><h4 class="title"> 33<a name="idm130203945888"></a>Description</h4></div></div></div> 34<p>A type fulfills the requirements of an Integer if it has the 35 properties of a integer.</p> 36<p>More specifically, a type T is Integer if there exists a 37 specialization of <code class="computeroutput">std::numeric_limits<T> for which 38 std::numeric_limits<T>::is_integer</code> is equal to 39 <code class="computeroutput">true</code>. See the documentation for standard library class 40 <code class="computeroutput">numeric_limits</code>. The standard library includes such 41 specializations for all built-in numeric types. Note that this concept is 42 distinct from the C++ standard library type traits 43 <code class="computeroutput">is_integral</code> and <code class="computeroutput">is_arithmetic</code>. These latter 44 fulfill the requirements of the concept Numeric. But there are types which 45 fulfill this concept for which <code class="computeroutput">is_arithmetic<T>::value == 46 false</code>. For example see <code class="computeroutput">safe<int></code>.</p> 47</div> 48<div class="section"> 49<div class="titlepage"><div><div><h4 class="title"> 50<a name="idm130203938448"></a>Refinement of</h4></div></div></div> 51<p><a class="link" href="numeric.html" title="Numeric<T>">Numeric</a></p> 52</div> 53<div class="section"> 54<div class="titlepage"><div><div><h4 class="title"> 55<a name="idm130203936672"></a>Notation</h4></div></div></div> 56<div class="informaltable"><table class="table"> 57<colgroup> 58<col align="left"> 59<col align="left"> 60</colgroup> 61<tbody> 62<tr> 63<td align="left"><code class="computeroutput">T, U, V</code></td> 64<td align="left">A type that is a model of the Integer</td> 65</tr> 66<tr> 67<td align="left"><code class="computeroutput">t, u</code></td> 68<td align="left">An object of type modeling Integer</td> 69</tr> 70</tbody> 71</table></div> 72</div> 73<div class="section"> 74<div class="titlepage"><div><div><h4 class="title"> 75<a name="idm130203929296"></a>Valid Expressions</h4></div></div></div> 76<p>In addition to the expressions defined in <a class="link" href="numeric.html" title="Numeric<T>">Numeric</a> the following expressions 77 must be valid. </p> 78<div class="table"> 79<a name="idm130203927472"></a><p class="title"><b>Table 4. General</b></p> 80<div class="table-contents"><table class="table" summary="General"> 81<colgroup> 82<col align="left"> 83<col align="left"> 84</colgroup> 85<thead><tr> 86<th align="left">Expression</th> 87<th align="left">Value</th> 88</tr></thead> 89<tbody><tr> 90<td align="left"><code class="computeroutput">std::numeric_limits<T>::is_integer</code></td> 91<td align="left">true</td> 92</tr></tbody> 93</table></div> 94</div> 95<p><br class="table-break"></p> 96<div class="informaltable"><table class="table"> 97<colgroup> 98<col align="left"> 99<col align="left"> 100<col align="left"> 101</colgroup> 102<thead><tr> 103<th align="left">Expression</th> 104<th align="left">Return Type</th> 105<th align="left">Semantics</th> 106</tr></thead> 107<tbody> 108<tr> 109<td align="left"><code class="computeroutput">~t</code></td> 110<td align="left"><code class="computeroutput">T</code></td> 111<td align="left">bitwise complement</td> 112</tr> 113<tr> 114<td align="left"><code class="computeroutput">t << u</code></td> 115<td align="left"><code class="computeroutput">T</code></td> 116<td align="left">shift t left u bits</td> 117</tr> 118<tr> 119<td align="left"><code class="computeroutput">t >> u</code></td> 120<td align="left"><code class="computeroutput">T</code></td> 121<td align="left">shift t right by u bits</td> 122</tr> 123<tr> 124<td align="left"><code class="computeroutput">t & u</code></td> 125<td align="left"><code class="computeroutput">V</code></td> 126<td align="left">and of t and u padded out to max # bits in t, u</td> 127</tr> 128<tr> 129<td align="left"><code class="computeroutput">t | u</code></td> 130<td align="left"><code class="computeroutput">V</code></td> 131<td align="left">or of t and u padded out to max # bits in t, u</td> 132</tr> 133<tr> 134<td align="left"><code class="computeroutput">t ^ u</code></td> 135<td align="left"><code class="computeroutput">V</code></td> 136<td align="left">exclusive or of t and u padded out to max # bits in t, 137 u</td> 138</tr> 139<tr> 140<td align="left"><code class="computeroutput">t <<= u</code></td> 141<td align="left"><code class="computeroutput">T</code></td> 142<td align="left">left shift the value of t by u bits</td> 143</tr> 144<tr> 145<td align="left"><code class="computeroutput">t >>= u</code></td> 146<td align="left"><code class="computeroutput">T</code></td> 147<td align="left">right shift the value of t by u bits</td> 148</tr> 149<tr> 150<td align="left"><code class="computeroutput">t &= u</code></td> 151<td align="left"><code class="computeroutput">T</code></td> 152<td align="left">and the value of t with u and assign to t</td> 153</tr> 154<tr> 155<td align="left"><code class="computeroutput">t |= u</code></td> 156<td align="left"><code class="computeroutput">T</code></td> 157<td align="left">or the value of t with u and assign to t</td> 158</tr> 159<tr> 160<td align="left"><code class="computeroutput">t ^= u</code></td> 161<td align="left"><code class="computeroutput">T</code></td> 162<td align="left">exclusive or the value of t with u and assign to 163 t</td> 164</tr> 165</tbody> 166</table></div> 167</div> 168<div class="section"> 169<div class="titlepage"><div><div><h4 class="title"> 170<a name="idm130203887248"></a>Models</h4></div></div></div> 171<p><code class="computeroutput">int, safe<int>, safe_unsigned_range<0, 11>, 172 checked_result<int> etc.</code></p> 173</div> 174<div class="section"> 175<div class="titlepage"><div><div><h4 class="title"> 176<a name="idm130203885520"></a>Header</h4></div></div></div> 177<p><a href="../../include/boost/safe_numerics/concept/numeric.hpp" target="_top"><code class="computeroutput">#include 178 <boost/safe_numerics/concepts/integer.hpp> </code></a></p> 179</div> 180</div> 181<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 182<td align="left"></td> 183<td align="right"><div class="copyright-footer">Copyright © 2012-2018 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost 184 Software License</a></p> 185</div></td> 186</tr></table> 187<hr> 188<div class="spirit-nav"> 189<a accesskey="p" href="numeric.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="concepts.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_numeric_concept.html"><img src="images/next.png" alt="Next"></a> 190</div> 191</body> 192</html> 193