identifier.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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_DETAIL_IDENTIFIER_HPP)
  6. #define BOOST_VMD_DETAIL_IDENTIFIER_HPP
  7. #include <boost/preprocessor/arithmetic/dec.hpp>
  8. #include <boost/preprocessor/comparison/equal.hpp>
  9. #include <boost/preprocessor/control/expr_iif.hpp>
  10. #include <boost/preprocessor/control/iif.hpp>
  11. #include <boost/preprocessor/logical/bitand.hpp>
  12. #include <boost/preprocessor/logical/bitor.hpp>
  13. #include <boost/preprocessor/punctuation/is_begin_parens.hpp>
  14. #include <boost/preprocessor/tuple/elem.hpp>
  15. #include <boost/preprocessor/variadic/elem.hpp>
  16. #include <boost/vmd/identity.hpp>
  17. #include <boost/vmd/is_empty.hpp>
  18. #include <boost/vmd/detail/identifier_concat.hpp>
  19. #include <boost/vmd/detail/is_entire.hpp>
  20. #include <boost/vmd/detail/match_identifier.hpp>
  21. #include <boost/vmd/detail/mods.hpp>
  22. #include <boost/vmd/detail/not_empty.hpp>
  23. #include <boost/vmd/detail/parens.hpp>
  24. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_SUCCESS(id,rest,keymatch,mods) \
  25. BOOST_VMD_DETAIL_IDENTIFIER_SUCCESS_MODS(id,rest,BOOST_PP_DEC(keymatch),mods) \
  26. /**/
  27. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_FAILURE(id,rest,keymatch,mods) \
  28. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_MODS(mods) \
  29. /**/
  30. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_TUPLE_RESULT(id,rest,keymatch,mods) \
  31. BOOST_PP_IIF \
  32. ( \
  33. BOOST_PP_EQUAL(keymatch,0), \
  34. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_FAILURE, \
  35. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_SUCCESS \
  36. ) \
  37. (id,rest,keymatch,mods) \
  38. /**/
  39. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_TUPLE_RESULT_D(d,id,rest,keymatch,mods) \
  40. BOOST_PP_IIF \
  41. ( \
  42. BOOST_PP_EQUAL_D(d,keymatch,0), \
  43. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_FAILURE, \
  44. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_SUCCESS \
  45. ) \
  46. (id,rest,keymatch,mods) \
  47. /**/
  48. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_TUPLE(id,rest,keytuple,mods) \
  49. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_TUPLE_RESULT \
  50. ( \
  51. id, \
  52. rest, \
  53. BOOST_VMD_DETAIL_MATCH_IDENTIFIER(id,keytuple), \
  54. mods \
  55. ) \
  56. /**/
  57. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_TUPLE_D(d,id,rest,keytuple,mods) \
  58. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_TUPLE_RESULT_D \
  59. ( \
  60. d, \
  61. id, \
  62. rest, \
  63. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_D(d,id,keytuple), \
  64. mods \
  65. ) \
  66. /**/
  67. #define BOOST_VMD_DETAIL_IDENTIFIER_MAKE_SPLIT(tuple) \
  68. ( \
  69. BOOST_PP_TUPLE_ELEM \
  70. ( \
  71. 0, \
  72. BOOST_PP_TUPLE_ELEM(0,tuple) \
  73. ), \
  74. BOOST_PP_TUPLE_ELEM(1,tuple) \
  75. ) \
  76. /**/
  77. #define BOOST_VMD_DETAIL_IDENTIFIER_SPLIT_SEQUENCE_CONCAT_DATA(tuple) \
  78. BOOST_VMD_IDENTITY_RESULT \
  79. ( \
  80. BOOST_PP_IIF \
  81. ( \
  82. BOOST_VMD_IS_EMPTY \
  83. ( \
  84. BOOST_PP_TUPLE_ELEM(0,tuple) \
  85. ), \
  86. BOOST_VMD_IDENTITY(tuple), \
  87. BOOST_VMD_DETAIL_IDENTIFIER_MAKE_SPLIT \
  88. ) \
  89. (tuple) \
  90. ) \
  91. /**/
  92. #define BOOST_VMD_DETAIL_IDENTIFIER_SPLIT_SEQUENCE_CONCAT(vcseq) \
  93. BOOST_VMD_DETAIL_IDENTIFIER_SPLIT_SEQUENCE_CONCAT_DATA \
  94. ( \
  95. BOOST_VMD_DETAIL_PARENS(vcseq,BOOST_VMD_RETURN_AFTER) \
  96. ) \
  97. /**/
  98. #define BOOST_VMD_DETAIL_IDENTIFIER_GETID_TID(tid) \
  99. BOOST_VMD_IDENTITY_RESULT \
  100. ( \
  101. BOOST_PP_IIF \
  102. ( \
  103. BOOST_VMD_IS_EMPTY(tid), \
  104. BOOST_VMD_IDENTITY(tid), \
  105. BOOST_PP_TUPLE_ELEM \
  106. ) \
  107. (0,tid) \
  108. ) \
  109. /**/
  110. #define BOOST_VMD_DETAIL_IDENTIFIER_GETID_SEQUENCE(vseq) \
  111. BOOST_VMD_DETAIL_IDENTIFIER_GETID_TID \
  112. ( \
  113. BOOST_VMD_DETAIL_PARENS(BOOST_VMD_DETAIL_IDENTIFIER_CONCATENATE(vseq)) \
  114. ) \
  115. /**/
  116. #define BOOST_VMD_DETAIL_IDENTIFIER_SPLIT_SEQUENCE(vseq) \
  117. BOOST_VMD_DETAIL_IDENTIFIER_SPLIT_SEQUENCE_CONCAT \
  118. ( \
  119. BOOST_VMD_DETAIL_IDENTIFIER_CONCATENATE(vseq) \
  120. ) \
  121. /**/
  122. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS(id,rest,mods) \
  123. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_TUPLE \
  124. ( \
  125. id, \
  126. rest, \
  127. BOOST_VMD_DETAIL_MODS_RESULT_OTHER(mods), \
  128. mods \
  129. ) \
  130. /**/
  131. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_D(d,id,rest,mods) \
  132. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_TUPLE_D \
  133. ( \
  134. d, \
  135. id, \
  136. rest, \
  137. BOOST_VMD_DETAIL_MODS_RESULT_OTHER(mods), \
  138. mods \
  139. ) \
  140. /**/
  141. #define BOOST_VMD_DETAIL_IDENTIFIER_JUST(id,rest,mods) \
  142. BOOST_VMD_DETAIL_IDENTIFIER_SUCCESS_MODS(id,rest,0,mods) \
  143. /**/
  144. #define BOOST_VMD_DETAIL_IDENTIFIER_JUST_D(d,id,rest,mods) \
  145. BOOST_VMD_DETAIL_IDENTIFIER_SUCCESS_MODS(id,rest,0,mods) \
  146. /**/
  147. #define BOOST_VMD_DETAIL_IDENTIFIER_CHECK_KEYS(id,rest,mods) \
  148. BOOST_PP_IIF \
  149. ( \
  150. BOOST_VMD_IS_EMPTY \
  151. ( \
  152. BOOST_VMD_DETAIL_MODS_RESULT_OTHER(mods) \
  153. ), \
  154. BOOST_VMD_DETAIL_IDENTIFIER_JUST, \
  155. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS \
  156. ) \
  157. (id,rest,mods) \
  158. /**/
  159. #define BOOST_VMD_DETAIL_IDENTIFIER_CHECK_KEYS_D(d,id,rest,mods) \
  160. BOOST_PP_IIF \
  161. ( \
  162. BOOST_VMD_IS_EMPTY \
  163. ( \
  164. BOOST_VMD_DETAIL_MODS_RESULT_OTHER(mods) \
  165. ), \
  166. BOOST_VMD_DETAIL_IDENTIFIER_JUST_D, \
  167. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_KEYS_D \
  168. ) \
  169. (d,id,rest,mods) \
  170. /**/
  171. #define BOOST_VMD_DETAIL_IDENTIFIER_MKEYS(mods) \
  172. BOOST_PP_BITAND \
  173. ( \
  174. BOOST_VMD_DETAIL_MODS_IS_RESULT_INDEX(mods), \
  175. BOOST_VMD_DETAIL_NOT_EMPTY \
  176. ( \
  177. BOOST_VMD_DETAIL_MODS_RESULT_OTHER(mods) \
  178. ) \
  179. ) \
  180. /**/
  181. #define BOOST_VMD_DETAIL_IDENTIFIER_SUCCESS_MODS(id,rest,keymatch,mods) \
  182. BOOST_PP_IIF \
  183. ( \
  184. BOOST_VMD_DETAIL_IDENTIFIER_MKEYS(mods), \
  185. BOOST_PP_IIF \
  186. ( \
  187. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER(mods), \
  188. (id,rest,keymatch), \
  189. (id,keymatch) \
  190. ), \
  191. BOOST_PP_IIF \
  192. ( \
  193. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER(mods), \
  194. (id,rest), \
  195. id \
  196. ) \
  197. ) \
  198. /**/
  199. #define BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_MODS(mods) \
  200. BOOST_PP_IIF \
  201. ( \
  202. BOOST_VMD_DETAIL_IDENTIFIER_MKEYS(mods), \
  203. BOOST_PP_IIF \
  204. ( \
  205. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER(mods), \
  206. (,,), \
  207. (,) \
  208. ), \
  209. BOOST_PP_EXPR_IIF \
  210. ( \
  211. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER(mods), \
  212. (,) \
  213. ) \
  214. ) \
  215. /**/
  216. #define BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_REST(id,rest,mods) \
  217. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_MODS(mods) \
  218. /**/
  219. #define BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_REST_D(d,id,rest,mods) \
  220. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_MODS(mods) \
  221. /**/
  222. #define BOOST_VMD_DETAIL_IDENTIFIER_ID_REST(id,rest,mods) \
  223. BOOST_PP_IIF \
  224. ( \
  225. BOOST_VMD_IS_EMPTY(id), \
  226. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_REST, \
  227. BOOST_VMD_DETAIL_IDENTIFIER_CHECK_KEYS \
  228. ) \
  229. (id,rest,mods) \
  230. /**/
  231. #define BOOST_VMD_DETAIL_IDENTIFIER_ID_REST_D(d,id,rest,mods) \
  232. BOOST_PP_IIF \
  233. ( \
  234. BOOST_VMD_IS_EMPTY(id), \
  235. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_REST_D, \
  236. BOOST_VMD_DETAIL_IDENTIFIER_CHECK_KEYS_D \
  237. ) \
  238. (d,id,rest,mods) \
  239. /**/
  240. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_DATA(tuple,mods) \
  241. BOOST_VMD_DETAIL_IDENTIFIER_ID_REST \
  242. ( \
  243. BOOST_PP_TUPLE_ELEM(0,tuple), \
  244. BOOST_PP_TUPLE_ELEM(1,tuple), \
  245. mods \
  246. ) \
  247. /**/
  248. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_ID(id,mods) \
  249. BOOST_PP_IIF \
  250. ( \
  251. BOOST_VMD_IS_EMPTY(id), \
  252. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_REST, \
  253. BOOST_VMD_DETAIL_IDENTIFIER_CHECK_KEYS \
  254. ) \
  255. (id,,mods) \
  256. /**/
  257. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_ID_D(d,id,mods) \
  258. BOOST_PP_IIF \
  259. ( \
  260. BOOST_VMD_IS_EMPTY(id), \
  261. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_REST_D, \
  262. BOOST_VMD_DETAIL_IDENTIFIER_CHECK_KEYS_D \
  263. ) \
  264. (d,id,,mods) \
  265. /**/
  266. #define BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_DATA_D(d,tuple,mods) \
  267. BOOST_VMD_DETAIL_IDENTIFIER_ID_REST_D \
  268. ( \
  269. d, \
  270. BOOST_PP_TUPLE_ELEM(0,tuple), \
  271. BOOST_PP_TUPLE_ELEM(1,tuple), \
  272. mods \
  273. ) \
  274. /**/
  275. #define BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_AFTER(vseq,mods) \
  276. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_DATA \
  277. ( \
  278. BOOST_VMD_DETAIL_IDENTIFIER_SPLIT_SEQUENCE(vseq), \
  279. mods \
  280. ) \
  281. /**/
  282. #define BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_AFTER_D(d,vseq,mods) \
  283. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_DATA_D \
  284. ( \
  285. d, \
  286. BOOST_VMD_DETAIL_IDENTIFIER_SPLIT_SEQUENCE(vseq), \
  287. mods \
  288. ) \
  289. /**/
  290. #define BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_ID(vseq,mods) \
  291. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_ID \
  292. ( \
  293. BOOST_VMD_DETAIL_IDENTIFIER_GETID_SEQUENCE(vseq), \
  294. mods \
  295. ) \
  296. /**/
  297. #define BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_ID_D(d,vseq,mods) \
  298. BOOST_VMD_DETAIL_IDENTIFIER_PROCESS_ID_D \
  299. ( \
  300. d, \
  301. BOOST_VMD_DETAIL_IDENTIFIER_GETID_SEQUENCE(vseq), \
  302. mods \
  303. ) \
  304. /**/
  305. #define BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE(vseq,mods) \
  306. BOOST_PP_IIF \
  307. ( \
  308. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER(mods), \
  309. BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_AFTER, \
  310. BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_ID \
  311. ) \
  312. (vseq,mods) \
  313. /**/
  314. #define BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_D(d,vseq,mods) \
  315. BOOST_PP_IIF \
  316. ( \
  317. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER(mods), \
  318. BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_AFTER_D, \
  319. BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_ID_D \
  320. ) \
  321. (d,vseq,mods) \
  322. /**/
  323. #define BOOST_VMD_DETAIL_IDENTIFIER_EX_FAILURE(vseq,mods) \
  324. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_MODS(mods) \
  325. /**/
  326. #define BOOST_VMD_DETAIL_IDENTIFIER_EX_FAILURE_D(d,vseq,mods) \
  327. BOOST_VMD_DETAIL_IDENTIFIER_FAILURE_MODS(mods) \
  328. /**/
  329. #define BOOST_VMD_DETAIL_IDENTIFIER_EX(vseq,mods) \
  330. BOOST_PP_IIF \
  331. ( \
  332. BOOST_PP_BITOR \
  333. ( \
  334. BOOST_VMD_IS_EMPTY(vseq), \
  335. BOOST_PP_IS_BEGIN_PARENS(vseq) \
  336. ), \
  337. BOOST_VMD_DETAIL_IDENTIFIER_EX_FAILURE, \
  338. BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE \
  339. ) \
  340. (vseq,mods) \
  341. /**/
  342. #define BOOST_VMD_DETAIL_IDENTIFIER_EX_D(d,vseq,mods) \
  343. BOOST_PP_IIF \
  344. ( \
  345. BOOST_PP_BITOR \
  346. ( \
  347. BOOST_VMD_IS_EMPTY(vseq), \
  348. BOOST_PP_IS_BEGIN_PARENS(vseq) \
  349. ), \
  350. BOOST_VMD_DETAIL_IDENTIFIER_EX_FAILURE_D, \
  351. BOOST_VMD_DETAIL_IDENTIFIER_SEQUENCE_D \
  352. ) \
  353. (d,vseq,mods) \
  354. /**/
  355. #define BOOST_VMD_DETAIL_IDENTIFIER(...) \
  356. BOOST_VMD_DETAIL_IDENTIFIER_EX \
  357. ( \
  358. BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__), \
  359. BOOST_VMD_DETAIL_NEW_MODS(BOOST_VMD_ALLOW_INDEX,__VA_ARGS__) \
  360. ) \
  361. /**/
  362. #define BOOST_VMD_DETAIL_IDENTIFIER_D(d,...) \
  363. BOOST_VMD_DETAIL_IDENTIFIER_EX_D \
  364. ( \
  365. d, \
  366. BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__), \
  367. BOOST_VMD_DETAIL_NEW_MODS_D(d,BOOST_VMD_ALLOW_INDEX,__VA_ARGS__) \
  368. ) \
  369. /**/
  370. #define BOOST_VMD_DETAIL_IS_IDENTIFIER_MULTIPLE(...) \
  371. BOOST_VMD_DETAIL_IS_ENTIRE \
  372. ( \
  373. BOOST_VMD_DETAIL_IDENTIFIER(__VA_ARGS__,BOOST_VMD_RETURN_AFTER) \
  374. ) \
  375. /**/
  376. #define BOOST_VMD_DETAIL_IS_IDENTIFIER_MULTIPLE_D(d,...) \
  377. BOOST_VMD_DETAIL_IS_ENTIRE \
  378. ( \
  379. BOOST_VMD_DETAIL_IDENTIFIER_D(d,__VA_ARGS__,BOOST_VMD_RETURN_AFTER) \
  380. ) \
  381. /**/
  382. #endif /* BOOST_VMD_DETAIL_IDENTIFIER_HPP */