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