1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Identifying data types</title> 5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Chapter 1. The Variadic Macro Data Library 1.9"> 8<link rel="up" href="../vmd_specific.html" title="Specific macros for working with data types"> 9<link rel="prev" href="vmd_pp_data_types.html" title="VMD and Boost PP data types"> 10<link rel="next" href="../vmd_generic.html" title="Generic macros for working with data types"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="vmd_pp_data_types.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../vmd_specific.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../vmd_generic.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="variadic_macro_data.vmd_specific.vmd_identifying"></a><a class="link" href="vmd_identifying.html" title="Identifying data types">Identifying 28 data types</a> 29</h3></div></div></div> 30<h5> 31<a name="variadic_macro_data.vmd_specific.vmd_identifying.h0"></a> 32 <span class="phrase"><a name="variadic_macro_data.vmd_specific.vmd_identifying.identifying_macros_and_boost_vmd"></a></span><a class="link" href="vmd_identifying.html#variadic_macro_data.vmd_specific.vmd_identifying.identifying_macros_and_boost_vmd">Identifying 33 macros and BOOST_VMD_IS_EMPTY </a> 34 </h5> 35<p> 36 The various macros for identifying VMD data types complement the ability 37 to identify emptiness using BOOST_VMD_IS_EMPTY. The general name I will use 38 in this documentation for these specific macros is "identifying macros." 39 The identifying macros also share with BOOST_VMD_IS_EMPTY the inherent flaw 40 mentioned when discussing BOOST_VMD_IS_EMPTY prior to the C++20 standard, 41 since they themselves use BOOST_VMD_IS_EMPTY to determine that the input 42 has ended. 43 </p> 44<p> 45 To recapitulate the flaw with BOOST_VMD_IS_EMPTY prior to C++20: 46 </p> 47<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 48<li class="listitem"> 49 using a standard C++ compiler if the input ends with the name of a function-like 50 macro, and that macro takes two or more parameters, a preprocessing error 51 will occur. 52 </li> 53<li class="listitem"> 54 using the VC++ compiler if the input consists of the name of a function-like 55 macro, and that macro when invoked with no parameters returns a tuple, 56 the macro erroneously returns 1, meaning that the input is empty. 57 </li> 58<li class="listitem"> 59 even if the function-like macro takes one parameter, passing emptiness 60 to that macro could cause a preprocessing error. 61 </li> 62</ul></div> 63<p> 64 The obvious way to avoid the BOOST_VMD_IS_EMPTY problem with the identifying 65 macros is to design input so that the name of a function-like macro is never 66 passed as a parameter. This can be done, if one uses VMD and has situations 67 where the input could contain a function-like macro name, by having that 68 function-like macro name placed within a Boost PP data type, such as a tuple, 69 without attempting to identify the type of the tuple element using VMD. In 70 other word if the input is: 71 </p> 72<pre class="programlisting"><span class="special">(</span> <span class="identifier">SOME_FUNCTION_MACRO_NAME</span> <span class="special">)</span> 73</pre> 74<p> 75 and we have the macro definition: 76 </p> 77<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">SOME_FUNCTION_MACRO_NAME</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span><span class="identifier">y</span><span class="special">)</span> <span class="identifier">some_output</span> 78</pre> 79<p> 80 VMD can still parse the input as a tuple, if desired, using BOOST_VMD_IS_TUPLE 81 without encountering the BOOST_VMD_IS_EMPTY problem. However if the input 82 is: 83 </p> 84<pre class="programlisting"><span class="identifier">SOME_FUNCTION_MACRO_NAME</span> 85</pre> 86<p> 87 either directly or through accessing the above tuple's first element, and 88 the programmer attempts to use BOOST_VMD_IS_IDENTIFIER with this input, the 89 BOOST_VMD_IS_EMPTY problem will occur. 90 </p> 91<h5> 92<a name="variadic_macro_data.vmd_specific.vmd_identifying.h1"></a> 93 <span class="phrase"><a name="variadic_macro_data.vmd_specific.vmd_identifying.identifying_macros_and_programmi"></a></span><a class="link" href="vmd_identifying.html#variadic_macro_data.vmd_specific.vmd_identifying.identifying_macros_and_programmi">Identifying 94 macros and programming flexibility </a> 95 </h5> 96<p> 97 The VMD identifying macros give the preprocessor metaprogrammer a great amount 98 of flexibility when designing macros. It is not merely the flexibility of 99 allowing direct parameters to a macro to be different data types, and having 100 the macro work differently depending on the type of data passed to it, but 101 it is also the flexibility of allowing individual elements of the higher 102 level Boost PP data types to be different data types and have the macro work 103 correctly depending on the type of data type passed as part of those elements. 104 </p> 105<p> 106 With this flexibility also comes a greater amount of responsibility. For 107 the macro designer this responsibility is twofold: 108 </p> 109<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 110<li class="listitem"> 111 To carefully document the possible combinations of acceptable data and 112 what they mean. 113 </li> 114<li class="listitem"> 115 To balance flexibility with ease of use so that the macro does not become 116 so hard to understand that the programmer invoking the macro gives up 117 using it entirely. 118 </li> 119</ul></div> 120<p> 121 For the programmer invoking a macro the responsibility is to understand the 122 documentation and not attempt to pass to the macro data which may cause incorrect 123 results or preprocessing errors. 124 </p> 125</div> 126<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 127<td align="left"></td> 128<td align="right"><div class="copyright-footer">Copyright © 2010-2017 Tropic Software 129 East Inc</div></td> 130</tr></table> 131<hr> 132<div class="spirit-nav"> 133<a accesskey="p" href="vmd_pp_data_types.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../vmd_specific.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../vmd_generic.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 134</div> 135</body> 136</html> 137