vmd_identifying.qbk 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_identifying Identifying data types]
  8. [heading Identifying macros and BOOST_VMD_IS_EMPTY ]
  9. The various macros for identifying VMD data types complement
  10. the ability to identify emptiness using BOOST_VMD_IS_EMPTY.
  11. The general name I will use in this documentation for these
  12. specific macros is "identifying macros." The identifying macros
  13. also share with BOOST_VMD_IS_EMPTY the inherent flaw
  14. mentioned when discussing BOOST_VMD_IS_EMPTY, since they themselves
  15. use BOOST_VMD_IS_EMPTY to determine that the input has ended.
  16. To recapitulate the flaw with BOOST_VMD_IS_EMPTY:
  17. * using a standard C++ compiler if the input ends with the
  18. name of a function-like macro, and that macro takes two or
  19. more parameters, a preprocessing error will occur.
  20. * using the VC++ compiler if the input consists of the name
  21. of a function-like macro, and that macro when invoked with no
  22. parameters returns a tuple, the macro erroneously returns 1,
  23. meaning that the input is empty.
  24. * even if the function-like macro takes one parameter, passing
  25. emptiness to that macro could cause a preprocessing error.
  26. The obvious way to avoid the BOOST_VMD_IS_EMPTY problem with the
  27. identifying macros is to design input so that the name of a function-like
  28. macro is never passed as a parameter. This can be done, if one uses
  29. VMD and has situations where the input could contain
  30. a function-like macro name, by having that function-like macro name placed
  31. within a Boost PP data type, such as a tuple, without attempting to identify
  32. the type of the tuple element using VMD. In other word if the input is:
  33. ( SOME_FUNCTION_MACRO_NAME )
  34. and we have the macro definition:
  35. #define SOME_FUNCTION_MACRO_NAME(x,y) some_output
  36. VMD can still parse the input as a tuple, if desired, using BOOST_VMD_IS_TUPLE
  37. without encountering the BOOST_VMD_IS_EMPTY problem. However if the input is:
  38. SOME_FUNCTION_MACRO_NAME
  39. either directly or through accessing the above tuple's first element, and the
  40. programmer attempts to use BOOST_VMD_IS_IDENTIFIER with this input, the
  41. BOOST_VMD_IS_EMPTY problem will occur.
  42. [heading Identifying macros and programming flexibility ]
  43. The VMD identifying macros give the preprocessor metaprogrammer a great amount
  44. of flexibility when designing macros. It is not merely the flexibility of allowing
  45. direct parameters to a macro to be different data types, and having the macro work
  46. differently depending on the type of data passed to it, but it is also the flexibility
  47. of allowing individual elements of the higher level Boost PP data types to be
  48. different data types and have the macro work correctly depending on the type of data
  49. type passed as part of those elements.
  50. With this flexibility also comes a greater amount of responsibility. For the macro
  51. designer this responsibility is twofold:
  52. * To carefully document the possible combinations of acceptable data and what they mean.
  53. * To balance flexibility with ease of use so that the macro does not become so hard to
  54. understand that the programmer invoking the macro gives up using it entirely.
  55. For the programmer invoking a macro the responsibility is to understand the documentation
  56. and not attempt to pass to the macro data which may cause incorrect results or preprocessing
  57. errors.
  58. [endsect]