]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
2 | (C) Copyright Edward Diener 2011-2015 | |
3 | Distributed under the Boost Software License, Version 1.0. | |
4 | (See accompanying file LICENSE_1_0.txt or copy at | |
5 | http://www.boost.org/LICENSE_1_0.txt). | |
6 | ] | |
7 | ||
8 | [section:vmd_number Numbers] | |
9 | ||
10 | A number in VMD is a preprocessing 'pp-number', | |
11 | limited to a Boost PP number. This is an integral literal between 0 and 256. | |
12 | The form of the number does not contain leading zeros. Acceptable as numbers are: | |
13 | ||
14 | 0 | |
15 | 127 | |
16 | 33 | |
17 | 254 | |
18 | 18 | |
19 | ||
20 | but not: | |
21 | ||
22 | 033 | |
23 | 06 | |
24 | 009 | |
25 | 00 | |
26 | ||
27 | [heading Problem testing any number] | |
28 | ||
29 | As can be seen from the explanation of an identifier, a number is merely | |
30 | a small subset of all possible identifiers, for which VMD internally provides | |
31 | registration macros for its use and pre-detection macros for its use. Therefore the particular | |
32 | constraint on the input to test is exactly the same as for identifiers. | |
33 | ||
34 | The constraint is that the beginning input character, ignoring any whitespace, passed | |
35 | as the input to test must be either: | |
36 | ||
37 | * an identifier character, ie. an alphanumeric or an underscore | |
38 | * the left parenthesis of a tuple | |
39 | ||
40 | and if the first character is not the left parenthesis of a tuple | |
41 | the remaining characters must be alphanumeric or an underscore until a space character | |
42 | or end of input occurs. | |
43 | ||
44 | If this is not the case the behavior is undefined, and most likely | |
45 | a preprocessing error will occur. | |
46 | ||
47 | [heading Testing for a number macro] | |
48 | ||
49 | The macro used to test for any number in VMD is called BOOST_VMD_IS_NUMBER. | |
50 | The macro takes a single parameter, the input to test against. | |
51 | ||
52 | The macro returns 1 if the parameter is a Boost PP number, otherwise the macro returns 0. | |
53 | ||
54 | The Boost PP library has a great amount of functionality for working with numbers, | |
55 | so once you use VMD to parse/test for a number you can use Boost PP to work with that | |
56 | number in various ways. The VMD makes no attempt to duplicate the functionality | |
57 | of numbers that in the Boost PP library. | |
58 | ||
59 | Any number is also an identifier, which has been registered and pre-detected, | |
60 | so you can also use the VMD functionality which works with identifiers to work with | |
61 | a number as an identifier if you like. | |
62 | ||
63 | [heading Example] | |
64 | ||
65 | Let us look at an example of how to use BOOST_VMD_IS_NUMBER. | |
66 | ||
67 | #include <boost/vmd/is_number.hpp> | |
68 | ||
69 | BOOST_VMD_IS_NUMBER(input) | |
70 | ||
71 | returns: | |
72 | ||
73 | if input = 0, 1 | |
74 | if input = 44, 1 | |
75 | if input = SQUARE, 0 | |
76 | if input = 44 DATA, 0 since there are tokens after the number | |
77 | if input = 044, 0 since no leading zeros are allowed for our Boost PP numbers | |
78 | if input = 256, 1 | |
79 | if input = 257, 0 since it falls outside the Boost PP number range of 0-256 | |
80 | if input = %44, does not meet the constraint therefore undefined behavior | |
81 | if input = 44.0, does not meet the constraint therefore undefined behavior | |
82 | if input = ( 44 ), 0 since the macro begins with a tuple and this can be tested for | |
83 | ||
84 | [heading Usage] | |
85 | ||
86 | To use the BOOST_VMD_IS_NUMBER macro either include the general header: | |
87 | ||
88 | #include <boost/vmd/vmd.hpp> | |
89 | ||
90 | or include the specific header: | |
91 | ||
92 | #include <boost/vmd/is_number.hpp> | |
93 | ||
94 | [endsect] |