1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 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 1. 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 and pre-detection macros for its use. Therefore the particular 57 constraint on the input to test is exactly the same as for identifiers. 58 </p> 59<p> 60 The constraint is that the beginning input character, ignoring any whitespace, 61 passed as the input to test must be either: 62 </p> 63<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 64<li class="listitem"> 65 an identifier character, ie. an alphanumeric or an underscore 66 </li> 67<li class="listitem"> 68 the left parenthesis of a tuple 69 </li> 70</ul></div> 71<p> 72 and if the first character is not the left parenthesis of a tuple the remaining 73 characters must be alphanumeric or an underscore until a space character 74 or end of input occurs. 75 </p> 76<p> 77 If this is not the case the behavior is undefined, and most likely a preprocessing 78 error will occur. 79 </p> 80<h5> 81<a name="variadic_macro_data.vmd_specific.vmd_number.h1"></a> 82 <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 83 for a number macro</a> 84 </h5> 85<p> 86 The macro used to test for any number in VMD is called BOOST_VMD_IS_NUMBER. 87 The macro takes a single variadic parameter, the input to test against. 88 </p> 89<p> 90 The macro returns 1 if the parameter is a Boost PP number, otherwise the 91 macro returns 0. 92 </p> 93<p> 94 The Boost PP library has a great amount of functionality for working with 95 numbers, so once you use VMD to parse/test for a number you can use Boost 96 PP to work with that number in various ways. The VMD library makes no attempt 97 to duplicate the functionality of numbers that in the Boost PP library. 98 </p> 99<p> 100 Any number is also an identifier, which has been registered and pre-detected, 101 so you can also use the VMD functionality which works with identifiers to 102 work with a number as an identifier if you like. 103 </p> 104<h5> 105<a name="variadic_macro_data.vmd_specific.vmd_number.h2"></a> 106 <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> 107 </h5> 108<p> 109 Let us look at an example of how to use BOOST_VMD_IS_NUMBER. 110 </p> 111<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">></span> 112 113<span class="identifier">BOOST_VMD_IS_NUMBER</span><span class="special">(</span><span class="identifier">input</span><span class="special">)</span> 114 115<span class="identifier">returns</span><span class="special">:</span> 116 117<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> 118<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> 119<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> 120<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> 121<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> 122<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> 123<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> 124<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> 125<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> 126<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> 127</pre> 128<h5> 129<a name="variadic_macro_data.vmd_specific.vmd_number.h3"></a> 130 <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> 131 </h5> 132<p> 133 To use the BOOST_VMD_IS_NUMBER macro either include the general header: 134 </p> 135<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">></span> 136</pre> 137<p> 138 or include the specific header: 139 </p> 140<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">></span> 141</pre> 142</div> 143<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 144<td align="left"></td> 145<td align="right"><div class="copyright-footer">Copyright © 2010-2017 Tropic Software 146 East Inc</div></td> 147</tr></table> 148<hr> 149<div class="spirit-nav"> 150<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> 151</div> 152</body> 153</html> 154