• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4<title>safe&lt;T, PP, EP&gt;</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="types.html" title="Types">
9<link rel="prev" href="types.html" title="Types">
10<link rel="next" href="safe_range.html" title="safe_signed_range&lt;MIN, MAX, PP, EP&gt; and safe_unsigned_range&lt;MIN, MAX, PP, EP&gt;">
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="types.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_range.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.safe"></a>safe&lt;T, PP, EP&gt;</h3></div></div></div>
23<div class="toc"><dl class="toc">
24<dt><span class="section"><a href="safe.html#idm130203562112">Description</a></span></dt>
25<dt><span class="section"><a href="safe.html#idm130203560112">Model of</a></span></dt>
26<dt><span class="section"><a href="safe.html#idm130203556080">Notation</a></span></dt>
27<dt><span class="section"><a href="safe.html#idm130203548784">Associated Types</a></span></dt>
28<dt><span class="section"><a href="safe.html#idm130203541744">Template Parameters</a></span></dt>
29<dt><span class="section"><a href="safe.html#idm130203523280">Valid Expressions</a></span></dt>
30<dt><span class="section"><a href="safe.html#idm130203517392">Examples of use</a></span></dt>
31<dt><span class="section"><a href="safe.html#idm130203247744">Header</a></span></dt>
32</dl></div>
33<div class="section">
34<div class="titlepage"><div><div><h4 class="title">
35<a name="idm130203562112"></a>Description</h4></div></div></div>
36<p>A <code class="computeroutput">safe&lt;T, PP , EP&gt;</code> can be used anywhere a type T
37    can be used. Any expression which uses this type is guaranteed to return
38    an arithmetically correct value or to trap in some way.</p>
39</div>
40<div class="section">
41<div class="titlepage"><div><div><h4 class="title">
42<a name="idm130203560112"></a>Model of</h4></div></div></div>
43<p><a class="link" href="numeric.html" title="Numeric&lt;T&gt;">Integer</a></p>
44<p><a class="link" href="safe_numeric_concept.html" title="SafeNumeric&lt;T&gt;">SafeNumeric</a></p>
45<p>This type inherits all the notation, associated types and template
46    parameters and valid expressions of <a class="link" href="safe_numeric_concept.html" title="SafeNumeric&lt;T&gt;">SafeNumeric</a> types. The
47    following specify additional features of this type.</p>
48</div>
49<div class="section">
50<div class="titlepage"><div><div><h4 class="title">
51<a name="idm130203556080"></a>Notation</h4></div></div></div>
52<div class="informaltable"><table class="table">
53<colgroup>
54<col align="left">
55<col align="left">
56</colgroup>
57<thead><tr>
58<th align="left">Symbol</th>
59<th align="left">Description</th>
60</tr></thead>
61<tbody><tr>
62<td align="left"><code class="computeroutput">T</code></td>
63<td align="left">Underlying type from which a safe type is being
64            derived</td>
65</tr></tbody>
66</table></div>
67</div>
68<div class="section">
69<div class="titlepage"><div><div><h4 class="title">
70<a name="idm130203548784"></a>Associated Types</h4></div></div></div>
71<div class="informaltable"><table class="table">
72<colgroup>
73<col align="left">
74<col align="left">
75</colgroup>
76<tbody>
77<tr>
78<td align="left"><code class="computeroutput">PP</code></td>
79<td align="left">A type which specifies the result type of an expression
80            using safe types.</td>
81</tr>
82<tr>
83<td align="left"><code class="computeroutput">EP</code></td>
84<td align="left">A type containing members which are called when a correct
85            result cannot be returned</td>
86</tr>
87</tbody>
88</table></div>
89</div>
90<div class="section">
91<div class="titlepage"><div><div><h4 class="title">
92<a name="idm130203541744"></a>Template Parameters</h4></div></div></div>
93<div class="informaltable"><table class="table">
94<colgroup>
95<col>
96<col align="left">
97<col align="left">
98</colgroup>
99<thead><tr>
100<th align="left">Parameter</th>
101<th align="left">Type Requirements</th>
102<th align="left">Description</th>
103</tr></thead>
104<tbody>
105<tr>
106<td><code class="computeroutput">T</code></td>
107<td align="left"><a href="http://en.cppreference.com/w/cpp/types/is_integral" target="_top">Integer&lt;T&gt;</a></td>
108<td align="left"><p>The underlying type. Currently only integer types are
109            supported</p></td>
110</tr>
111<tr>
112<td><code class="computeroutput">PP</code></td>
113<td align="left"><a class="link" href="numeric.html" title="Numeric&lt;T&gt;">PromotionPolicy&lt;PP&gt;</a></td>
114<td align="left"><p>Optional promotion policy. Default value is <a class="link" href="promotion_policies/native.html" title="native"><code class="computeroutput">boost::numeric::native</code></a></p></td>
115</tr>
116<tr>
117<td><code class="computeroutput">EP</code></td>
118<td align="left"><a class="link" href="numeric.html" title="Numeric&lt;T&gt;">Exception
119            Policy&lt;EP&gt;</a></td>
120<td align="left"><p>Optional exception policy. Default value is <a class="link" href="exception_policies.html#safe_numerics.exception_policies.default_exception_policy"><code class="computeroutput">boost::numeric::default_exception_policy</code></a></p></td>
121</tr>
122</tbody>
123</table></div>
124<p>See examples below.</p>
125</div>
126<div class="section">
127<div class="titlepage"><div><div><h4 class="title">
128<a name="idm130203523280"></a>Valid Expressions</h4></div></div></div>
129<p>Implements all expressions and only those expressions defined by the
130    <a class="link" href="safe_numeric_concept.html" title="SafeNumeric&lt;T&gt;">SafeNumeric</a>&lt;T&gt;
131    type requirements. Note that all these expressions are
132    <code class="computeroutput">constexpr</code>. Thus, the result type of such an expression will
133    be another safe type. The actual type of the result of such an expression
134    will depend upon the specific promotion policy template parameter.</p>
135<p>When a binary operand is applied to two instances of safe&lt;T, PP,
136    EP&gt;on of the following must be true:</p>
137<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
138<li class="listitem"><p>The promotion policies of the two operands must be the same or
139          one of them must be void</p></li>
140<li class="listitem"><p>The exception policies of the two operands must be the same or
141          one of them must be void</p></li>
142</ul></div>
143<p>If either of the above is not true, a compile error will
144    result.</p>
145</div>
146<div class="section">
147<div class="titlepage"><div><div><h4 class="title">
148<a name="idm130203517392"></a>Examples of use</h4></div></div></div>
149<p>The most common usage would be safe&lt;T&gt; which uses the default
150    promotion and exception policies. This type is meant to be a "drop-in"
151    replacement of the intrinsic integer types. That is, expressions involving
152    these types will be evaluated into result types which reflect the standard
153    rules for evaluation of C++ expressions. Should it occur that such
154    evaluation cannot return a correct result, an exception will be
155    thrown.</p>
156<p>There are two aspects of the operation of this type which can be
157    customized with a policy. The first is the result type of an arithmetic
158    operation. C++ defines the rules which define this result type in terms of
159    the constituent types of the operation. Here we refer to these rules as
160    "type promotion" rules. These rules will sometimes result in a type which
161    cannot hold the actual arithmetic result of the operation. This is the
162    main motivation for making this library in the first place. One way to
163    deal with this problem is to substitute our own type promotion rules for
164    the C++ ones.</p>
165<div class="section">
166<div class="titlepage"><div><div><h5 class="title">
167<a name="safe_numerics.drop_in_replacement"></a>As a Drop-in replacement for standard integer types.</h5></div></div></div>
168<p>The following program will throw an exception and emit an error
169      message at runtime if any of several events result in an incorrect
170      arithmetic result. Behavior of this program could vary according to the
171      machine architecture in question.</p>
172<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">exception</span><span class="special">&gt;</span>
173<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
174<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">safe_integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
175
176<span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="special">)</span><span class="special">{</span>
177    <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">;</span>
178    <span class="identifier">safe</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">j</span><span class="special">;</span>
179    <span class="keyword">try</span> <span class="special">{</span>
180        <span class="identifier">safe</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">i</span><span class="special">;</span>
181        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cin</span> <span class="special">&gt;&gt;</span> <span class="identifier">i</span><span class="special">;</span>  <span class="comment">// could overflow !</span>
182        <span class="identifier">j</span> <span class="special">=</span> <span class="identifier">i</span> <span class="special">*</span> <span class="identifier">i</span><span class="special">;</span>      <span class="comment">// could overflow</span>
183    <span class="special">}</span>
184    <span class="keyword">catch</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="special">&amp;</span> <span class="identifier">e</span><span class="special">)</span><span class="special">{</span>
185       <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">(</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
186    <span class="special">}</span>
187    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">j</span><span class="special">;</span>
188<span class="special">}</span></pre>
189<p>The term "drop-in replacement" reveals the aspiration of
190      this library. In most cases, this aspiration is realized. In the
191      following example, the normal implicit conversions function the same for
192      safe integers as they do for built-in integers. </p>
193<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">safe_numerics</span><span class="special">/</span><span class="identifier">safe_integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
194<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">safe_numerics</span><span class="special">;</span>
195
196<span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span><span class="special">{</span>
197    <span class="keyword">return</span> <span class="identifier">i</span><span class="special">;</span>
198<span class="special">}</span>
199
200<span class="keyword">using</span> <span class="identifier">safe_t</span> <span class="special">=</span> <span class="identifier">safe</span><span class="special">&lt;</span><span class="keyword">long</span><span class="special">&gt;</span><span class="special">;</span>
201
202<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="special">)</span><span class="special">{</span>
203    <span class="keyword">const</span> <span class="keyword">long</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">97</span><span class="special">;</span>
204    <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span><span class="special">;</span>   <span class="comment">// OK - implicit conversion to int</span>
205    <span class="keyword">const</span> <span class="identifier">safe_t</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">97</span><span class="special">;</span>
206    <span class="identifier">f</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span><span class="special">;</span>   <span class="comment">// Also OK - checked implicit conversion to int</span>
207    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
208<span class="special">}</span></pre>
209<p>When
210      the <code class="computeroutput">safe&lt;long&gt;</code> is implicitly converted to an
211      <code class="computeroutput">int</code> when calling <code class="computeroutput">f</code>, the value is checked to be
212      sure that it is within the legal range of an int and will invoke an
213      exception if it cannot. We can easily verify this by altering the
214      exception handling policy in the above example to
215      <code class="computeroutput">loose_trap_policy</code>. This will invoke a compile time error on
216      any conversion might invoke a runtime exception.</p>
217<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">safe_numerics</span><span class="special">/</span><span class="identifier">safe_integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
218<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">safe_numerics</span><span class="special">;</span>
219
220<span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span><span class="special">{</span>
221    <span class="keyword">return</span> <span class="identifier">i</span><span class="special">;</span>
222<span class="special">}</span>
223
224<span class="keyword">using</span> <span class="identifier">safe_t</span> <span class="special">=</span> <span class="identifier">safe</span><span class="special">&lt;</span><span class="keyword">long</span><span class="special">,</span> <span class="identifier">native</span><span class="special">,</span> <span class="identifier">loose_trap_policy</span><span class="special">&gt;</span><span class="special">;</span>
225
226<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="special">)</span><span class="special">{</span>
227    <span class="keyword">const</span> <span class="keyword">long</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">97</span><span class="special">;</span>
228    <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span><span class="special">;</span>   <span class="comment">// OK - implicit conversion to int</span>
229    <span class="keyword">const</span> <span class="identifier">safe_t</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">97</span><span class="special">;</span>
230    <span class="identifier">f</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span><span class="special">;</span>   <span class="comment">// Would be OK, but will invoke compile time error</span>
231    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
232<span class="special">}</span></pre>
233<p>But this raises it's own questions. We can see that in this
234      example, the program can never fail:</p>
235<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
236<li class="listitem"><p>The value 97 is assigned to y</p></li>
237<li class="listitem"><p>y is converted to an int</p></li>
238<li class="listitem"><p>and used as an argument to f</p></li>
239</ul></div>
240<p>The conversion can never fail because the value of 97 can always
241      fit into an int. But the library code can't detect this and emits the
242      checking code even though it's not necessary.</p>
243<p>This can be addressed by using a <a class="link" href="safe_literal.html" title="safe_signed_literal&lt;Value, PP , EP&gt; and safe_unsigned_literal&lt;Value, PP, EP&gt;"><code class="computeroutput">safe_literal</code></a>. A
244      safe literal can contain one and only one value. All the functions in
245      this library are marked <code class="computeroutput">constexpr</code>. So it can be determined
246      at compile time that conversion to an <code class="computeroutput">int</code> can never fail
247      and no runtime checking code need be emitted. Making this small change
248      will permit the above example to run with zero runtime overhead while
249      guaranteeing that no error can ever occur.</p>
250<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">safe_numerics</span><span class="special">/</span><span class="identifier">safe_integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
251<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">safe_numerics</span><span class="special">/</span><span class="identifier">safe_integer_literal</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
252
253<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">safe_numerics</span><span class="special">;</span>
254
255<span class="keyword">int</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span><span class="special">{</span>
256    <span class="keyword">return</span> <span class="identifier">i</span><span class="special">;</span>
257<span class="special">}</span>
258
259<span class="keyword">template</span><span class="special">&lt;</span><span class="identifier">intmax_t</span> <span class="identifier">N</span><span class="special">&gt;</span>
260<span class="keyword">using</span> <span class="identifier">safe_literal</span> <span class="special">=</span> <span class="identifier">safe_signed_literal</span><span class="special">&lt;</span><span class="identifier">N</span><span class="special">,</span> <span class="identifier">native</span><span class="special">,</span> <span class="identifier">loose_trap_policy</span><span class="special">&gt;</span><span class="special">;</span>
261
262<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="special">)</span><span class="special">{</span>
263    <span class="keyword">const</span> <span class="keyword">long</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">97</span><span class="special">;</span>
264    <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span><span class="special">;</span>   <span class="comment">// OK - implicit conversion to int</span>
265    <span class="keyword">const</span> <span class="identifier">safe_literal</span><span class="special">&lt;</span><span class="number">97</span><span class="special">&gt;</span> <span class="identifier">y</span><span class="special">;</span>
266    <span class="identifier">f</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span><span class="special">;</span>   <span class="comment">// OK - y is a type with min/max = 97;</span>
267    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
268<span class="special">}</span></pre>
269<p>With this trivial example, such efforts would hardly be deemed
270      necessary. But in a more complex case, perhaps including compile time
271      arithmetic expressions, it could be much more difficult to verify that
272      the constant is valid and/or no checking code is needed. And there is
273      also possibility that over the life time of the application, the compile
274      time constants might change, thus rendering any ad hoc analyse obsolete.
275      Using <a class="link" href="safe_literal.html" title="safe_signed_literal&lt;Value, PP , EP&gt; and safe_unsigned_literal&lt;Value, PP, EP&gt;"><code class="computeroutput">safe_literal</code></a>
276      will future-proof your code against well-meaning, but code-breaking
277      updates.</p>
278</div>
279<div class="section">
280<div class="titlepage"><div><div><h5 class="title">
281<a name="idm130203320752"></a>Adjust type promotion rules.</h5></div></div></div>
282<p>Another way to avoid arithmetic errors like overflow is to promote
283      types to larger sizes before doing the arithmetic.</p>
284<p>Stepping back, we can see that many of the cases of invalid
285      arithmetic wouldn't exist if the result types were larger. So we can
286      avoid these problems by replacing the C++ type promotion rules for
287      expressions with our own rules. This can be done by specifying a
288      promotion policy <code class="computeroutput"><code class="computeroutput">automatic</code></code>. The policy stores
289      the result of an expression in the smallest size type that can
290      accommodate the largest value that an expression can yield. No checking
291      for exceptions is necessary. The following example illustrates
292      this.</p>
293<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">safe_numerics</span><span class="special">/</span><span class="identifier">safe_integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
294<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
295
296<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">[</span><span class="special">]</span><span class="special">)</span><span class="special">{</span>
297    <span class="keyword">using</span> <span class="identifier">safe_int</span> <span class="special">=</span> <span class="identifier">safe</span><span class="special">&lt;</span>
298        <span class="keyword">int</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">automatic</span><span class="special">,</span>
299        <span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">default_exception_policy</span>
300    <span class="special">&gt;</span><span class="special">;</span>
301    <span class="identifier">safe_int</span> <span class="identifier">i</span><span class="special">;</span>
302    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cin</span> <span class="special">&gt;&gt;</span> <span class="identifier">i</span><span class="special">;</span> <span class="comment">// might throw exception</span>
303    <span class="keyword">auto</span> <span class="identifier">j</span> <span class="special">=</span> <span class="identifier">i</span> <span class="special">*</span> <span class="identifier">i</span><span class="special">;</span> <span class="comment">// won't ever trap - result type can hold the maximum value of i * i</span>
304    <span class="identifier">static_assert</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">numeric</span><span class="special">::</span><span class="identifier">is_safe</span><span class="special">&lt;</span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">j</span><span class="special">)</span><span class="special">&gt;</span><span class="special">::</span><span class="identifier">value</span><span class="special">)</span><span class="special">;</span> <span class="comment">// result is another safe type</span>
305    <span class="identifier">static_assert</span><span class="special">(</span>
306        <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">i</span> <span class="special">*</span> <span class="identifier">i</span><span class="special">)</span><span class="special">&gt;</span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="special">)</span> <span class="special">&gt;=</span>
307        <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">safe_int</span><span class="special">&gt;</span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">safe_int</span><span class="special">&gt;</span><span class="special">::</span><span class="identifier">max</span><span class="special">(</span><span class="special">)</span>
308    <span class="special">)</span><span class="special">;</span> <span class="comment">// always true</span>
309
310    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
311<span class="special">}</span></pre>
312</div>
313</div>
314<div class="section">
315<div class="titlepage"><div><div><h4 class="title">
316<a name="idm130203247744"></a>Header</h4></div></div></div>
317<p><code class="filename"><a href="../../include/safe_integer.hpp" target="_top">#include
318    &lt;boost/numeric/safe_numerics/safe_integer.hpp&gt;</a></code></p>
319</div>
320</div>
321<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
322<td align="left"></td>
323<td align="right"><div class="copyright-footer">Copyright &#169; 2012-2018 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
324      Software License</a></p>
325</div></td>
326</tr></table>
327<hr>
328<div class="spirit-nav">
329<a accesskey="p" href="types.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_range.html"><img src="images/next.png" alt="Next"></a>
330</div>
331</body>
332</html>
333