Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/doc/html/boost_staticassert/how.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 4.2 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title> How it works</title>
5<link rel="stylesheet" href="../boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
7<link rel="start" href="../index.html" title="The Boost C++ Libraries">
8<link rel="up" href="../boost_staticassert.html" title="Chapter 10. Boost.StaticAssert">
9<link rel="prev" href="../boost_staticassert.html" title="Chapter 10. Boost.StaticAssert">
10<link rel="next" href="test.html" title=" Test Programs">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%">
14<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td>
15<td align="center"><a href="../../../index.htm">Home</a></td>
16<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="../../../people/people.htm">People</a></td>
18<td align="center"><a href="../../../more/faq.htm">FAQ</a></td>
19<td align="center"><a href="../../../more/index.htm">More</a></td>
20</table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="../boost_staticassert.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_staticassert.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="test.html"><img src="../images/next.png" alt="Next"></a>
24</div>
25<div class="section" lang="en">
26<div class="titlepage"><div><div><h3 class="title">
27<a name="boost_staticassert.how"></a> How it works</h3></div></div></div>
28<p><code class="computeroutput"><span class="identifier">BOOST_STATIC_ASSERT</span></code> works as follows. There is class <code class="computeroutput"><span class="identifier">STATIC_ASSERTION_FAILURE</span></code>
29 which is defined as:</p>
30<pre class="programlisting"><code class="literal"><span class="keyword">namespace</span><span class="identifier"> boost</span><span class="special">{</span><span class="keyword">
31
32template</span><span class="special"> &lt;</span><span class="keyword">bool</span><span class="special">&gt;</span><span class="keyword"> struct</span><span class="identifier"> STATIC_ASSERTION_FAILURE</span><span class="special">;</span><span class="keyword">
33
34template</span><span class="special"> &lt;&gt;</span><span class="keyword"> struct</span><span class="identifier"> STATIC_ASSERTION_FAILURE</span><span class="special">&lt;</span><span class="keyword">true</span><span class="special">&gt;{};</span><span class="special">
35
36}</span></code></pre>
37<p>
38The key feature is that the error message triggered by the undefined
39expression <code class="computeroutput"><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">STATIC_ASSERTION_FAILURE</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;)</span></code>, tends to be consistent
40across a wide variety of compilers. The rest of the machinery of
41<code class="computeroutput"><span class="identifier">BOOST_STATIC_ASSERT</span></code> is just a way to feed the <code class="computeroutput"><span class="keyword">sizeof</span></code> expression into a <code class="computeroutput"><span class="keyword">typedef</span></code>.
42The use of a macro here is somewhat ugly; however boost members have spent
43considerable effort trying to invent a static assert that avoided macros,
44all to no avail. The general conclusion was that the good of a static assert
45working at namespace, function, and class scope outweighed the ugliness of a macro.</p>
46</div>
47<table width="100%"><tr>
48<td align="left"></td>
49<td align="right"><small>Copyright © 2000, 2005 Steve Cleary and John Maddock</small></td>
50</tr></table>
51<hr>
52<div class="spirit-nav">
53<a accesskey="p" href="../boost_staticassert.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_staticassert.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="test.html"><img src="../images/next.png" alt="Next"></a>
54</div>
55</body>
56</html>
Note: See TracBrowser for help on using the repository browser.