is_combinable.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2008-2009: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_IS_COMBINABLE_HPP_JOFA_090115
  9. #define BOOST_ICL_IS_COMBINABLE_HPP_JOFA_090115
  10. #include <boost/mpl/bool.hpp>
  11. #include <boost/mpl/if.hpp>
  12. #include <boost/mpl/and.hpp>
  13. #include <boost/mpl/or.hpp>
  14. #include <boost/mpl/not.hpp>
  15. #include <boost/type_traits/is_same.hpp>
  16. #include <boost/icl/type_traits/is_concept_equivalent.hpp>
  17. #include <boost/icl/type_traits/is_interval_container.hpp>
  18. namespace boost{namespace icl
  19. {
  20. template<class Type>
  21. struct is_overloadable
  22. {
  23. typedef is_overloadable<Type> type;
  24. BOOST_STATIC_CONSTANT(bool, value =
  25. (boost::is_same<Type, typename Type::overloadable_type>::value)
  26. );
  27. };
  28. //------------------------------------------------------------------------------
  29. template<class LeftT, class RightT>
  30. struct is_codomain_equal
  31. {
  32. typedef is_codomain_equal<LeftT, RightT> type;
  33. BOOST_STATIC_CONSTANT(bool, value =
  34. (boost::is_same<typename LeftT::codomain_type,
  35. typename RightT::codomain_type>::value)
  36. );
  37. };
  38. //NOTE: Equality of compare order implies the equality of the domain_types
  39. template<class LeftT, class RightT>
  40. struct is_key_compare_equal
  41. {
  42. typedef is_key_compare_equal<LeftT, RightT> type;
  43. BOOST_STATIC_CONSTANT(bool, value =
  44. (boost::is_same<typename LeftT::key_compare,
  45. typename RightT::key_compare>::value)
  46. );
  47. };
  48. template<class LeftT, class RightT>
  49. struct is_codomain_type_equal
  50. {
  51. typedef is_codomain_type_equal<LeftT, RightT> type;
  52. BOOST_STATIC_CONSTANT(bool, value =
  53. (mpl::and_<is_key_compare_equal<LeftT, RightT>,
  54. is_codomain_equal<LeftT, RightT> >::value)
  55. );
  56. };
  57. // For equal containers concepts, domain order and codomain type must match.
  58. template<template<class>class IsConcept, class LeftT, class RightT>
  59. struct is_concept_compatible
  60. {
  61. typedef is_concept_compatible<IsConcept, LeftT, RightT> type;
  62. BOOST_STATIC_CONSTANT(bool, value =
  63. (mpl::and_<
  64. IsConcept<LeftT>
  65. , IsConcept<RightT>
  66. , is_codomain_type_equal<LeftT, RightT>
  67. >::value)
  68. );
  69. };
  70. template<template<class>class LeftConcept,
  71. template<class>class RightConcept,
  72. class LeftT, class RightT>
  73. struct is_concept_combinable
  74. {
  75. typedef is_concept_combinable<LeftConcept, RightConcept, LeftT, RightT> type;
  76. BOOST_STATIC_CONSTANT(bool, value =
  77. (mpl::and_<
  78. LeftConcept<LeftT>
  79. , RightConcept<RightT>
  80. , is_key_compare_equal<LeftT, RightT>
  81. >::value)
  82. );
  83. };
  84. template<class LeftT, class RightT>
  85. struct is_intra_combinable
  86. {
  87. typedef is_intra_combinable<LeftT, RightT> type;
  88. BOOST_STATIC_CONSTANT(bool, value =
  89. (mpl::or_<
  90. is_concept_compatible<is_interval_set, LeftT, RightT>
  91. , is_concept_compatible<is_interval_map, LeftT, RightT>
  92. >::value)
  93. );
  94. };
  95. //------------------------------------------------------------------------------
  96. //------------------------------------------------------------------------------
  97. template<class LeftT, class RightT>
  98. struct is_cross_combinable
  99. {
  100. typedef is_cross_combinable<LeftT, RightT> type;
  101. BOOST_STATIC_CONSTANT(bool, value =
  102. (mpl::or_<
  103. is_concept_combinable<is_interval_set, is_interval_map, LeftT, RightT>
  104. , is_concept_combinable<is_interval_map, is_interval_set, LeftT, RightT>
  105. >::value)
  106. );
  107. };
  108. template<class LeftT, class RightT>
  109. struct is_inter_combinable
  110. {
  111. typedef is_inter_combinable<LeftT, RightT> type;
  112. BOOST_STATIC_CONSTANT(bool, value =
  113. (mpl::or_<is_intra_combinable<LeftT,RightT>,
  114. is_cross_combinable<LeftT,RightT> >::value)
  115. );
  116. };
  117. //------------------------------------------------------------------------------
  118. // is_fragment_of
  119. //------------------------------------------------------------------------------
  120. template<class FragmentT, class Type>
  121. struct is_fragment_of
  122. {
  123. typedef is_fragment_of type;
  124. BOOST_STATIC_CONSTANT(bool, value = false);
  125. };
  126. template<class Type>
  127. struct is_fragment_of<typename Type::element_type, Type>
  128. {
  129. typedef is_fragment_of type;
  130. BOOST_STATIC_CONSTANT(bool, value = true);
  131. };
  132. template<class Type>
  133. struct is_fragment_of<typename Type::segment_type, Type>
  134. {
  135. typedef is_fragment_of type;
  136. BOOST_STATIC_CONSTANT(bool, value = true);
  137. };
  138. //------------------------------------------------------------------------------
  139. // is_key_of
  140. //------------------------------------------------------------------------------
  141. template<class KeyT, class Type>
  142. struct is_key_of
  143. {
  144. typedef is_key_of type;
  145. BOOST_STATIC_CONSTANT(bool, value = false);
  146. };
  147. template<class Type>
  148. struct is_key_of<typename Type::domain_type, Type>
  149. {
  150. typedef is_key_of type;
  151. BOOST_STATIC_CONSTANT(bool, value = true);
  152. };
  153. template<class Type>
  154. struct is_key_of<typename Type::interval_type, Type>
  155. {
  156. typedef is_key_of type;
  157. BOOST_STATIC_CONSTANT(bool, value = true);
  158. };
  159. //------------------------------------------------------------------------------
  160. // is_interval_set_derivative
  161. //------------------------------------------------------------------------------
  162. template<class Type, class AssociateT>
  163. struct is_interval_set_derivative;
  164. template<class Type>
  165. struct is_interval_set_derivative<Type, typename Type::domain_type>
  166. {
  167. typedef is_interval_set_derivative type;
  168. BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
  169. };
  170. template<class Type>
  171. struct is_interval_set_derivative<Type, typename Type::interval_type>
  172. {
  173. typedef is_interval_set_derivative type;
  174. BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
  175. };
  176. template<class Type, class AssociateT>
  177. struct is_interval_set_derivative
  178. {
  179. typedef is_interval_set_derivative<Type, AssociateT> type;
  180. BOOST_STATIC_CONSTANT(bool, value = false);
  181. };
  182. //------------------------------------------------------------------------------
  183. // is_interval_map_derivative
  184. //------------------------------------------------------------------------------
  185. template<class Type, class AssociateT>
  186. struct is_interval_map_derivative;
  187. template<class Type>
  188. struct is_interval_map_derivative<Type, typename Type::domain_mapping_type>
  189. {
  190. typedef is_interval_map_derivative type;
  191. BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
  192. };
  193. template<class Type>
  194. struct is_interval_map_derivative<Type, typename Type::interval_mapping_type>
  195. {
  196. typedef is_interval_map_derivative type;
  197. BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
  198. };
  199. template<class Type>
  200. struct is_interval_map_derivative<Type, typename Type::value_type>
  201. {
  202. typedef is_interval_map_derivative type;
  203. BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
  204. };
  205. template<class Type, class AssociateT>
  206. struct is_interval_map_derivative
  207. {
  208. typedef is_interval_map_derivative<Type, AssociateT> type;
  209. BOOST_STATIC_CONSTANT(bool, value = false);
  210. };
  211. //------------------------------------------------------------------------------
  212. // is_intra_derivative
  213. //------------------------------------------------------------------------------
  214. template<class Type, class AssociateT>
  215. struct is_intra_derivative
  216. {
  217. typedef is_intra_derivative<Type, AssociateT> type;
  218. BOOST_STATIC_CONSTANT(bool, value =
  219. (mpl::or_
  220. <
  221. mpl::and_<is_interval_set<Type>,
  222. is_interval_set_derivative<Type, AssociateT> >
  223. , mpl::and_<is_interval_map<Type>,
  224. is_interval_map_derivative<Type, AssociateT> >
  225. >::value)
  226. );
  227. };
  228. template<class Type, class AssociateT>
  229. struct is_cross_derivative
  230. {
  231. typedef is_cross_derivative<Type, AssociateT> type;
  232. BOOST_STATIC_CONSTANT(bool, value =
  233. (mpl::and_<
  234. is_interval_map<Type>
  235. , is_interval_set_derivative<Type, AssociateT>
  236. >::value)
  237. );
  238. };
  239. template<class Type, class AssociateT>
  240. struct is_inter_derivative
  241. {
  242. typedef is_inter_derivative<Type, AssociateT> type;
  243. BOOST_STATIC_CONSTANT(bool, value =
  244. (mpl::or_<
  245. is_intra_derivative<Type, AssociateT>
  246. , is_cross_derivative<Type, AssociateT>
  247. >::value)
  248. );
  249. };
  250. //------------------------------------------------------------------------------
  251. //- right combinable
  252. //------------------------------------------------------------------------------
  253. template<class GuideT, class CompanionT>
  254. struct is_interval_set_right_combinable
  255. {
  256. typedef is_interval_set_right_combinable<GuideT, CompanionT> type;
  257. BOOST_STATIC_CONSTANT(bool, value =
  258. (mpl::and_
  259. <
  260. is_interval_set<GuideT>
  261. , mpl::or_
  262. <
  263. is_interval_set_derivative<GuideT, CompanionT>
  264. , is_concept_compatible<is_interval_set, GuideT, CompanionT>
  265. >
  266. >::value)
  267. );
  268. };
  269. template<class GuideT, class CompanionT>
  270. struct is_interval_map_right_intra_combinable //NOTE equivalent to is_fragment_type_of
  271. {
  272. typedef is_interval_map_right_intra_combinable<GuideT, CompanionT> type;
  273. BOOST_STATIC_CONSTANT(bool, value =
  274. (mpl::and_
  275. <
  276. is_interval_map<GuideT>
  277. , mpl::or_
  278. <
  279. is_interval_map_derivative<GuideT, CompanionT>
  280. , is_concept_compatible<is_interval_map, GuideT, CompanionT>
  281. >
  282. >::value)
  283. );
  284. };
  285. template<class GuideT, class CompanionT>
  286. struct is_interval_map_right_cross_combinable //NOTE equivalent to key_type_of<Comp, Guide>
  287. {
  288. typedef is_interval_map_right_cross_combinable<GuideT, CompanionT> type;
  289. BOOST_STATIC_CONSTANT(bool, value =
  290. (mpl::and_
  291. <
  292. is_interval_map<GuideT>
  293. , mpl::or_
  294. <
  295. is_cross_derivative<GuideT, CompanionT>
  296. , is_concept_combinable<is_interval_map, is_interval_set, GuideT, CompanionT>
  297. >
  298. >::value)
  299. );
  300. };
  301. template<class GuideT, class CompanionT>
  302. struct is_interval_map_right_inter_combinable
  303. {
  304. typedef is_interval_map_right_inter_combinable<GuideT, CompanionT> type;
  305. BOOST_STATIC_CONSTANT(bool, value =
  306. (mpl::or_<
  307. is_interval_map_right_intra_combinable<GuideT, CompanionT>
  308. , is_interval_map_right_cross_combinable<GuideT, CompanionT>
  309. >::value)
  310. );
  311. };
  312. template<class GuideT, class CompanionT>
  313. struct is_right_intra_combinable
  314. {
  315. typedef is_right_intra_combinable<GuideT, CompanionT> type;
  316. BOOST_STATIC_CONSTANT(bool, value =
  317. (mpl::or_
  318. <
  319. is_interval_set_right_combinable<GuideT, CompanionT>
  320. , is_interval_map_right_intra_combinable<GuideT, CompanionT>
  321. >::value)
  322. );
  323. };
  324. template<class GuideT, class CompanionT>
  325. struct is_right_inter_combinable
  326. {
  327. typedef is_right_inter_combinable<GuideT, CompanionT> type;
  328. BOOST_STATIC_CONSTANT(bool, value =
  329. (mpl::or_
  330. <
  331. is_interval_set_right_combinable<GuideT, CompanionT>
  332. , is_interval_map_right_inter_combinable<GuideT, CompanionT>
  333. >::value)
  334. );
  335. };
  336. template<class GuideT, class IntervalSetT>
  337. struct combines_right_to_interval_set
  338. {
  339. typedef combines_right_to_interval_set<GuideT, IntervalSetT> type;
  340. BOOST_STATIC_CONSTANT(bool, value =
  341. (is_concept_combinable<is_interval_container, is_interval_set,
  342. GuideT, IntervalSetT>::value)
  343. );
  344. };
  345. template<class GuideT, class IntervalMapT>
  346. struct combines_right_to_interval_map
  347. {
  348. typedef combines_right_to_interval_map<GuideT, IntervalMapT> type;
  349. BOOST_STATIC_CONSTANT(bool, value =
  350. (is_concept_compatible<is_interval_map, GuideT, IntervalMapT>::value) );
  351. };
  352. template<class GuideT, class IntervalContainerT>
  353. struct combines_right_to_interval_container
  354. {
  355. typedef combines_right_to_interval_container<GuideT, IntervalContainerT> type;
  356. BOOST_STATIC_CONSTANT(bool, value =
  357. (mpl::or_<combines_right_to_interval_set<GuideT, IntervalContainerT>,
  358. combines_right_to_interval_map<GuideT, IntervalContainerT> >::value)
  359. );
  360. };
  361. //------------------------------------------------------------------------------
  362. //- segmentational_fineness
  363. //------------------------------------------------------------------------------
  364. template<class Type> struct unknown_fineness
  365. {
  366. typedef unknown_fineness<Type> type;
  367. static const int value = 0;
  368. };
  369. template<class Type> struct known_fineness
  370. {
  371. typedef known_fineness<Type> type;
  372. static const int value = Type::fineness;
  373. };
  374. template<class Type>struct segmentational_fineness
  375. {
  376. typedef segmentational_fineness<Type> type;
  377. static const int value =
  378. mpl::if_<is_interval_container<Type>,
  379. known_fineness<Type>,
  380. unknown_fineness<Type>
  381. >::type::value;
  382. };
  383. //------------------------------------------------------------------------------
  384. // is_interval_set_companion
  385. //------------------------------------------------------------------------------
  386. // CompanionT is either an interval_set or a derivative of set level:
  387. // element_type=domain_type, segment_type=interval_type
  388. template<class GuideT, class CompanionT> struct is_interval_set_companion
  389. {
  390. typedef is_interval_set_companion<GuideT,CompanionT> type;
  391. BOOST_STATIC_CONSTANT(bool, value =
  392. (mpl::or_
  393. <
  394. combines_right_to_interval_set<GuideT,CompanionT>
  395. , is_interval_set_derivative<GuideT,CompanionT>
  396. >::value)
  397. );
  398. };
  399. //------------------------------------------------------------------------------
  400. // is_interval_map_companion
  401. //------------------------------------------------------------------------------
  402. template<class GuideT, class CompanionT> struct is_interval_map_companion
  403. {
  404. typedef is_interval_map_companion<GuideT,CompanionT> type;
  405. BOOST_STATIC_CONSTANT(bool, value =
  406. (mpl::or_
  407. <
  408. combines_right_to_interval_map<GuideT,CompanionT>
  409. , is_interval_map_derivative<GuideT,CompanionT>
  410. >::value)
  411. );
  412. };
  413. //------------------------------------------------------------------------------
  414. //- is_coarser_interval_{set,map}_companion
  415. //------------------------------------------------------------------------------
  416. template<class GuideT, class CompanionT>
  417. struct is_coarser_interval_set_companion
  418. {
  419. typedef is_coarser_interval_set_companion<GuideT, CompanionT> type;
  420. BOOST_STATIC_CONSTANT(bool, value =
  421. (mpl::and_
  422. <
  423. is_interval_set_companion<GuideT, CompanionT>
  424. , mpl::bool_<( segmentational_fineness<GuideT>::value
  425. > segmentational_fineness<CompanionT>::value)>
  426. >::value)
  427. );
  428. };
  429. template<class GuideT, class CompanionT>
  430. struct is_coarser_interval_map_companion
  431. {
  432. typedef is_coarser_interval_map_companion<GuideT, CompanionT> type;
  433. BOOST_STATIC_CONSTANT(bool, value =
  434. (mpl::and_
  435. <
  436. is_interval_map_companion<GuideT, CompanionT>
  437. , mpl::bool_<( segmentational_fineness<GuideT>::value
  438. > segmentational_fineness<CompanionT>::value)>
  439. >::value)
  440. );
  441. };
  442. //------------------------------------------------------------------------------
  443. // is_binary_interval_{set,map}_combinable
  444. //------------------------------------------------------------------------------
  445. template<class GuideT, class CompanionT>
  446. struct is_binary_interval_set_combinable
  447. {
  448. typedef is_binary_interval_set_combinable<GuideT,CompanionT> type;
  449. static const int value =
  450. mpl::and_< is_interval_set<GuideT>
  451. , is_coarser_interval_set_companion<GuideT, CompanionT>
  452. >::value;
  453. };
  454. template<class GuideT, class CompanionT>
  455. struct is_binary_interval_map_combinable
  456. {
  457. typedef is_binary_interval_map_combinable<GuideT,CompanionT> type;
  458. static const int value =
  459. mpl::and_< is_interval_map<GuideT>
  460. , is_coarser_interval_map_companion<GuideT, CompanionT>
  461. >::value;
  462. };
  463. template<class GuideT, class CompanionT>
  464. struct is_binary_intra_combinable
  465. {
  466. typedef is_binary_intra_combinable<GuideT,CompanionT> type;
  467. BOOST_STATIC_CONSTANT(bool, value =
  468. (mpl::or_<is_binary_interval_set_combinable<GuideT, CompanionT>,
  469. is_binary_interval_map_combinable<GuideT, CompanionT>
  470. >::value)
  471. );
  472. };
  473. template<class GuideT, class CompanionT>
  474. struct is_binary_cross_combinable
  475. {
  476. typedef is_binary_cross_combinable<GuideT,CompanionT> type;
  477. BOOST_STATIC_CONSTANT(bool, value =
  478. (mpl::and_
  479. < is_interval_map<GuideT>
  480. , mpl::or_< is_coarser_interval_map_companion<GuideT, CompanionT>
  481. , is_interval_set_companion<GuideT, CompanionT> >
  482. >::value)
  483. );
  484. };
  485. template<class GuideT, class CompanionT>
  486. struct is_binary_inter_combinable
  487. {
  488. typedef is_binary_inter_combinable<GuideT,CompanionT> type;
  489. BOOST_STATIC_CONSTANT(bool, value =
  490. (mpl::or_
  491. <
  492. mpl::and_<is_interval_map<GuideT>,
  493. is_binary_cross_combinable<GuideT, CompanionT> >
  494. , mpl::and_<is_interval_set<GuideT>,
  495. is_binary_intra_combinable<GuideT, CompanionT> >
  496. >::value)
  497. );
  498. };
  499. }} // namespace icl boost
  500. #endif