vmd_introduction.qbk 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. [/
  2. (C) Copyright Edward Diener 2011-2017
  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_intro Introduction]
  8. Welcome to the Variadic Macro Data library.
  9. The Variadic Macro Data library, referred to hereafter as VMD for
  10. short, is a library of variadic macros which provide enhancements
  11. to the functionality in the Boost preprocessor library ( Boost PP ),
  12. especially as it relates to preprocessor data types.
  13. The preprocessor data types with which VMD has specific functionality
  14. are emptiness, identifiers, numbers ( a subset of identifiers ),
  15. types ( a subset of identifiers ), Boost PP arrays,
  16. Boost PP lists, Boost PP seqs, Boost PP tuples,
  17. and sequences. The first four are basic preprocessor data types
  18. while the latter five are composite preprocessor data types. A
  19. sequence is zero or more of the other preprocessor data types
  20. following each other.
  21. [heading Data type examples]
  22. [table:dwe Data types with examples
  23. [[Type] [Example]]
  24. [[identifier] [anyname]]
  25. [[number] [47]]
  26. [[type] [BOOST_VMD_TYPE_NUMBER]]
  27. [[array] [(4,(an_identifier,156,BOOST_VMD_TYPE_IDENTIFIER))]]
  28. [[list] [(78,(some_identifier,(BOOST_VMD_TYPE_TYPE,BOOST_PP_NIL)))]]
  29. [[seq] [(identifier)(89)(245)]]
  30. [[tuple] [(any_id,175,BOOST_VMD_TYPE_LIST,happy,21)]]
  31. [[sequence] [tree 59 (56,BOOST_VMD_TYPE_SEQ) (128)(fire)(clown) (47,(BOOST_VMD_TYPE_TUPLE,BOOST_PP_NIL))]]
  32. ]
  33. Emptiness is the lack of any preprocessing tokens. A macro which
  34. expands to nothing, as in:
  35. #define RETURN_NOTHING(x)
  36. is said to return emptiness. Conversely a macro could accept
  37. nothing when invoked, such as in:
  38. RETURN_NOTHING()
  39. Finally emptiness can be part of any composite data type as in:
  40. (45,,some_name)
  41. where the second tuple element is empty.
  42. [heading What is the advantage ?]
  43. VMD can identify any of the preprocessor data types previously mentioned,
  44. and can parse sequences into their individual preprocessor data types.
  45. You may well ask why that is important.
  46. In Boost PP macro programming a great deal of the control logic of
  47. designing a macro is based on the support Boost PP has for numbers
  48. and testing for the value of a number, in particular 0 and 1 to represent
  49. boolean choices. Essentially Boost PP often uses the value of a number to
  50. control the logic in a macro's design.
  51. VMD does not attempt, in any way, to duplicate Boost PP's support for
  52. testing the value of numbers or of the boolean 0 or 1 values, but just
  53. reuses that functionality. What VMD offers, which goes beyond Boost PP,
  54. is a system for deciphering the preprocessor data types, as well as
  55. comparing any of the preprocessor data types for equality to any given
  56. value. This allows macro logic to be designed in a more flexible way,
  57. relying on the type of data and/or the value of the data. If this intrigues
  58. you, continue reading to understand how you can use VMD to do macro programming.
  59. [heading Functionality areas]
  60. The functionality of the library may be summed up as:
  61. # Provide a better way of testing for and using empty parameters and empty preprocessor data.
  62. # Provide ways for testing/parsing for identifiers, numbers, types, tuples, arrays, lists, and seqs.
  63. # Provide ways for testing/parsing sequences of identifiers, numbers, types, tuples, arrays, lists. and seqs.
  64. # Provide some useful variadic macros not in Boost PP.
  65. The library is a header only library and all macros in the
  66. library are included by a single header, whose name is 'vmd.hpp'.
  67. Individual headers may be used for different functionality
  68. in the library and will be denoted when that functionality is
  69. explained.
  70. All the macros in the library begin with the sequence 'BOOST_VMD_'
  71. to distinguish them from other macros the end-user might use. Therefore
  72. the end-user should not use any C++ identifiers, whether in macros or
  73. otherwise, which being with the sequence 'BOOST_VMD_'.
  74. Use of the library is only dependent on Boost PP. The library also
  75. uses Boost detail lightweight_test.hpp for its own tests.
  76. [endsect]