elem.hpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. // (C) Copyright Edward Diener 2011-2015
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_VMD_ELEM_HPP)
  6. #define BOOST_VMD_ELEM_HPP
  7. #include <boost/vmd/detail/setup.hpp>
  8. #if BOOST_PP_VARIADICS
  9. #include <boost/vmd/detail/modifiers.hpp>
  10. #include <boost/vmd/detail/sequence_elem.hpp>
  11. /*
  12. The succeeding comments in this file are in doxygen format.
  13. */
  14. /** \file
  15. */
  16. /** \def BOOST_VMD_ELEM(elem,...)
  17. \brief Accesses an element of a sequence.
  18. elem = A sequence element number. From 0 to sequence size - 1.
  19. ... = Variadic parameters.
  20. The first variadic parameter is required and is the sequence to access.
  21. Further variadic parameters are all optional.
  22. With no further variadic parameters the macro returns the particular element
  23. in the sequence. If the element number is outside the bounds of the sequence
  24. macro access fails and the macro turns emptiness.
  25. Optional parameters determine what it means that an element is successfully
  26. accessed as well as what data is returned by the macro.
  27. Filters: specifying a VMD type tells the macro to return the element only
  28. if it is of the VMD type specified, else macro access fails. If more than
  29. one VMD type is specified as an optional parameter the last one
  30. specified is the filter.
  31. Matching Identifiers: If the filter is specified as the identifier type, BOOST_VMD_TYPE_IDENTIFIER,
  32. optional parameters which are identifiers specify that the element accessed
  33. must match one of the identifiers else access fails. The identifiers may be specified multiple
  34. times as single optional parameters or once as a tuple of identifier
  35. parameters. If the identifiers are specified as single optional parameters
  36. they cannot be any of the specific BOOST_VMD_ optional parameters in order to be
  37. recognized as matching identifiers. Normally this should never be the case.
  38. The only situation where this could occur is if the VMD types, which are filters,
  39. are used as matching identifiers; in this case the matching identifiers need
  40. to be passed as a tuple of identifier parameters so they are not treated
  41. as filters.
  42. Filters and matching identifiers change what it means that an element is successfully
  43. accessed. They do not change what data is returned by the macro. The remaining optional
  44. parameters do not change what it means that an element is successfully accessed but they
  45. do change what data is returned by the macro.
  46. Splitting: Splitting allows the macro to return the rest of the sequence
  47. after the element accessed.
  48. If BOOST_VMD_RETURN_AFTER is specified the return is a tuple
  49. with the element accessed as the first tuple parameter and the rest of
  50. the sequence as the second tuple parameter. If element access fails
  51. both tuple parameters are empty.
  52. If BOOST_VMD_RETURN_ONLY_AFTER
  53. is specified the return is the rest of the sequence after the element accessed
  54. found. If the element access fails the return is emptiness.
  55. If BOOST_VMD_RETURN_NO_AFTER, the default, is specified no splitting
  56. occurs.
  57. If more than one of the splitting identifiers are specified
  58. the last one specified determines the splitting.
  59. Return Type: The element accessed can be changed to return both the type
  60. of the element as well as the element data with optional return type
  61. parameters. When a type is returned, the element accessed which is returned becomes a
  62. two-element tuple where the type of the element accessed is the first tuple element and the element
  63. data itself is the second tuple element. If the macro fails to access the
  64. element the element access returned is emptiness and not a tuple.
  65. If BOOST_VMD_RETURN_NO_TYPE, the default, is specified no type is returned
  66. as part of the element accessed.
  67. If BOOST_VMD_RETURN_TYPE is specified the specific type of the element
  68. is returned in the tuple.
  69. If BOOST_VMD_RETURN_TYPE_ARRAY is specified
  70. an array type is returned if the element is an array, else a tuple
  71. type is returned if the element is a tuple, else the actual type
  72. is returned for non-tuple data.
  73. If BOOST_VMD_RETURN_TYPE_LIST is specified
  74. a list type is returned if the element is a list, else a tuple
  75. type is returned if the element is a tuple, else the actual type
  76. is returned for non-tuple data.
  77. If BOOST_VMD_RETURN_TYPE_TUPLE is specified
  78. a tuple type is returned for all tuple-like data, else the actual type
  79. is returned for non-tuple data.
  80. If more than one return type optional
  81. parameter is specified the last one specified determines the return type.
  82. If a filter is specified optional return type parameters are ignored and
  83. the default BOOST_VMD_RETURN_NO_TYPE is in effect.
  84. Index: If the filter is specified as the identifier type, BOOST_VMD_TYPE_IDENTIFIER,
  85. and matching identifiers are specified, an index parameter specifies that the
  86. numeric index, starting with 0, of the matching identifier found, be returned
  87. as part of the result.
  88. If BOOST_VMD_RETURN_INDEX is specified an index is returned
  89. as part of the result.
  90. If BOOST_VMD_RETURN_NO_INDEX, the default, is specified
  91. no index is returned as part of the result.
  92. If both are specified the last one specified determines the index parameter.
  93. When an index is returned as part of the result, the result is a tuple where the
  94. element accessed is the first tuple parameter and the index is the last tuple parameter.
  95. If element access fails the index is empty. If there is no BOOST_VMD_TYPE_IDENTIFIER
  96. filter or if there are no matching identifiers the BOOST_VMD_RETURN_INDEX is ignored
  97. and no index is returned as part of the result.
  98. returns = With no optional parameters the element accessed is returned, or emptiness if
  99. element is outside the bounds of the sequence. Filters and matching identifiers
  100. can change the meaning of whether the element accessed is returned or failure
  101. occurs, but whenever failure occurs emptiness is returned as the element access part
  102. of that failure, else the element accessed is returned. Return type optional parameters,
  103. when filters are not used, return the element accessed as a two-element tuple
  104. where the first tuple element is the type and the second tuple element is the
  105. data; if the element is not accessed then emptiness is returned as the element access
  106. and not a tuple. Splitting with BOOST_VMD_RETURN_AFTER returns a tuple where the element accessed
  107. is the first tuple element and the rest of the sequence is the second tuple element.
  108. Splitting with BOOST_VMD_RETURN_ONLY_AFTER returns the rest of the sequence after
  109. the element accessed or emptiness if the element can not be accessed. Indexing
  110. returns the index as part of the output only if filtering with
  111. BOOST_VMD_TYPE_IDENTIFIER is specified and matching identifiers are specified.
  112. When the index is returned with BOOST_VMD_RETURN_AFTER it is the third element
  113. of the tuple returned, else it is the second element of a tuple where the element
  114. accessed is the first element of the tuple.
  115. */
  116. #define BOOST_VMD_ELEM(elem,...) \
  117. BOOST_VMD_DETAIL_SEQUENCE_ELEM(BOOST_VMD_ALLOW_ALL,elem,__VA_ARGS__) \
  118. /**/
  119. /** \def BOOST_VMD_ELEM_D(d,elem,...)
  120. \brief Accesses an element of a sequence. Re-entrant version.
  121. d = The next available BOOST_PP_WHILE iteration.
  122. elem = A sequence element number. From 0 to sequence size - 1.
  123. ... = Variadic parameters.
  124. The first variadic parameter is required and is the sequence to access.
  125. Further variadic parameters are all optional.
  126. With no further variadic parameters the macro returns the particular element
  127. in the sequence. If the element number is outside the bounds of the sequence
  128. macro access fails and the macro turns emptiness.
  129. Optional parameters determine what it means that an element is successfully
  130. accessed as well as what data is returned by the macro.
  131. Filters: specifying a VMD type tells the macro to return the element only
  132. if it is of the VMD type specified, else macro access fails. If more than
  133. one VMD type is specified as an optional parameter the last one
  134. specified is the filter.
  135. Matching Identifiers: If the filter is specified as the identifier type, BOOST_VMD_TYPE_IDENTIFIER,
  136. optional parameters which are identifiers specify that the element accessed
  137. must match one of the identifiers else access fails. The identifiers may be specified multiple
  138. times as single optional parameters or once as a tuple of identifier
  139. parameters. If the identifiers are specified as single optional parameters
  140. they cannot be any of the specific BOOST_VMD_ optional parameters in order to be
  141. recognized as matching identifiers. Normally this should never be the case.
  142. The only situation where this could occur is if the VMD types, which are filters,
  143. are used as matching identifiers; in this case the matching identifiers need
  144. to be passed as a tuple of identifier parameters so they are not treated
  145. as filters.
  146. Filters and matching identifiers change what it means that an element is successfully
  147. accessed. They do not change what data is returned by the macro. The remaining optional
  148. parameters do not change what it means that an element is successfully accessed but they
  149. do change what data is returned by the macro.
  150. Splitting: Splitting allows the macro to return the rest of the sequence
  151. after the element accessed.
  152. If BOOST_VMD_RETURN_AFTER is specified the return is a tuple
  153. with the element accessed as the first tuple parameter and the rest of
  154. the sequence as the second tuple parameter. If element access fails
  155. both tuple parameters are empty.
  156. If BOOST_VMD_RETURN_ONLY_AFTER
  157. is specified the return is the rest of the sequence after the element accessed
  158. found. If the element access fails the return is emptiness.
  159. If BOOST_VMD_RETURN_NO_AFTER, the default, is specified no splitting
  160. occurs.
  161. If more than one of the splitting identifiers are specified
  162. the last one specified determines the splitting.
  163. Return Type: The element accessed can be changed to return both the type
  164. of the element as well as the element data with optional return type
  165. parameters. When a type is returned, the element accessed which is returned becomes a
  166. two-element tuple where the type of the element accessed is the first tuple element and the element
  167. data itself is the second tuple element. If the macro fails to access the
  168. element the element access returned is emptiness and not a tuple.
  169. If BOOST_VMD_RETURN_NO_TYPE, the default, is specified no type is returned
  170. as part of the element accessed.
  171. If BOOST_VMD_RETURN_TYPE is specified the specific type of the element
  172. is returned in the tuple.
  173. If BOOST_VMD_RETURN_TYPE_ARRAY is specified
  174. an array type is returned if the element is an array, else a tuple
  175. type is returned if the element is a tuple, else the actual type
  176. is returned for non-tuple data.
  177. If BOOST_VMD_RETURN_TYPE_LIST is specified
  178. a list type is returned if the element is a list, else a tuple
  179. type is returned if the element is a tuple, else the actual type
  180. is returned for non-tuple data.
  181. If BOOST_VMD_RETURN_TYPE_TUPLE is specified
  182. a tuple type is returned for all tuple-like data, else the actual type
  183. is returned for non-tuple data. If more than one return type optional
  184. parameter is specified the last one specified determines the return type.
  185. If a filter is specified optional return type parameters are ignored and
  186. the default BOOST_VMD_RETURN_NO_TYPE is in effect.
  187. Index: If the filter is specified as the identifier type, BOOST_VMD_TYPE_IDENTIFIER,
  188. and matching identifiers are specified, an index parameter specifies that the
  189. numeric index, starting with 0, of the matching identifier found, be returned
  190. as part of the result.
  191. If BOOST_VMD_RETURN_INDEX is specified an index is returned
  192. as part of the result.
  193. If BOOST_VMD_RETURN_NO_INDEX, the default, is specified
  194. no index is returned as part of the result.
  195. If both are specified the last one specified determines the index parameter.
  196. When an index is returned as part of the result, the result is a tuple where the
  197. element accessed is the first tuple parameter and the index is the last tuple parameter.
  198. If element access fails the index is empty. If there is no BOOST_VMD_TYPE_IDENTIFIER
  199. filter or if there are no matching identifiers the BOOST_VMD_RETURN_INDEX is ignored
  200. and no index is returned as part of the result.
  201. returns = With no optional parameters the element accessed is returned, or emptiness if
  202. element is outside the bounds of the sequence. Filters and matching identifiers
  203. can change the meaning of whether the element accessed is returned or failure
  204. occurs, but whenever failure occurs emptiness is returned as the element access part
  205. of that failure, else the element accessed is returned. Return type optional parameters,
  206. when filters are not used, return the element accessed as a two-element tuple
  207. where the first tuple element is the type and the second tuple element is the
  208. data; if the element is not accessed then emptiness is returned as the element access
  209. and not a tuple. Splitting with BOOST_VMD_RETURN_AFTER returns a tuple where the element accessed
  210. is the first tuple element and the rest of the sequence is the second tuple element.
  211. Splitting with BOOST_VMD_RETURN_ONLY_AFTER returns the rest of the sequence after
  212. the element accessed or emptiness if the element can not be accessed. Indexing
  213. returns the index as part of the output only if filtering with
  214. BOOST_VMD_TYPE_IDENTIFIER is specified and matching identifiers are specified.
  215. When the index is returned with BOOST_VMD_RETURN_AFTER it is the third element
  216. of the tuple returned, else it is the second element of a tuple where the element
  217. accessed is the first element of the tuple.
  218. */
  219. #define BOOST_VMD_ELEM_D(d,elem,...) \
  220. BOOST_VMD_DETAIL_SEQUENCE_ELEM_D(d,BOOST_VMD_ALLOW_ALL,elem,__VA_ARGS__) \
  221. /**/
  222. #endif /* BOOST_PP_VARIADICS */
  223. #endif /* BOOST_VMD_ELEM_HPP */