• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN"
3"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
4<section id="safe_numerics.integer">
5  <title>Integer&lt;T&gt;</title>
6
7  <?dbhtml stop-chunking?>
8
9  <section>
10    <title>Description</title>
11
12    <para>A type fulfills the requirements of an Integer if it has the
13    properties of a integer.</para>
14
15    <para>More specifically, a type T is Integer if there exists a
16    specialization of <code>std::numeric_limits&lt;T&gt; for which
17    std::numeric_limits&lt;T&gt;::is_integer</code> is equal to
18    <code>true</code>. See the documentation for standard library class
19    <code>numeric_limits</code>. The standard library includes such
20    specializations for all built-in numeric types. Note that this concept is
21    distinct from the C++ standard library type traits
22    <code>is_integral</code> and <code>is_arithmetic</code>. These latter
23    fulfill the requirements of the concept Numeric. But there are types which
24    fulfill this concept for which <code>is_arithmetic&lt;T&gt;::value ==
25    false</code>. For example see <code>safe&lt;int&gt;</code>.</para>
26  </section>
27
28  <section>
29    <title>Refinement of</title>
30
31    <para><link linkend="safe_numerics.numeric">Numeric</link></para>
32  </section>
33
34  <section>
35    <title>Notation</title>
36
37    <informaltable>
38      <tgroup cols="2" colsep="1" rowsep="1">
39        <colspec align="left" colwidth="2*"/>
40
41        <colspec align="left" colwidth="4*"/>
42
43        <tbody>
44          <row>
45            <entry><code>T, U, V</code></entry>
46
47            <entry>A type that is a model of the Integer</entry>
48          </row>
49
50          <row>
51            <entry><code>t, u</code></entry>
52
53            <entry>An object of type modeling Integer</entry>
54          </row>
55        </tbody>
56      </tgroup>
57    </informaltable>
58  </section>
59
60  <section>
61    <title>Valid Expressions</title>
62
63    <para>In addition to the expressions defined in <link
64    linkend="safe_numerics.numeric">Numeric</link> the following expressions
65    must be valid. <table>
66        <title>General</title>
67
68        <tgroup cols="2">
69          <colspec align="left" colwidth="2*"/>
70
71          <colspec align="left" colwidth="4*"/>
72
73          <thead>
74            <row>
75              <entry align="left">Expression</entry>
76
77              <entry>Value</entry>
78            </row>
79          </thead>
80
81          <tbody>
82            <row>
83              <entry><code>std::numeric_limits&lt;T&gt;::is_integer</code></entry>
84
85              <entry>true</entry>
86            </row>
87          </tbody>
88        </tgroup>
89      </table><informaltable>
90        <tgroup cols="3">
91          <colspec align="left" colwidth="1*"/>
92
93          <colspec align="left" colwidth="1*"/>
94
95          <colspec align="left" colwidth="4*"/>
96
97          <thead>
98            <row>
99              <entry align="left">Expression</entry>
100
101              <entry>Return Type</entry>
102
103              <entry>Semantics</entry>
104            </row>
105          </thead>
106
107          <tbody>
108            <row>
109              <entry><code>~t</code></entry>
110
111              <entry><code>T</code></entry>
112
113              <entry>bitwise complement</entry>
114            </row>
115
116            <row>
117              <entry><code>t &lt;&lt; u</code></entry>
118
119              <entry><code>T</code></entry>
120
121              <entry>shift t left u bits</entry>
122            </row>
123
124            <row>
125              <entry><code>t &gt;&gt; u</code></entry>
126
127              <entry><code>T</code></entry>
128
129              <entry>shift t right by u bits</entry>
130            </row>
131
132            <row>
133              <entry><code>t &amp; u</code></entry>
134
135              <entry><code>V</code></entry>
136
137              <entry>and of t and u padded out to max # bits in t, u</entry>
138            </row>
139
140            <row>
141              <entry><code>t | u</code></entry>
142
143              <entry><code>V</code></entry>
144
145              <entry>or of t and u padded out to max # bits in t, u</entry>
146            </row>
147
148            <row>
149              <entry><code>t ^ u</code></entry>
150
151              <entry><code>V</code></entry>
152
153              <entry>exclusive or of t and u padded out to max # bits in t,
154              u</entry>
155            </row>
156
157            <row>
158              <entry><code>t &lt;&lt;= u</code></entry>
159
160              <entry><code>T</code></entry>
161
162              <entry>left shift the value of t by u bits</entry>
163            </row>
164
165            <row>
166              <entry><code>t &gt;&gt;= u</code></entry>
167
168              <entry><code>T</code></entry>
169
170              <entry>right shift the value of t by u bits</entry>
171            </row>
172
173            <row>
174              <entry><code>t &amp;= u</code></entry>
175
176              <entry><code>T</code></entry>
177
178              <entry>and the value of t with u and assign to t</entry>
179            </row>
180
181            <row>
182              <entry><code>t |= u</code></entry>
183
184              <entry><code>T</code></entry>
185
186              <entry>or the value of t with u and assign to t</entry>
187            </row>
188
189            <row>
190              <entry><code>t ^= u</code></entry>
191
192              <entry><code>T</code></entry>
193
194              <entry>exclusive or the value of t with u and assign to
195              t</entry>
196            </row>
197          </tbody>
198        </tgroup>
199      </informaltable></para>
200  </section>
201
202  <section>
203    <title>Models</title>
204
205    <para><code>int, safe&lt;int&gt;, safe_unsigned_range&lt;0, 11&gt;,
206    checked_result&lt;int&gt; etc.</code></para>
207  </section>
208
209  <section>
210    <title>Header</title>
211
212    <para><ulink
213    url="../../include/boost/safe_numerics/concept/numeric.hpp"><code>#include
214    &lt;boost/safe_numerics/concepts/integer.hpp&gt; </code></ulink></para>
215  </section>
216</section>
217