1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
10 #ifndef BOOST_GEOMETRY_STRATEGIES_COMPARABLE_DISTANCE_RESULT_HPP
11 #define BOOST_GEOMETRY_STRATEGIES_COMPARABLE_DISTANCE_RESULT_HPP
13 #include <boost/mpl/always.hpp>
14 #include <boost/mpl/bool.hpp>
15 #include <boost/mpl/vector.hpp>
17 #include <boost/variant/variant_fwd.hpp>
19 #include <boost/geometry/core/point_type.hpp>
21 #include <boost/geometry/strategies/default_strategy.hpp>
22 #include <boost/geometry/strategies/distance.hpp>
24 #include <boost/geometry/util/compress_variant.hpp>
25 #include <boost/geometry/util/transform_variant.hpp>
26 #include <boost/geometry/util/combine_if.hpp>
28 #include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
31 namespace boost { namespace geometry
34 namespace resolve_strategy
37 template <typename Geometry1, typename Geometry2, typename Strategy>
38 struct comparable_distance_result
39 : strategy::distance::services::return_type
41 typename strategy::distance::services::comparable_type
45 typename point_type<Geometry1>::type,
46 typename point_type<Geometry2>::type
50 template <typename Geometry1, typename Geometry2>
51 struct comparable_distance_result<Geometry1, Geometry2, default_strategy>
52 : comparable_distance_result
56 typename detail::distance::default_strategy
63 } // namespace resolve_strategy
66 namespace resolve_variant
69 template <typename Geometry1, typename Geometry2, typename Strategy>
70 struct comparable_distance_result
71 : resolve_strategy::comparable_distance_result
83 BOOST_VARIANT_ENUM_PARAMS(typename T),
86 struct comparable_distance_result
88 Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy
91 // A set of all variant type combinations that are compatible and
93 typedef typename util::combine_if<
94 typename boost::mpl::vector1<Geometry1>,
95 typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
96 boost::mpl::always<boost::mpl::true_>
97 >::type possible_input_types;
99 // The (possibly variant) result type resulting from these combinations
100 typedef typename compress_variant<
101 typename transform_variant<
102 possible_input_types,
103 resolve_strategy::comparable_distance_result<
104 boost::mpl::first<boost::mpl::_>,
105 boost::mpl::second<boost::mpl::_>,
108 boost::mpl::back_inserter<boost::mpl::vector0<> >
114 // Distance arguments are commutative
117 BOOST_VARIANT_ENUM_PARAMS(typename T),
121 struct comparable_distance_result
123 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
126 > : public comparable_distance_result
128 Geometry2, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Strategy
133 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Strategy>
134 struct comparable_distance_result
136 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
137 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
141 // A set of all variant type combinations that are compatible and
143 typedef typename util::combine_if
145 typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
146 typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
147 boost::mpl::always<boost::mpl::true_>
148 >::type possible_input_types;
150 // The (possibly variant) result type resulting from these combinations
151 typedef typename compress_variant<
152 typename transform_variant<
153 possible_input_types,
154 resolve_strategy::comparable_distance_result<
155 boost::mpl::first<boost::mpl::_>,
156 boost::mpl::second<boost::mpl::_>,
159 boost::mpl::back_inserter<boost::mpl::vector0<> >
164 } // namespace resolve_variant
171 \brief Meta-function defining return type of comparable_distance function
177 typename Geometry2 = Geometry1,
178 typename Strategy = void
180 struct comparable_distance_result
181 : resolve_variant::comparable_distance_result
183 Geometry1, Geometry2, Strategy
187 template <typename Geometry1, typename Geometry2>
188 struct comparable_distance_result<Geometry1, Geometry2, void>
189 : comparable_distance_result<Geometry1, Geometry2, default_strategy>
193 }} // namespace boost::geometry
196 #endif // BOOST_GEOMETRY_STRATEGIES_COMPARABLE_DISTANCE_RESULT_HPP