123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
- <title>Numbers</title>
- <link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
- <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
- <link rel="home" href="../../index.html" title="Chapter 1. The Variadic Macro Data Library 1.9">
- <link rel="up" href="../vmd_specific.html" title="Specific macros for working with data types">
- <link rel="prev" href="vmd_identifier.html" title="Identifiers">
- <link rel="next" href="vmd_type.html" title="Types">
- </head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <table cellpadding="2" width="100%"><tr>
- <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
- <td align="center"><a href="../../../../../../index.html">Home</a></td>
- <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
- <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
- <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
- <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <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>
- </div>
- <div class="section">
- <div class="titlepage"><div><div><h3 class="title">
- <a name="variadic_macro_data.vmd_specific.vmd_number"></a><a class="link" href="vmd_number.html" title="Numbers">Numbers</a>
- </h3></div></div></div>
- <p>
- A number in VMD is a preprocessing 'pp-number', limited to a Boost PP number.
- This is an integral literal between 0 and 256. The form of the number does
- not contain leading zeros. Acceptable as numbers are:
- </p>
- <pre class="programlisting"><span class="number">0</span>
- <span class="number">127</span>
- <span class="number">33</span>
- <span class="number">254</span>
- <span class="number">18</span>
- </pre>
- <p>
- but not:
- </p>
- <pre class="programlisting"><span class="number">033</span>
- <span class="number">06</span>
- <span class="number">00</span><span class="number">9</span>
- <span class="number">00</span>
- </pre>
- <h5>
- <a name="variadic_macro_data.vmd_specific.vmd_number.h0"></a>
- <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
- testing any number</a>
- </h5>
- <p>
- As can be seen from the explanation of an identifier, a number is merely
- a small subset of all possible identifiers, for which VMD internally provides
- registration macros for its use and pre-detection macros for its use. Therefore
- the particular constraint on the input to test is exactly the same as for
- identifiers.
- </p>
- <p>
- The constraint is that the beginning input character, ignoring any whitespace,
- passed as the input to test must be either:
- </p>
- <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
- <li class="listitem">
- an identifier character, ie. an alphanumeric or an underscore
- </li>
- <li class="listitem">
- the left parenthesis of a tuple
- </li>
- </ul></div>
- <p>
- and if the first character is not the left parenthesis of a tuple the remaining
- characters must be alphanumeric or an underscore until a space character
- or end of input occurs.
- </p>
- <p>
- If this is not the case the behavior is undefined, and most likely a preprocessing
- error will occur.
- </p>
- <h5>
- <a name="variadic_macro_data.vmd_specific.vmd_number.h1"></a>
- <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
- for a number macro</a>
- </h5>
- <p>
- The macro used to test for any number in VMD is called BOOST_VMD_IS_NUMBER.
- The macro takes a single parameter, the input to test against.
- </p>
- <p>
- The macro returns 1 if the parameter is a Boost PP number, otherwise the
- macro returns 0.
- </p>
- <p>
- The Boost PP library has a great amount of functionality for working with
- numbers, so once you use VMD to parse/test for a number you can use Boost
- PP to work with that number in various ways. The VMD makes no attempt to
- duplicate the functionality of numbers that in the Boost PP library.
- </p>
- <p>
- Any number is also an identifier, which has been registered and pre-detected,
- so you can also use the VMD functionality which works with identifiers to
- work with a number as an identifier if you like.
- </p>
- <h5>
- <a name="variadic_macro_data.vmd_specific.vmd_number.h2"></a>
- <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>
- </h5>
- <p>
- Let us look at an example of how to use BOOST_VMD_IS_NUMBER.
- </p>
- <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>
- <span class="identifier">BOOST_VMD_IS_NUMBER</span><span class="special">(</span><span class="identifier">input</span><span class="special">)</span>
- <span class="identifier">returns</span><span class="special">:</span>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- </pre>
- <h5>
- <a name="variadic_macro_data.vmd_specific.vmd_number.h3"></a>
- <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>
- </h5>
- <p>
- To use the BOOST_VMD_IS_NUMBER macro either include the general header:
- </p>
- <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>
- </pre>
- <p>
- or include the specific header:
- </p>
- <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>
- </pre>
- </div>
- <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
- <td align="left"></td>
- <td align="right"><div class="copyright-footer">Copyright © 2010-2017 Tropic Software
- East Inc</div></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <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>
- </div>
- </body>
- </html>
|