vmd_empty_ppdata.qbk 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. [/
  2. (C) Copyright Edward Diener 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. [section:vmd_empty_ppdata Functionality for "empty" seqs and tuples]
  8. Boost PP arrays and lists can be empty but seqs and tuples cannot.
  9. The form of an empty array is '(0,())' and the form of an empty
  10. list is 'BOOST_PP_NIL'. But the form of '()' does not represent
  11. an empty seq or an empty tuple. Instead for a seq it represents
  12. a one element seq whose data is empty, while for a tuple it
  13. represents a tuple with a size of 1 whose single element is empty.
  14. Not having a way to represent an empty seq or tuple represents a
  15. small problem for Boost PP users. For a tuple, especially, not being
  16. able to be "empty" is the only reason, when variadic macros are supported,
  17. why an end-user might prefer to use an array rather than a tuple as
  18. Boost PP preprocessor data. Otherwise, when using variadic macros, using
  19. a tuple is easier to notate and subsequently use than an array
  20. since no effort is needed to specify the number of elements of a tuple.
  21. VMD as we have seen has functionality to tell when preprocessor data is "empty"
  22. through its BOOST_VMD_IS_EMPTY macro. Because of this it is possible to treat
  23. emptiness, when applied to a seq or tuple, as an empty seq or an empty tuple
  24. respectively, thus allowing seqs and tuples to be empty, just as arrays and
  25. lists are.
  26. However there is one large problem when treating emptiness as an empty seq or
  27. empty tuple; Boost PP functionality for a seq or tuple knows nothing about it.
  28. In other words if you passed emptiness to a Boost PP macro which expects a
  29. seq or tuple, such as:
  30. BOOST_PP_SEQ_SIZE()
  31. or
  32. BOOST_PP_TUPLE_PUSH_BACK(,1)
  33. you would get UB, undefined behavior.
  34. In order to use seqs and tuples which can be empty VMD defines a number
  35. of macros which mimic many of those in Boost PP, but begin with BOOST_VMD_
  36. rather than BOOST_PP_. The VMD macros work with what I will call a 'VMD seq' or
  37. a 'VMD tuple', while the Boost PP equivalents work with the traditional seq
  38. or tuple. A VMD seq is a seq which may be empty and a VMD tuple is a tuple
  39. which may be empty. A VMD seq is therefore a superset of a normal seq and a
  40. VMD tuple is therefore a superset of a normal tuple. The VMD functionality
  41. therefore can accept a VMD seq or tuple or a normal seq or tuple whereas the
  42. equivalent Boost PP functionality only accepts a normal seq or tuple. To be more
  43. more precise the Boost PP functionality can accept a VMD seq or a VMD tuple as
  44. long as it is not empty. In other words there is no difference between a
  45. non-empty VMD seq or a Boost PP seq, or between a non-empty VMD tuple and
  46. a Boost PP tuple.
  47. The particular macros which VMD supplies, supporting VMD seqs and VMD tuples,
  48. are divided between array, list, seq, and tuple functionality. The actual header
  49. files for these macros are in sub-directories of the VMD directory, which start
  50. respectively with 'array','list','seq' and 'tuple'. The header files are all
  51. also included in the general boost/vmd/vmd.hpp header file.
  52. [heading Array macros]
  53. The array macros provide conversions from an array to a VMD seq or a VMD tuple.
  54. The array macros are:
  55. [table:vpp_array Array macros
  56. [[Macro][Parameter][Return][Functionality][Header]]
  57. [
  58. [BOOST_VMD_ARRAY_TO_SEQ]
  59. [array = a Boost PP array]
  60. [A VMD seq]
  61. [Converts an array to a VMD seq. If the array is empty the seq is empty, otherwise the conversion is the same as BOOST_PP_ARRAY_TO_SEQ]
  62. [boost/vmd/array/to_seq.hpp]
  63. ]
  64. [
  65. [BOOST_VMD_ARRAY_TO_TUPLE]
  66. [array = a Boost PP array]
  67. [A VMD tuple]
  68. [Converts an array to a VMD tuple. If the array is empty the tuple is empty, otherwise the conversion is the same as BOOST_PP_ARRAY_TO_TUPLE]
  69. [boost/vmd/array/to_tuple.hpp]
  70. ]
  71. ]
  72. The difference between the array conversion macros and their equivalent ones
  73. in Boost PP is that if the array is empty the VMD macros return emptiness
  74. whereas the Boost PP macros have UB.
  75. You can include the array macros either using their individual header files,
  76. the general 'boost/vmd/array.hpp' header file for all array macros, or the
  77. general header file 'boost/vmd/vmd.hpp' for all macros.
  78. [heading List macros]
  79. The list macros provide conversions from a list to a VMD seq or a VMD tuple.
  80. The list macros are:
  81. [table:vpp_list List macros
  82. [[Macro][Parameter][Return][Functionality][Header]]
  83. [
  84. [BOOST_VMD_LIST_TO_SEQ]
  85. [list = a Boost PP list]
  86. [A VMD seq]
  87. [Converts a list to a VMD seq. If the list is empty the seq is empty, otherwise the conversion is the same as BOOST_PP_LIST_TO_SEQ]
  88. [boost/vmd/list/to_seq.hpp]
  89. ]
  90. [
  91. [BOOST_VMD_LIST_TO_TUPLE]
  92. [list = a Boost PP list]
  93. [A VMD tuple]
  94. [Converts a list to a VMD tuple. If the list is empty the tuple is empty, otherwise the conversion is the same as BOOST_PP_LIST_TO_TUPLE]
  95. [boost/vmd/list/to_tuple.hpp]
  96. ]
  97. ]
  98. The difference between the list conversion macros and their equivalent ones
  99. in Boost PP is that if the list is empty the VMD macros return emptiness
  100. whereas the Boost PP macros have UB.
  101. You can include the list macros either using their individual header files,
  102. the general 'boost/vmd/list.hpp' header file for all list macros, or the
  103. general header file 'boost/vmd/vmd.hpp' for all macros.
  104. [heading Seq macros]
  105. The seq macros either work with a VMD seq or return A VMD seq. The seq macros are:
  106. [table:vpp_seq Seq macros
  107. [[Macro][Parameter][Return][Functionality][Header]]
  108. [
  109. [BOOST_VMD_IS_VMD_SEQ]
  110. [sequence = a VMD sequence]
  111. [1 if the VMD sequence is a VMD seq, else 0]
  112. [Tests a sequence as a VMD seq. If the sequence is empty returns 1, otherwise returns the same as BOOST_VMD_IS_SEQ]
  113. [boost/vmd/seq/is_vmd_seq.hpp]
  114. ]
  115. [
  116. [BOOST_VMD_SEQ_POP_BACK]
  117. [seq = a Boost PP seq]
  118. [A VMD seq]
  119. [Pops an element from the end of a seq. If the seq has a single element returns an empty seq, otherwise works exactly the same as BOOST_PP_SEQ_POP_BACK]
  120. [boost/vmd/seq/pop_back.hpp]
  121. ]
  122. [
  123. [BOOST_VMD_SEQ_POP_FRONT]
  124. [seq = a Boost PP seq]
  125. [A VMD seq]
  126. [Pops an element from the beginning of a seq. If the seq has a single element returns an empty seq, otherwise works exactly the same as BOOST_PP_SEQ_POP_FRONT]
  127. [boost/vmd/seq/pop_front.hpp]
  128. ]
  129. [
  130. [BOOST_VMD_SEQ_PUSH_BACK]
  131. [seq = a VMD seq, elem = element to push onto the end of the VMD seq]
  132. [A Boost PP seq]
  133. [Pushes an element onto the end of a VMD seq. If the VMD seq is empty the returned seq consists of that element, otherwise works exactly the same as BOOST_PP_SEQ_PUSH_BACK]
  134. [boost/vmd/seq/push_back.hpp]
  135. ]
  136. [
  137. [BOOST_VMD_SEQ_PUSH_FRONT]
  138. [seq = a VMD seq, elem = element to push onto the beginning of the VMD seq]
  139. [A Boost PP seq]
  140. [Pushes an element onto the beginning of a VMD seq. If the VMD seq is empty the returned seq consists of that element, otherwise works exactly the same as BOOST_PP_SEQ_PUSH_FRONT]
  141. [boost/vmd/seq/push_front.hpp]
  142. ]
  143. [
  144. [BOOST_VMD_SEQ_REMOVE]
  145. [seq = a Boost PP seq, i = index of element to remove]
  146. [A VMD seq]
  147. [Removes an element from a Boost PP seq. If the seq has a single element and the index to be removed is 0 returns an empty seq, otherwise works exactly the same as BOOST_PP_SEQ_REMOVE]
  148. [boost/vmd/seq/remove.hpp]
  149. ]
  150. [
  151. [BOOST_VMD_SEQ_SIZE]
  152. [seq = a VMD seq]
  153. [The number of elements in the VMD seq]
  154. [Returns the number of elements in the VMD seq. If the seq is empty returns 0, otherwise works exactly the same as BOOST_PP_SEQ_SIZE]
  155. [boost/vmd/seq/size.hpp]
  156. ]
  157. [
  158. [BOOST_VMD_SEQ_TO_ARRAY]
  159. [seq = a VMD seq]
  160. [A Boost PP array]
  161. [Converts a VMD seq to a Boost PP array. If the seq is empty returns an empty array whose form is '(0,())', otherwise works exactly the same as BOOST_PP_SEQ_TO_ARRAY]
  162. [boost/vmd/seq/to_array.hpp]
  163. ]
  164. [
  165. [BOOST_VMD_SEQ_TO_LIST]
  166. [seq = a VMD seq]
  167. [A Boost PP list]
  168. [Converts a VMD seq to a Boost PP list. If the seq is empty returns an empty list whose form is 'BOOST_PP_NIL', otherwise works exactly the same as BOOST_PP_SEQ_TO_LIST]
  169. [boost/vmd/seq/to_list.hpp]
  170. ]
  171. [
  172. [BOOST_VMD_SEQ_TO_TUPLE]
  173. [seq = a VMD seq]
  174. [A VMD tuple]
  175. [Converts a VMD seq to a VMD tuple. If the seq is empty returns an empty tuple, otherwise works exactly the same as BOOST_PP_SEQ_TO_TUPLE]
  176. [boost/vmd/seq/to_tuple.hpp]
  177. ]
  178. ]
  179. The difference between the seq macros and their equivalent ones in Boost PP is
  180. that working with a VMD seq or returning a VMD seq is valid with the seq macros
  181. but with the Boost PP equivalent macros working with an empty seq causes UB and
  182. returning an empty seq can never occur.
  183. You can include the seq macros either using their individual header files,
  184. the general 'boost/vmd/seq.hpp' header file for all seq macros, or the
  185. general header file 'boost/vmd/vmd.hpp' for all macros.
  186. [heading Tuple macros]
  187. The tuple macros either work with a VMD tuple or return a VMD tuple. The tuple macros are:
  188. [table:vpp_tuple Tuple macros
  189. [[Macro][Parameter][Return][Functionality][Header]]
  190. [
  191. [BOOST_VMD_IS_VMD_TUPLE]
  192. [sequence = a VMD sequence]
  193. [1 if the VMD sequence is a VMD tuple, else 0]
  194. [Tests a sequence as a VMD tuple. If the sequence is empty returns 1, otherwise returns the same as BOOST_VMD_IS_TUPLE]
  195. [boost/vmd/tuple/is_vmd_tuple.hpp]
  196. ]
  197. [
  198. [BOOST_VMD_TUPLE_POP_BACK]
  199. [tuple = a Boost PP tuple]
  200. [A VMD tuple]
  201. [Pops an element from the end of a tuple. If the tuple's size is 1 returns an empty tuple, otherwise works exactly the same as BOOST_PP_TUPLE_POP_BACK]
  202. [boost/vmd/tuple/pop_back.hpp]
  203. ]
  204. [
  205. [BOOST_VMD_TUPLE_POP_FRONT]
  206. [tuple = a Boost PP tuple]
  207. [A VMD tuple]
  208. [Pops an element from the beginning of a tuple. If the tuple's size is 1 returns an empty tuple, otherwise works exactly the same as BOOST_PP_TUPLE_POP_FRONT]
  209. [boost/vmd/tuple/pop_front.hpp]
  210. ]
  211. [
  212. [BOOST_VMD_TUPLE_PUSH_BACK]
  213. [tuple = a VMD tuple, elem = element to push onto the end of the VMD tuple]
  214. [A Boost PP tuple]
  215. [Pushes an element onto the end of a VMD tuple. If the VMD tuple is empty the returned tuple consists of that element, otherwise works exactly the same as BOOST_PP_TUPLE_PUSH_BACK]
  216. [boost/vmd/tuple/push_back.hpp]
  217. ]
  218. [
  219. [BOOST_VMD_TUPLE_PUSH_FRONT]
  220. [tuple = a VMD tuple, elem = element to push onto the beginning of the VMD tuple]
  221. [A Boost PP tuple]
  222. [Pushes an element onto the beginning of a VMD tuple. If the VMD tuple is empty the returned tuple consists of that element, otherwise works exactly the same as BOOST_PP_TUPLE_PUSH_FRONT]
  223. [boost/vmd/tuple/push_front.hpp]
  224. ]
  225. [
  226. [BOOST_VMD_TUPLE_REMOVE]
  227. [tuple = a Boost PP tuple, i = index of element to remove]
  228. [A VMD tuple]
  229. [Removes an element from a Boost PP tuple. If the tuple has a single element and the index to be removed is 0 returns an empty tuple, otherwise works exactly the same as BOOST_PP_TUPLE_REMOVE]
  230. [boost/vmd/tuple/remove.hpp]
  231. ]
  232. [
  233. [BOOST_VMD_TUPLE_SIZE]
  234. [tuple = a VMD tuple]
  235. [The number of elements in the VMD tuple]
  236. [Returns the number of elements in the VMD tuple. If the tuple is empty returns 0, otherwise works exactly the same as BOOST_PP_TUPLE_SIZE]
  237. [boost/vmd/tuple/size.hpp]
  238. ]
  239. [
  240. [BOOST_VMD_TUPLE_TO_ARRAY]
  241. [tuple = a VMD tuple]
  242. [A Boost PP array]
  243. [Converts a VMD tuple to a Boost PP array. If the tuple is empty returns an empty array whose form is '(0,())', otherwise works exactly the same as BOOST_PP_TUPLE_TO_ARRAY]
  244. [boost/vmd/tuple/to_array.hpp]
  245. ]
  246. [
  247. [BOOST_VMD_TUPLE_TO_LIST]
  248. [tuple = a VMD tuple]
  249. [A Boost PP list]
  250. [Converts a VMD tuple to a Boost PP list. If the tuple is empty returns an empty list whose form is 'BOOST_PP_NIL', otherwise works exactly the same as BOOST_PP_TUPLE_TO_LIST]
  251. [boost/vmd/tuple/to_list.hpp]
  252. ]
  253. [
  254. [BOOST_VMD_TUPLE_TO_SEQ]
  255. [tuple = a VMD tuple]
  256. [A VMD seq]
  257. [Converts a VMD tuple to a VMD seq. If the tuple is empty returns an empty seq, otherwise works exactly the same as BOOST_PP_TUPLE_TO_SEQ]
  258. [boost/vmd/tuple/to_seq.hpp]
  259. ]
  260. ]
  261. The difference between the tuple macros and their equivalent ones in Boost PP is
  262. that working with a VMD tuple or returning a VMD tuple is valid with the tuple macros
  263. but with the Boost PP equivalent macros working with an empty tuple causes UB and
  264. returning an empty tuple can never occur.
  265. You can include the tuple macros either using their individual header files,
  266. the general 'boost/vmd/tuple.hpp' header file for all tuple macros, or the
  267. general header file 'boost/vmd/vmd.hpp' for all macros.
  268. [heading Seq and tuple functionality]
  269. The set of macros for seq and tuple functionality which work with VMD seqs and
  270. VMD tuples are largely only a subset of the seq and tuple functionality in Boost PP. This reflects
  271. the fact that a number of macros in Boost PP for working with a seq or tuple make no
  272. sense when extended to work with a possible empty seq or empty tuple. For instance
  273. BOOST_PP_SEQ_FIRST_N could not mean anything when passed an empty
  274. seq and BOOST_PP_TUPLE_REM_CTOR could not mean anything when passed an empty tuple.
  275. Likewise for other Boost PP seq and tuple macros which do not have a VMD equivalent.
  276. The set of functionality in VMD for working with a possibly empty seq or empty tuple makes
  277. it possible to add or remove elements in a seq or tuple which could start out or
  278. end up empty, take the seq or tuple size even when the seq or tuple is empty,
  279. convert between arrays, lists, seqs, or tuples which could start out or end up
  280. empty, and test for a VMD seq or a VMD tuple. This functionality should allow macro
  281. programmers the ability to work with empty seqs and tuples while still using other
  282. Boost PP seq and tuple functuionality to work with non-empty seqs and tuples. The
  283. easiest way to do this is to use the VMD seq and VMD tuple equivalent functions
  284. when choosing between VMD and Boost PP, and use the Boost PP seq and tuple
  285. functionality otherwise. Just remember that Boost PP seq and tuple functionality
  286. can never work with empty seqs or empty tuples.
  287. [endsect]