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:
0 127 33 254 18
033 06 009 00
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 and pre-detection macros for its use. Therefore the particular constraint on the input to test is exactly the same as for identifiers.
The constraint is that the beginning input character, ignoring any whitespace, passed as the input to test must be either:
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.
If this is not the case the behavior is undefined, and most likely a preprocessing error will occur.
The macro used to test for any number in VMD is called BOOST_VMD_IS_NUMBER. The macro takes a single variadic parameter, the input to test against.
The macro returns 1 if the parameter is a Boost PP number, otherwise the macro returns 0.
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 library makes no attempt to duplicate the functionality of numbers that in the Boost PP library.
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.
Let us look at an example of how to use BOOST_VMD_IS_NUMBER.
#include <boost/vmd/is_number.hpp> BOOST_VMD_IS_NUMBER(input) returns: if input = 0, 1 if input = 44, 1 if input = SQUARE, 0 if input = 44 DATA, 0 since there are tokens after the number if input = 044, 0 since no leading zeros are allowed for our Boost PP numbers if input = 256, 1 if input = 257, 0 since it falls outside the Boost PP number range of 0-256 if input = %44, does not meet the constraint therefore undefined behavior if input = 44.0, does not meet the constraint therefore undefined behavior if input = ( 44 ), 0 since the macro begins with a tuple and this can be tested for
To use the BOOST_VMD_IS_NUMBER macro either include the general header:
or include the specific header: