comparable_distance_result.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2015, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_STRATEGIES_COMPARABLE_DISTANCE_RESULT_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_COMPARABLE_DISTANCE_RESULT_HPP
  8. #include <boost/mpl/always.hpp>
  9. #include <boost/mpl/bool.hpp>
  10. #include <boost/mpl/vector.hpp>
  11. #include <boost/variant/variant_fwd.hpp>
  12. #include <boost/geometry/core/point_type.hpp>
  13. #include <boost/geometry/strategies/default_strategy.hpp>
  14. #include <boost/geometry/strategies/distance.hpp>
  15. #include <boost/geometry/util/compress_variant.hpp>
  16. #include <boost/geometry/util/transform_variant.hpp>
  17. #include <boost/geometry/util/combine_if.hpp>
  18. #include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. namespace resolve_strategy
  22. {
  23. template <typename Geometry1, typename Geometry2, typename Strategy>
  24. struct comparable_distance_result
  25. : strategy::distance::services::return_type
  26. <
  27. typename strategy::distance::services::comparable_type
  28. <
  29. Strategy
  30. >::type,
  31. typename point_type<Geometry1>::type,
  32. typename point_type<Geometry2>::type
  33. >
  34. {};
  35. template <typename Geometry1, typename Geometry2>
  36. struct comparable_distance_result<Geometry1, Geometry2, default_strategy>
  37. : comparable_distance_result
  38. <
  39. Geometry1,
  40. Geometry2,
  41. typename detail::distance::default_strategy
  42. <
  43. Geometry1, Geometry2
  44. >::type
  45. >
  46. {};
  47. } // namespace resolve_strategy
  48. namespace resolve_variant
  49. {
  50. template <typename Geometry1, typename Geometry2, typename Strategy>
  51. struct comparable_distance_result
  52. : resolve_strategy::comparable_distance_result
  53. <
  54. Geometry1,
  55. Geometry2,
  56. Strategy
  57. >
  58. {};
  59. template
  60. <
  61. typename Geometry1,
  62. BOOST_VARIANT_ENUM_PARAMS(typename T),
  63. typename Strategy
  64. >
  65. struct comparable_distance_result
  66. <
  67. Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy
  68. >
  69. {
  70. // A set of all variant type combinations that are compatible and
  71. // implemented
  72. typedef typename util::combine_if<
  73. typename boost::mpl::vector1<Geometry1>,
  74. typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
  75. boost::mpl::always<boost::mpl::true_>
  76. >::type possible_input_types;
  77. // The (possibly variant) result type resulting from these combinations
  78. typedef typename compress_variant<
  79. typename transform_variant<
  80. possible_input_types,
  81. resolve_strategy::comparable_distance_result<
  82. boost::mpl::first<boost::mpl::_>,
  83. boost::mpl::second<boost::mpl::_>,
  84. Strategy
  85. >,
  86. boost::mpl::back_inserter<boost::mpl::vector0<> >
  87. >::type
  88. >::type type;
  89. };
  90. // Distance arguments are commutative
  91. template
  92. <
  93. BOOST_VARIANT_ENUM_PARAMS(typename T),
  94. typename Geometry2,
  95. typename Strategy
  96. >
  97. struct comparable_distance_result
  98. <
  99. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
  100. Geometry2,
  101. Strategy
  102. > : public comparable_distance_result
  103. <
  104. Geometry2, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy
  105. >
  106. {};
  107. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Strategy>
  108. struct comparable_distance_result
  109. <
  110. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
  111. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
  112. Strategy
  113. >
  114. {
  115. // A set of all variant type combinations that are compatible and
  116. // implemented
  117. typedef typename util::combine_if
  118. <
  119. typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
  120. typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
  121. boost::mpl::always<boost::mpl::true_>
  122. >::type possible_input_types;
  123. // The (possibly variant) result type resulting from these combinations
  124. typedef typename compress_variant<
  125. typename transform_variant<
  126. possible_input_types,
  127. resolve_strategy::comparable_distance_result<
  128. boost::mpl::first<boost::mpl::_>,
  129. boost::mpl::second<boost::mpl::_>,
  130. Strategy
  131. >,
  132. boost::mpl::back_inserter<boost::mpl::vector0<> >
  133. >::type
  134. >::type type;
  135. };
  136. } // namespace resolve_variant
  137. /*!
  138. \brief Meta-function defining return type of comparable_distance function
  139. \ingroup distance
  140. */
  141. template
  142. <
  143. typename Geometry1,
  144. typename Geometry2 = Geometry1,
  145. typename Strategy = void
  146. >
  147. struct comparable_distance_result
  148. : resolve_variant::comparable_distance_result
  149. <
  150. Geometry1, Geometry2, Strategy
  151. >
  152. {};
  153. template <typename Geometry1, typename Geometry2>
  154. struct comparable_distance_result<Geometry1, Geometry2, void>
  155. : comparable_distance_result<Geometry1, Geometry2, default_strategy>
  156. {};
  157. }} // namespace boost::geometry
  158. #endif // BOOST_GEOMETRY_STRATEGIES_COMPARABLE_DISTANCE_RESULT_HPP