Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / vmd / doc / html / variadic_macro_data / vmd_specific / vmd_number.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Numbers</title>
5 <link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Chapter&#160;1.&#160;The Variadic Macro Data Library 1.9">
8 <link rel="up" href="../vmd_specific.html" title="Specific macros for working with data types">
9 <link rel="prev" href="vmd_identifier.html" title="Identifiers">
10 <link rel="next" href="vmd_type.html" title="Types">
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 alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="vmd_identifier.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../vmd_specific.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="vmd_type.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="variadic_macro_data.vmd_specific.vmd_number"></a><a class="link" href="vmd_number.html" title="Numbers">Numbers</a>
28 </h3></div></div></div>
29 <p>
30         A number in VMD is a preprocessing 'pp-number', limited to a Boost PP number.
31         This is an integral literal between 0 and 256. The form of the number does
32         not contain leading zeros. Acceptable as numbers are:
33       </p>
34 <pre class="programlisting"><span class="number">0</span>
35 <span class="number">127</span>
36 <span class="number">33</span>
37 <span class="number">254</span>
38 <span class="number">18</span>
39 </pre>
40 <p>
41         but not:
42       </p>
43 <pre class="programlisting"><span class="number">033</span>
44 <span class="number">06</span>
45 <span class="number">00</span><span class="number">9</span>
46 <span class="number">00</span>
47 </pre>
48 <h5>
49 <a name="variadic_macro_data.vmd_specific.vmd_number.h0"></a>
50         <span class="phrase"><a name="variadic_macro_data.vmd_specific.vmd_number.problem_testing_any_number"></a></span><a class="link" href="vmd_number.html#variadic_macro_data.vmd_specific.vmd_number.problem_testing_any_number">Problem
51         testing any number</a>
52       </h5>
53 <p>
54         As can be seen from the explanation of an identifier, a number is merely
55         a small subset of all possible identifiers, for which VMD internally provides
56         registration macros for its use and pre-detection macros for its use. Therefore
57         the particular constraint on the input to test is exactly the same as for
58         identifiers.
59       </p>
60 <p>
61         The constraint is that the beginning input character, ignoring any whitespace,
62         passed as the input to test must be either:
63       </p>
64 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
65 <li class="listitem">
66             an identifier character, ie. an alphanumeric or an underscore
67           </li>
68 <li class="listitem">
69             the left parenthesis of a tuple
70           </li>
71 </ul></div>
72 <p>
73         and if the first character is not the left parenthesis of a tuple the remaining
74         characters must be alphanumeric or an underscore until a space character
75         or end of input occurs.
76       </p>
77 <p>
78         If this is not the case the behavior is undefined, and most likely a preprocessing
79         error will occur.
80       </p>
81 <h5>
82 <a name="variadic_macro_data.vmd_specific.vmd_number.h1"></a>
83         <span class="phrase"><a name="variadic_macro_data.vmd_specific.vmd_number.testing_for_a_number_macro"></a></span><a class="link" href="vmd_number.html#variadic_macro_data.vmd_specific.vmd_number.testing_for_a_number_macro">Testing
84         for a number macro</a>
85       </h5>
86 <p>
87         The macro used to test for any number in VMD is called BOOST_VMD_IS_NUMBER.
88         The macro takes a single parameter, the input to test against.
89       </p>
90 <p>
91         The macro returns 1 if the parameter is a Boost PP number, otherwise the
92         macro returns 0.
93       </p>
94 <p>
95         The Boost PP library has a great amount of functionality for working with
96         numbers, so once you use VMD to parse/test for a number you can use Boost
97         PP to work with that number in various ways. The VMD makes no attempt to
98         duplicate the functionality of numbers that in the Boost PP library.
99       </p>
100 <p>
101         Any number is also an identifier, which has been registered and pre-detected,
102         so you can also use the VMD functionality which works with identifiers to
103         work with a number as an identifier if you like.
104       </p>
105 <h5>
106 <a name="variadic_macro_data.vmd_specific.vmd_number.h2"></a>
107         <span class="phrase"><a name="variadic_macro_data.vmd_specific.vmd_number.example"></a></span><a class="link" href="vmd_number.html#variadic_macro_data.vmd_specific.vmd_number.example">Example</a>
108       </h5>
109 <p>
110         Let us look at an example of how to use BOOST_VMD_IS_NUMBER.
111       </p>
112 <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">vmd</span><span class="special">/</span><span class="identifier">is_number</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
113
114 <span class="identifier">BOOST_VMD_IS_NUMBER</span><span class="special">(</span><span class="identifier">input</span><span class="special">)</span>
115
116 <span class="identifier">returns</span><span class="special">:</span>
117
118 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="number">1</span>
119 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="number">44</span><span class="special">,</span> <span class="number">1</span>
120 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="identifier">SQUARE</span><span class="special">,</span> <span class="number">0</span>
121 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="number">44</span> <span class="identifier">DATA</span><span class="special">,</span> <span class="number">0</span> <span class="identifier">since</span> <span class="identifier">there</span> <span class="identifier">are</span> <span class="identifier">tokens</span> <span class="identifier">after</span> <span class="identifier">the</span> <span class="identifier">number</span>
122 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="number">044</span><span class="special">,</span> <span class="number">0</span> <span class="identifier">since</span> <span class="identifier">no</span> <span class="identifier">leading</span> <span class="identifier">zeros</span> <span class="identifier">are</span> <span class="identifier">allowed</span> <span class="keyword">for</span> <span class="identifier">our</span> <span class="identifier">Boost</span> <span class="identifier">PP</span> <span class="identifier">numbers</span>
123 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="number">256</span><span class="special">,</span> <span class="number">1</span>
124 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="number">257</span><span class="special">,</span> <span class="number">0</span> <span class="identifier">since</span> <span class="identifier">it</span> <span class="identifier">falls</span> <span class="identifier">outside</span> <span class="identifier">the</span> <span class="identifier">Boost</span> <span class="identifier">PP</span> <span class="identifier">number</span> <span class="identifier">range</span> <span class="identifier">of</span> <span class="number">0</span><span class="special">-</span><span class="number">256</span>
125 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="special">%</span><span class="number">44</span><span class="special">,</span> <span class="identifier">does</span> <span class="keyword">not</span> <span class="identifier">meet</span> <span class="identifier">the</span> <span class="identifier">constraint</span> <span class="identifier">therefore</span> <span class="identifier">undefined</span> <span class="identifier">behavior</span>
126 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="number">44.0</span><span class="special">,</span> <span class="identifier">does</span> <span class="keyword">not</span> <span class="identifier">meet</span> <span class="identifier">the</span> <span class="identifier">constraint</span> <span class="identifier">therefore</span> <span class="identifier">undefined</span> <span class="identifier">behavior</span>
127 <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="special">(</span> <span class="number">44</span> <span class="special">),</span> <span class="number">0</span> <span class="identifier">since</span> <span class="identifier">the</span> <span class="identifier">macro</span> <span class="identifier">begins</span> <span class="identifier">with</span> <span class="identifier">a</span> <span class="identifier">tuple</span> <span class="keyword">and</span> <span class="keyword">this</span> <span class="identifier">can</span> <span class="identifier">be</span> <span class="identifier">tested</span> <span class="keyword">for</span>
128 </pre>
129 <h5>
130 <a name="variadic_macro_data.vmd_specific.vmd_number.h3"></a>
131         <span class="phrase"><a name="variadic_macro_data.vmd_specific.vmd_number.usage"></a></span><a class="link" href="vmd_number.html#variadic_macro_data.vmd_specific.vmd_number.usage">Usage</a>
132       </h5>
133 <p>
134         To use the BOOST_VMD_IS_NUMBER macro either include the general header:
135       </p>
136 <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">vmd</span><span class="special">/</span><span class="identifier">vmd</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
137 </pre>
138 <p>
139         or include the specific header:
140       </p>
141 <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">vmd</span><span class="special">/</span><span class="identifier">is_number</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
142 </pre>
143 </div>
144 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
145 <td align="left"></td>
146 <td align="right"><div class="copyright-footer">Copyright &#169; 2010-2017 Tropic Software
147       East Inc</div></td>
148 </tr></table>
149 <hr>
150 <div class="spirit-nav">
151 <a accesskey="p" href="vmd_identifier.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../vmd_specific.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="vmd_type.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
152 </div>
153 </body>
154 </html>