vmd_number.qbk 2.9 KB

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