elem.hpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. <br/>
  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. @code
  47. Splitting: Splitting allows the macro to return the rest of the sequence
  48. after the element accessed.
  49. If BOOST_VMD_RETURN_AFTER is specified the return is a tuple
  50. with the element accessed as the first tuple parameter and the rest of
  51. the sequence as the second tuple parameter. If element access fails
  52. both tuple parameters are empty.
  53. If BOOST_VMD_RETURN_ONLY_AFTER
  54. is specified the return is the rest of the sequence after the element accessed
  55. found. If the element access fails the return is emptiness.
  56. If BOOST_VMD_RETURN_NO_AFTER, the default, is specified no splitting
  57. occurs.
  58. If more than one of the splitting identifiers are specified
  59. the last one specified determines the splitting.
  60. Return Type: The element accessed can be changed to return both the type
  61. of the element as well as the element data with optional return type
  62. parameters. When a type is returned, the element accessed which is returned becomes a
  63. two-element tuple where the type of the element accessed is the first tuple element and the element
  64. data itself is the second tuple element. If the macro fails to access the
  65. element the element access returned is emptiness and not a tuple.
  66. If BOOST_VMD_RETURN_NO_TYPE, the default, is specified no type is returned
  67. as part of the element accessed.
  68. If BOOST_VMD_RETURN_TYPE is specified the specific type of the element
  69. is returned in the tuple.
  70. If BOOST_VMD_RETURN_TYPE_ARRAY is specified
  71. an array type is returned if the element is an array, else a tuple
  72. type is returned if the element is a tuple, else the actual type
  73. is returned for non-tuple data.
  74. If BOOST_VMD_RETURN_TYPE_LIST is specified
  75. a list type is returned if the element is a list, else a tuple
  76. type is returned if the element is a tuple, else the actual type
  77. is returned for non-tuple data.
  78. If BOOST_VMD_RETURN_TYPE_TUPLE is specified
  79. a tuple type is returned for all tuple-like data, else the actual type
  80. is returned for non-tuple data.
  81. If more than one return type optional
  82. parameter is specified the last one specified determines the return type.
  83. If a filter is specified optional return type parameters are ignored and
  84. the default BOOST_VMD_RETURN_NO_TYPE is in effect.
  85. Index: If the filter is specified as the identifier type, BOOST_VMD_TYPE_IDENTIFIER,
  86. and matching identifiers are specified, an index parameter specifies that the
  87. numeric index, starting with 0, of the matching identifier found, be returned
  88. as part of the result.
  89. If BOOST_VMD_RETURN_INDEX is specified an index is returned
  90. as part of the result.
  91. If BOOST_VMD_RETURN_NO_INDEX, the default, is specified
  92. no index is returned as part of the result.
  93. If both are specified the last one specified determines the index parameter.
  94. When an index is returned as part of the result, the result is a tuple where the
  95. element accessed is the first tuple parameter and the index is the last tuple parameter.
  96. If element access fails the index is empty. If there is no BOOST_VMD_TYPE_IDENTIFIER
  97. filter or if there are no matching identifiers the BOOST_VMD_RETURN_INDEX is ignored
  98. and no index is returned as part of the result.
  99. @endcode
  100. returns = With no optional parameters the element accessed is returned, or emptiness if
  101. element is outside the bounds of the sequence. Filters and matching identifiers
  102. can change the meaning of whether the element accessed is returned or failure
  103. occurs, but whenever failure occurs emptiness is returned as the element access part
  104. of that failure, else the element accessed is returned. Return type optional parameters,
  105. when filters are not used, return the element accessed as a two-element tuple
  106. where the first tuple element is the type and the second tuple element is the
  107. data; if the element is not accessed then emptiness is returned as the element access
  108. and not a tuple. Splitting with BOOST_VMD_RETURN_AFTER returns a tuple where the element accessed
  109. is the first tuple element and the rest of the sequence is the second tuple element.
  110. Splitting with BOOST_VMD_RETURN_ONLY_AFTER returns the rest of the sequence after
  111. the element accessed or emptiness if the element can not be accessed. Indexing
  112. returns the index as part of the output only if filtering with
  113. BOOST_VMD_TYPE_IDENTIFIER is specified and matching identifiers are specified.
  114. When the index is returned with BOOST_VMD_RETURN_AFTER it is the third element
  115. of the tuple returned, else it is the second element of a tuple where the element
  116. accessed is the first element of the tuple.
  117. */
  118. #define BOOST_VMD_ELEM(elem,...) \
  119. BOOST_VMD_DETAIL_SEQUENCE_ELEM(BOOST_VMD_ALLOW_ALL,elem,__VA_ARGS__) \
  120. /**/
  121. /** \def BOOST_VMD_ELEM_D(d,elem,...)
  122. \brief Accesses an element of a sequence. Re-entrant version.
  123. d = The next available BOOST_PP_WHILE iteration. <br/>
  124. elem = A sequence element number. From 0 to sequence size - 1. <br/>
  125. ... = Variadic parameters.
  126. The first variadic parameter is required and is the sequence to access.
  127. Further variadic parameters are all optional.
  128. With no further variadic parameters the macro returns the particular element
  129. in the sequence. If the element number is outside the bounds of the sequence
  130. macro access fails and the macro turns emptiness.
  131. Optional parameters determine what it means that an element is successfully
  132. accessed as well as what data is returned by the macro.
  133. Filters: specifying a VMD type tells the macro to return the element only
  134. if it is of the VMD type specified, else macro access fails. If more than
  135. one VMD type is specified as an optional parameter the last one
  136. specified is the filter.
  137. Matching Identifiers: If the filter is specified as the identifier type, BOOST_VMD_TYPE_IDENTIFIER,
  138. optional parameters which are identifiers specify that the element accessed
  139. must match one of the identifiers else access fails. The identifiers may be specified multiple
  140. times as single optional parameters or once as a tuple of identifier
  141. parameters. If the identifiers are specified as single optional parameters
  142. they cannot be any of the specific BOOST_VMD_ optional parameters in order to be
  143. recognized as matching identifiers. Normally this should never be the case.
  144. The only situation where this could occur is if the VMD types, which are filters,
  145. are used as matching identifiers; in this case the matching identifiers need
  146. to be passed as a tuple of identifier parameters so they are not treated
  147. as filters.
  148. Filters and matching identifiers change what it means that an element is successfully
  149. accessed. They do not change what data is returned by the macro. The remaining optional
  150. parameters do not change what it means that an element is successfully accessed but they
  151. do change what data is returned by the macro.
  152. @code
  153. Splitting: Splitting allows the macro to return the rest of the sequence
  154. after the element accessed.
  155. If BOOST_VMD_RETURN_AFTER is specified the return is a tuple
  156. with the element accessed as the first tuple parameter and the rest of
  157. the sequence as the second tuple parameter. If element access fails
  158. both tuple parameters are empty.
  159. If BOOST_VMD_RETURN_ONLY_AFTER
  160. is specified the return is the rest of the sequence after the element accessed
  161. found. If the element access fails the return is emptiness.
  162. If BOOST_VMD_RETURN_NO_AFTER, the default, is specified no splitting
  163. occurs.
  164. If more than one of the splitting identifiers are specified
  165. the last one specified determines the splitting.
  166. Return Type: The element accessed can be changed to return both the type
  167. of the element as well as the element data with optional return type
  168. parameters. When a type is returned, the element accessed which is returned becomes a
  169. two-element tuple where the type of the element accessed is the first tuple element and the element
  170. data itself is the second tuple element. If the macro fails to access the
  171. element the element access returned is emptiness and not a tuple.
  172. If BOOST_VMD_RETURN_NO_TYPE, the default, is specified no type is returned
  173. as part of the element accessed.
  174. If BOOST_VMD_RETURN_TYPE is specified the specific type of the element
  175. is returned in the tuple.
  176. If BOOST_VMD_RETURN_TYPE_ARRAY is specified
  177. an array type is returned if the element is an array, else a tuple
  178. type is returned if the element is a tuple, else the actual type
  179. is returned for non-tuple data.
  180. If BOOST_VMD_RETURN_TYPE_LIST is specified
  181. a list type is returned if the element is a list, else a tuple
  182. type is returned if the element is a tuple, else the actual type
  183. is returned for non-tuple data.
  184. If BOOST_VMD_RETURN_TYPE_TUPLE is specified
  185. a tuple type is returned for all tuple-like data, else the actual type
  186. is returned for non-tuple data. If more than one return type optional
  187. parameter is specified the last one specified determines the return type.
  188. If a filter is specified optional return type parameters are ignored and
  189. the default BOOST_VMD_RETURN_NO_TYPE is in effect.
  190. Index: If the filter is specified as the identifier type, BOOST_VMD_TYPE_IDENTIFIER,
  191. and matching identifiers are specified, an index parameter specifies that the
  192. numeric index, starting with 0, of the matching identifier found, be returned
  193. as part of the result.
  194. If BOOST_VMD_RETURN_INDEX is specified an index is returned
  195. as part of the result.
  196. If BOOST_VMD_RETURN_NO_INDEX, the default, is specified
  197. no index is returned as part of the result.
  198. If both are specified the last one specified determines the index parameter.
  199. When an index is returned as part of the result, the result is a tuple where the
  200. element accessed is the first tuple parameter and the index is the last tuple parameter.
  201. If element access fails the index is empty. If there is no BOOST_VMD_TYPE_IDENTIFIER
  202. filter or if there are no matching identifiers the BOOST_VMD_RETURN_INDEX is ignored
  203. and no index is returned as part of the result.
  204. @endcode
  205. returns = With no optional parameters the element accessed is returned, or emptiness if
  206. element is outside the bounds of the sequence. Filters and matching identifiers
  207. can change the meaning of whether the element accessed is returned or failure
  208. occurs, but whenever failure occurs emptiness is returned as the element access part
  209. of that failure, else the element accessed is returned. Return type optional parameters,
  210. when filters are not used, return the element accessed as a two-element tuple
  211. where the first tuple element is the type and the second tuple element is the
  212. data; if the element is not accessed then emptiness is returned as the element access
  213. and not a tuple. Splitting with BOOST_VMD_RETURN_AFTER returns a tuple where the element accessed
  214. is the first tuple element and the rest of the sequence is the second tuple element.
  215. Splitting with BOOST_VMD_RETURN_ONLY_AFTER returns the rest of the sequence after
  216. the element accessed or emptiness if the element can not be accessed. Indexing
  217. returns the index as part of the output only if filtering with
  218. BOOST_VMD_TYPE_IDENTIFIER is specified and matching identifiers are specified.
  219. When the index is returned with BOOST_VMD_RETURN_AFTER it is the third element
  220. of the tuple returned, else it is the second element of a tuple where the element
  221. accessed is the first element of the tuple.
  222. */
  223. #define BOOST_VMD_ELEM_D(d,elem,...) \
  224. BOOST_VMD_DETAIL_SEQUENCE_ELEM_D(d,BOOST_VMD_ALLOW_ALL,elem,__VA_ARGS__) \
  225. /**/
  226. #endif /* BOOST_PP_VARIADICS */
  227. #endif /* BOOST_VMD_ELEM_HPP */