File: vmd_identifying.qbk

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (54 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[/ 
  (C) Copyright Edward Diener 2011-2015,2020
  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE_1_0.txt or copy at
  http://www.boost.org/LICENSE_1_0.txt).
]

[section:vmd_identifying Identifying macros and BOOST_VMD_IS_EMPTY]

The various macros for identifying VMD data types complement
the ability to identify emptiness using BOOST_VMD_IS_EMPTY.
The general name I will use in this documentation for these 
specific macros is "identifying macros." The identifying macros
also share with BOOST_VMD_IS_EMPTY the inherent flaw
mentioned when discussing BOOST_VMD_IS_EMPTY prior to the C++20
standard, since they themselves use BOOST_VMD_IS_EMPTY to determine
that the input has ended.

To recapitulate the flaw with BOOST_VMD_IS_EMPTY prior to C++20:

* using a standard C++ compiler if the input ends with the
name of a function-like macro, and that macro takes two or
more parameters, a preprocessing error will occur.
* using the VC++ compiler with its default preprocessor if the input consists of the name
of a function-like macro, and that macro when invoked with no 
parameters returns a tuple, the macro erroneously returns 1, 
meaning that the input is empty.
* even if the function-like macro takes one parameter, passing
emptiness to that macro could cause a preprocessing error.

The obvious way to avoid the BOOST_VMD_IS_EMPTY problem with the 
identifying macros is to design input so that the name of a function-like
macro is never passed as a parameter. This can be done, if one uses
VMD and has situations where the input could contain
a function-like macro name, by having that function-like macro name placed
within a Boost PP data type, such as a tuple, without attempting to identify
the type of the tuple element using VMD. In other word if the input is:

 ( SOME_FUNCTION_MACRO_NAME )
 
and we have the macro definition:

 #define SOME_FUNCTION_MACRO_NAME(x,y) some_output
 
VMD can still parse the input as a tuple, if desired, using BOOST_VMD_IS_TUPLE
without encountering the BOOST_VMD_IS_EMPTY problem. However if the input is:

 SOME_FUNCTION_MACRO_NAME
 
either directly or through accessing the above tuple's first element, and the 
programmer attempts to use BOOST_VMD_IS_IDENTIFIER with this input, the 
BOOST_VMD_IS_EMPTY problem will occur.

[endsect]