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