vmd_type.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>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&#160;1.&#160;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_number.html" title="Numbers">
  10. <link rel="next" href="vmd_pp_data_types.html" title="VMD and Boost PP 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_number.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_pp_data_types.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_type"></a><a class="link" href="vmd_type.html" title="Types">Types</a>
  28. </h3></div></div></div>
  29. <p>
  30. A subset of identifiers is VMD types, called a 'v-type'. These are identifiers
  31. which represent all of the preprocessor data types which VMD can parse. This
  32. subset of identifiers is automatically registered and pre-detected by VMD.
  33. Each identifier type begins with the unique prefix 'BOOST_VMD_TYPE_'.
  34. </p>
  35. <p>
  36. The actual types are:
  37. </p>
  38. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  39. <li class="listitem">
  40. BOOST_VMD_TYPE_EMPTY, represents emptiness, ie. "empty data"
  41. </li>
  42. <li class="listitem">
  43. BOOST_VMD_TYPE_ARRAY, a Boost PP array
  44. </li>
  45. <li class="listitem">
  46. BOOST_VMD_TYPE_LIST, a Boost PP list
  47. </li>
  48. <li class="listitem">
  49. BOOST_VMD_TYPE_SEQ, a Boost PP seq
  50. </li>
  51. <li class="listitem">
  52. BOOST_VMD_TYPE_TUPLE, a Boost PP tuple
  53. </li>
  54. <li class="listitem">
  55. BOOST_VMD_TYPE_IDENTIFIER, identifier
  56. </li>
  57. <li class="listitem">
  58. BOOST_BMD_TYPE_NUMBER, a number
  59. </li>
  60. <li class="listitem">
  61. BOOST_VMD_TYPE_TYPE, a type itself
  62. </li>
  63. <li class="listitem">
  64. BOOST_VMD_TYPE_SEQUENCE, a sequence
  65. </li>
  66. <li class="listitem">
  67. BOOST_VMD_TYPE_UNKNOWN, an unknown type
  68. </li>
  69. </ul></div>
  70. <p>
  71. Since a v-type is itself an identifier the particular constraint on the input
  72. to test is exactly the same as for identifiers.
  73. </p>
  74. <p>
  75. The constraint is that the beginning input character, ignoring any whitespace,
  76. passed as the input to test must be either:
  77. </p>
  78. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  79. <li class="listitem">
  80. an identifier character, ie. an alphanumeric or an underscore
  81. </li>
  82. <li class="listitem">
  83. the left parenthesis of a tuple
  84. </li>
  85. </ul></div>
  86. <p>
  87. and if the first character is not the left parenthesis of a tuple the remaining
  88. characters must be alphanumeric or an underscore until a space character
  89. or end of input occurs.
  90. </p>
  91. <p>
  92. If this is not the case the behavior is undefined, and most likely a preprocessing
  93. error will occur.
  94. </p>
  95. <p>
  96. The macro used to test for a particular type in VMD is called BOOST_VMD_IS_TYPE.
  97. The macro takes a single parameter, the input to test against.
  98. </p>
  99. <p>
  100. The macro returns 1 if the parameter is a v-type, otherwise the macro returns
  101. 0.
  102. </p>
  103. <p>
  104. A v-type is also an identifier, which has been registered and pre-detected,
  105. so you can also use the VMD functionality which works with identifiers to
  106. work with a v-type as an identifier if you like.
  107. </p>
  108. <h5>
  109. <a name="variadic_macro_data.vmd_specific.vmd_type.h0"></a>
  110. <span class="phrase"><a name="variadic_macro_data.vmd_specific.vmd_type.example"></a></span><a class="link" href="vmd_type.html#variadic_macro_data.vmd_specific.vmd_type.example">Example</a>
  111. </h5>
  112. <p>
  113. Let us look at an example of how to use BOOST_VMD_IS_TYPE.
  114. </p>
  115. <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">vmd</span><span class="special">/</span><span class="identifier">is_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  116. <span class="identifier">BOOST_VMD_IS_TYPE</span><span class="special">(</span><span class="identifier">input</span><span class="special">)</span>
  117. <span class="identifier">returns</span><span class="special">:</span>
  118. <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="identifier">BOOST_VMD_TYPE_SEQ</span><span class="special">,</span> <span class="number">1</span>
  119. <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="identifier">BOOST_VMD_TYPE_NUMBER</span><span class="special">,</span> <span class="number">1</span>
  120. <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="identifier">SQUARE</span><span class="special">,</span> <span class="number">0</span>
  121. <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="identifier">BOOST_VMD_TYPE_IDENTIFIER</span> <span class="identifier">DATA</span><span class="special">,</span> <span class="number">0</span> <span class="identifier">since</span> <span class="identifier">there</span> <span class="identifier">are</span> <span class="identifier">tokens</span> <span class="identifier">after</span> <span class="identifier">the</span> <span class="identifier">type</span>
  122. <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="special">%</span><span class="number">44</span><span class="special">,</span> <span class="identifier">does</span> <span class="keyword">not</span> <span class="identifier">meet</span> <span class="identifier">the</span> <span class="identifier">constraint</span> <span class="identifier">therefore</span> <span class="identifier">undefined</span> <span class="identifier">behavior</span>
  123. <span class="keyword">if</span> <span class="identifier">input</span> <span class="special">=</span> <span class="special">(</span> <span class="identifier">BOOST_VMD_TYPE_EMPTY</span> <span class="special">),</span> <span class="number">0</span> <span class="identifier">since</span> <span class="identifier">the</span> <span class="identifier">macro</span> <span class="identifier">begins</span> <span class="identifier">with</span> <span class="identifier">a</span> <span class="identifier">tuple</span> <span class="keyword">and</span> <span class="keyword">this</span> <span class="identifier">can</span> <span class="identifier">be</span> <span class="identifier">tested</span> <span class="keyword">for</span>
  124. </pre>
  125. <h5>
  126. <a name="variadic_macro_data.vmd_specific.vmd_type.h1"></a>
  127. <span class="phrase"><a name="variadic_macro_data.vmd_specific.vmd_type.usage"></a></span><a class="link" href="vmd_type.html#variadic_macro_data.vmd_specific.vmd_type.usage">Usage</a>
  128. </h5>
  129. <p>
  130. To use the BOOST_VMD_IS_TYPE macro either include the general header:
  131. </p>
  132. <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">vmd</span><span class="special">/</span><span class="identifier">vmd</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  133. </pre>
  134. <p>
  135. or include the specific header:
  136. </p>
  137. <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">vmd</span><span class="special">/</span><span class="identifier">is_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  138. </pre>
  139. </div>
  140. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  141. <td align="left"></td>
  142. <td align="right"><div class="copyright-footer">Copyright &#169; 2010-2017 Tropic Software
  143. East Inc</div></td>
  144. </tr></table>
  145. <hr>
  146. <div class="spirit-nav">
  147. <a accesskey="p" href="vmd_number.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_pp_data_types.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
  148. </div>
  149. </body>
  150. </html>