data_equal_common.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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_DATA_EQUAL_COMMON_HPP)
  6. #define BOOST_VMD_DETAIL_DATA_EQUAL_COMMON_HPP
  7. #include <boost/preprocessor/arithmetic/inc.hpp>
  8. #include <boost/preprocessor/array/elem.hpp>
  9. #include <boost/preprocessor/array/size.hpp>
  10. #include <boost/preprocessor/comparison/equal.hpp>
  11. #include <boost/preprocessor/control/iif.hpp>
  12. #include <boost/preprocessor/list/at.hpp>
  13. #include <boost/preprocessor/list/size.hpp>
  14. #include <boost/preprocessor/logical/bitand.hpp>
  15. #include <boost/preprocessor/logical/bitor.hpp>
  16. #include <boost/preprocessor/logical/compl.hpp>
  17. #include <boost/preprocessor/punctuation/is_begin_parens.hpp>
  18. #include <boost/preprocessor/seq/elem.hpp>
  19. #include <boost/preprocessor/seq/size.hpp>
  20. #include <boost/preprocessor/tuple/elem.hpp>
  21. #include <boost/preprocessor/tuple/pop_front.hpp>
  22. #include <boost/preprocessor/tuple/push_back.hpp>
  23. #include <boost/preprocessor/tuple/replace.hpp>
  24. #include <boost/preprocessor/tuple/size.hpp>
  25. #include <boost/vmd/empty.hpp>
  26. #include <boost/vmd/is_empty.hpp>
  27. #include <boost/vmd/get_type.hpp>
  28. #include <boost/vmd/detail/equal_type.hpp>
  29. #define BOOST_VMD_DETAIL_DATA_EQUAL_IS_BOTH_COMPOSITE(vseq1,vseq2) \
  30. BOOST_PP_BITAND \
  31. ( \
  32. BOOST_PP_IS_BEGIN_PARENS(vseq1), \
  33. BOOST_PP_IS_BEGIN_PARENS(vseq2) \
  34. ) \
  35. /**/
  36. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM_ARRAY(d,index,data) \
  37. BOOST_PP_ARRAY_ELEM(index,data) \
  38. /**/
  39. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM_LIST(d,index,data) \
  40. BOOST_PP_LIST_AT_D(d,data,index) \
  41. /**/
  42. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM_SEQ(d,index,data) \
  43. BOOST_PP_SEQ_ELEM(index,data) \
  44. /**/
  45. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM_TUPLE(d,index,data) \
  46. BOOST_PP_TUPLE_ELEM(index,data) \
  47. /**/
  48. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_ARRAY(data) \
  49. BOOST_PP_ARRAY_SIZE(data) \
  50. /**/
  51. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_LIST(data) \
  52. BOOST_PP_LIST_SIZE(data) \
  53. /**/
  54. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_SEQ(data) \
  55. BOOST_PP_SEQ_SIZE(data) \
  56. /**/
  57. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_TUPLE(data) \
  58. BOOST_PP_TUPLE_SIZE(data) \
  59. /**/
  60. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_ARRAY_D(d,data) \
  61. BOOST_PP_ARRAY_SIZE(data) \
  62. /**/
  63. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_LIST_D(d,data) \
  64. BOOST_PP_LIST_SIZE_D(d,data) \
  65. /**/
  66. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_SEQ_D(d,data) \
  67. BOOST_PP_SEQ_SIZE(data) \
  68. /**/
  69. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_TUPLE_D(d,data) \
  70. BOOST_PP_TUPLE_SIZE(data) \
  71. /**/
  72. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM(d,index,data,vtype) \
  73. BOOST_PP_IIF \
  74. ( \
  75. BOOST_VMD_DETAIL_EQUAL_TYPE_D(d,vtype,BOOST_VMD_TYPE_ARRAY), \
  76. BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM_ARRAY, \
  77. BOOST_PP_IIF \
  78. ( \
  79. BOOST_VMD_DETAIL_EQUAL_TYPE_D(d,vtype,BOOST_VMD_TYPE_LIST), \
  80. BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM_LIST, \
  81. BOOST_PP_IIF \
  82. ( \
  83. BOOST_VMD_DETAIL_EQUAL_TYPE_D(d,vtype,BOOST_VMD_TYPE_SEQ), \
  84. BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM_SEQ, \
  85. BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM_TUPLE \
  86. ) \
  87. ) \
  88. ) \
  89. (d,index,data) \
  90. /**/
  91. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE(data,vtype) \
  92. BOOST_PP_IIF \
  93. ( \
  94. BOOST_VMD_DETAIL_EQUAL_TYPE(vtype,BOOST_VMD_TYPE_ARRAY), \
  95. BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_ARRAY, \
  96. BOOST_PP_IIF \
  97. ( \
  98. BOOST_VMD_DETAIL_EQUAL_TYPE(vtype,BOOST_VMD_TYPE_LIST), \
  99. BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_LIST, \
  100. BOOST_PP_IIF \
  101. ( \
  102. BOOST_VMD_DETAIL_EQUAL_TYPE(vtype,BOOST_VMD_TYPE_SEQ), \
  103. BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_SEQ, \
  104. BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_TUPLE \
  105. ) \
  106. ) \
  107. ) \
  108. (data) \
  109. /**/
  110. #define BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_D(d,data,vtype) \
  111. BOOST_PP_IIF \
  112. ( \
  113. BOOST_VMD_DETAIL_EQUAL_TYPE_D(d,vtype,BOOST_VMD_TYPE_ARRAY), \
  114. BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_ARRAY_D, \
  115. BOOST_PP_IIF \
  116. ( \
  117. BOOST_VMD_DETAIL_EQUAL_TYPE_D(d,vtype,BOOST_VMD_TYPE_LIST), \
  118. BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_LIST_D, \
  119. BOOST_PP_IIF \
  120. ( \
  121. BOOST_VMD_DETAIL_EQUAL_TYPE_D(d,vtype,BOOST_VMD_TYPE_SEQ), \
  122. BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_SEQ_D, \
  123. BOOST_VMD_DETAIL_DATA_EQUAL_GET_SIZE_TUPLE_D \
  124. ) \
  125. ) \
  126. ) \
  127. (d,data) \
  128. /**/
  129. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_RESULT(state) \
  130. BOOST_PP_TUPLE_ELEM(0,state) \
  131. /**/
  132. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_FIRST(state) \
  133. BOOST_PP_TUPLE_ELEM(1,state) \
  134. /**/
  135. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_SECOND(state) \
  136. BOOST_PP_TUPLE_ELEM(2,state) \
  137. /**/
  138. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_SIZE(state) \
  139. BOOST_PP_TUPLE_ELEM(3,state) \
  140. /**/
  141. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_TYPE(state) \
  142. BOOST_PP_TUPLE_ELEM(4,state) \
  143. /**/
  144. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_INDEX(state) \
  145. BOOST_PP_TUPLE_ELEM(5,state) \
  146. /**/
  147. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP(state) \
  148. BOOST_PP_TUPLE_ELEM(6,state) \
  149. /**/
  150. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PROCESSING(d,state) \
  151. BOOST_PP_BITAND \
  152. ( \
  153. BOOST_PP_EQUAL_D \
  154. ( \
  155. d, \
  156. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_INDEX(state), \
  157. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_SIZE(state) \
  158. ), \
  159. BOOST_PP_COMPL(BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_EMPTY(state)) \
  160. ) \
  161. /**/
  162. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_EMPTY(state) \
  163. BOOST_VMD_IS_EMPTY(BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP(state)) \
  164. /**/
  165. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_INDEX(state) \
  166. BOOST_PP_IIF \
  167. ( \
  168. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_EMPTY(state), \
  169. BOOST_VMD_EMPTY, \
  170. BOOST_PP_TUPLE_ELEM \
  171. ) \
  172. (0,BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP(state)) \
  173. /**/
  174. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_POP_NE_EMPTY(d,state) \
  175. BOOST_PP_TUPLE_REPLACE_D \
  176. ( \
  177. d, \
  178. state, \
  179. 6, \
  180. ) \
  181. /**/
  182. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_POP_NE_REMOVE(d,state) \
  183. BOOST_PP_TUPLE_REPLACE_D \
  184. ( \
  185. d, \
  186. state, \
  187. 6, \
  188. BOOST_PP_TUPLE_POP_FRONT(BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP(state)) \
  189. ) \
  190. /**/
  191. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_POP(d,state) \
  192. BOOST_PP_IIF \
  193. ( \
  194. BOOST_PP_EQUAL_D(d,BOOST_PP_TUPLE_SIZE(BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP(state)),1), \
  195. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_POP_NE_EMPTY, \
  196. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_POP_NE_REMOVE \
  197. ) \
  198. (d,state) \
  199. /**/
  200. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PUSH_CREATE(d,state) \
  201. BOOST_VMD_DETAIL_DATA_EQUAL_OP_SUCCESS \
  202. ( \
  203. d, \
  204. BOOST_PP_TUPLE_REPLACE_D \
  205. ( \
  206. d, \
  207. state, \
  208. 6, \
  209. (BOOST_VMD_DETAIL_DATA_EQUAL_STATE_INDEX(state)) \
  210. ) \
  211. ) \
  212. /**/
  213. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PUSH_ADD(d,state) \
  214. BOOST_VMD_DETAIL_DATA_EQUAL_OP_SUCCESS \
  215. ( \
  216. d, \
  217. BOOST_PP_TUPLE_REPLACE_D \
  218. ( \
  219. d, \
  220. state, \
  221. 6, \
  222. BOOST_PP_TUPLE_PUSH_BACK \
  223. ( \
  224. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP(state), \
  225. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_INDEX(state) \
  226. ) \
  227. ) \
  228. ) \
  229. /**/
  230. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PUSH(d,state) \
  231. BOOST_PP_IIF \
  232. ( \
  233. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_EMPTY(state), \
  234. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PUSH_CREATE, \
  235. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PUSH_ADD \
  236. ) \
  237. (d,state) \
  238. /**/
  239. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_GET_INDEX(d,state) \
  240. BOOST_PP_IIF \
  241. ( \
  242. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PROCESSING(d,state), \
  243. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_INDEX, \
  244. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_INDEX \
  245. ) \
  246. (state) \
  247. /**/
  248. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_GET_FIRST_ELEMENT(d,state) \
  249. BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM \
  250. ( \
  251. d, \
  252. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_GET_INDEX(d,state), \
  253. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_FIRST(state), \
  254. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_TYPE(state) \
  255. ) \
  256. /**/
  257. #define BOOST_VMD_DETAIL_DATA_EQUAL_STATE_GET_SECOND_ELEMENT(d,state) \
  258. BOOST_VMD_DETAIL_DATA_EQUAL_GET_ELEM \
  259. ( \
  260. d, \
  261. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_GET_INDEX(d,state), \
  262. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_SECOND(state), \
  263. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_TYPE(state) \
  264. ) \
  265. /**/
  266. #define BOOST_VMD_DETAIL_DATA_EQUAL_PRED(d,state) \
  267. BOOST_PP_BITAND \
  268. ( \
  269. BOOST_PP_EQUAL_D \
  270. ( \
  271. d, \
  272. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_RESULT(state), \
  273. 1 \
  274. ), \
  275. BOOST_PP_BITOR \
  276. ( \
  277. BOOST_PP_NOT_EQUAL_D \
  278. ( \
  279. d, \
  280. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_INDEX(state), \
  281. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_SIZE(state) \
  282. ), \
  283. BOOST_PP_COMPL \
  284. ( \
  285. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_EMPTY(state) \
  286. ) \
  287. ) \
  288. ) \
  289. /**/
  290. #define BOOST_VMD_DETAIL_DATA_EQUAL_OP_SUCCESS_NCP(d,state) \
  291. BOOST_PP_TUPLE_REPLACE_D \
  292. ( \
  293. d, \
  294. state, \
  295. 5, \
  296. BOOST_PP_INC(BOOST_VMD_DETAIL_DATA_EQUAL_STATE_INDEX(state)) \
  297. ) \
  298. /**/
  299. #define BOOST_VMD_DETAIL_DATA_EQUAL_OP_SUCCESS(d,state) \
  300. BOOST_PP_IIF \
  301. ( \
  302. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PROCESSING(d,state), \
  303. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_POP, \
  304. BOOST_VMD_DETAIL_DATA_EQUAL_OP_SUCCESS_NCP \
  305. ) \
  306. (d,state) \
  307. /**/
  308. #define BOOST_VMD_DETAIL_DATA_EQUAL_OP_FAILURE(d,state) \
  309. BOOST_PP_TUPLE_REPLACE_D \
  310. ( \
  311. d, \
  312. state, \
  313. 0, \
  314. 0 \
  315. ) \
  316. /**/
  317. #define BOOST_VMD_DETAIL_DATA_EQUAL_OP_RESULT(d,state,result) \
  318. BOOST_PP_IIF \
  319. ( \
  320. BOOST_PP_EQUAL_D(d,result,0), \
  321. BOOST_VMD_DETAIL_DATA_EQUAL_OP_FAILURE, \
  322. BOOST_PP_IIF \
  323. ( \
  324. BOOST_PP_EQUAL_D(d,result,1), \
  325. BOOST_VMD_DETAIL_DATA_EQUAL_OP_SUCCESS, \
  326. BOOST_VMD_DETAIL_DATA_EQUAL_STATE_COMP_PUSH \
  327. ) \
  328. ) \
  329. (d,state) \
  330. /**/
  331. #define BOOST_VMD_DETAIL_DATA_EQUAL_TYPE(emf,ems,vtype) \
  332. BOOST_PP_BITAND \
  333. ( \
  334. BOOST_VMD_DETAIL_EQUAL_TYPE \
  335. ( \
  336. BOOST_VMD_GET_TYPE(emf), \
  337. vtype \
  338. ), \
  339. BOOST_VMD_DETAIL_EQUAL_TYPE \
  340. ( \
  341. BOOST_VMD_GET_TYPE(ems), \
  342. vtype \
  343. ) \
  344. ) \
  345. /**/
  346. #define BOOST_VMD_DETAIL_DATA_EQUAL_TYPE_D(d,emf,ems,vtype) \
  347. BOOST_PP_BITAND \
  348. ( \
  349. BOOST_VMD_DETAIL_EQUAL_TYPE_D \
  350. ( \
  351. d, \
  352. BOOST_VMD_GET_TYPE(emf), \
  353. vtype \
  354. ), \
  355. BOOST_VMD_DETAIL_EQUAL_TYPE_D \
  356. ( \
  357. d, \
  358. BOOST_VMD_GET_TYPE(ems), \
  359. vtype \
  360. ) \
  361. ) \
  362. /**/
  363. #endif /* BOOST_VMD_DETAIL_DATA_EQUAL_COMMON_HPP */