vmd_dynamic_typing.qbk 2.0 KB

123456789101112131415161718192021222324252627282930313233343536
  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_dynamic_typing Input as dynamic types]
  8. Within the constraints based on the top-level types which VMD can parse,
  9. the libraries gives the end-user the ability to design macros with
  10. dynamic data types. By this I mean that a macro could be designed to handle
  11. different data types based on some documented agreement of different combinations
  12. of macro input meaning slightly different things. Add to this the ability
  13. to design such macros with variadic parameters and we have a preprocessor
  14. system of macro creation which to a lesser extent rivals the DSELS of template
  15. metaprogramming. Of course the preprocessor is not nearly as flexible as
  16. C++ templates, but still the sort of preprocessor metaprogramming one could
  17. do with VMD, and the underlying Boost PP, in creating flexible macros which
  18. can handle different combinations of data types is very interesting.
  19. Of course macros need to be usable by an end-user so the syntactical ability
  20. of sequences to represent different types of input data must
  21. be balanced against ease of use and understanding when using a macro. But because
  22. certain sequences can mimic C++ function calls to some extent it is possible
  23. to represent macros as a language closer to C++ with VMD.
  24. What is important when designing a macro in which you parse input to decide which type
  25. of data the invoker is passing to your macro is that you are aware of the constraints
  26. when parsing a data type. As an example if you design a macro where some input can either
  27. be a number, an identifier, or some other data type top-level input then attempting
  28. to parse the data to see if it is a number or identifier could fail with a preprocessor
  29. error and nullify your design if the data is not a VMD data type. So designing a macro with
  30. data types in mind often means restricting data to parseable top-level types.
  31. [endsect]