1 // Boost.Geometry Index
3 // Copyright (c) 2011-2016 Adam Wulkiewicz, Lodz, Poland.
5 // This file was modified by Oracle on 2019-2020.
6 // Modifications copyright (c) 2019-2020 Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
14 #define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
16 #include <boost/geometry/algorithms/detail/equals/interface.hpp>
17 #include <boost/geometry/index/indexable.hpp>
19 namespace boost { namespace geometry { namespace index { namespace detail
22 template <typename Geometry,
23 typename Tag = typename geometry::tag<Geometry>::type>
26 template <typename Strategy>
27 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const&)
29 return geometry::equals(g1, g2);
33 template <typename Geometry>
34 struct equals<Geometry, point_tag>
36 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
38 return geometry::equals(g1, g2);
41 template <typename Strategy>
42 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
44 return geometry::equals(g1, g2, s);
48 template <typename Geometry>
49 struct equals<Geometry, box_tag>
51 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
53 return geometry::equals(g1, g2);
56 template <typename Strategy>
57 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
59 return geometry::equals(g1, g2, s);
63 template <typename Geometry>
64 struct equals<Geometry, segment_tag>
66 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
68 return geometry::equals(g1, g2);
71 template <typename Strategy>
72 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
74 return geometry::equals(g1, g2, s);
79 template <typename Geometry, typename Tag>
80 struct equals<Geometry *, Tag>
82 template <typename Strategy>
83 inline static bool apply(const Geometry * g1, const Geometry * g2, Strategy const&)
90 struct equals<T, void>
92 template <typename Strategy>
93 inline static bool apply(T const& v1, T const& v2, Strategy const&)
100 struct equals<T *, void>
102 template <typename Strategy>
103 inline static bool apply(const T * v1, const T * v2, Strategy const&)
109 template <typename Tuple, size_t I, size_t N>
112 template <typename Strategy>
113 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
115 typedef typename boost::tuples::element<I, Tuple>::type T;
117 return equals<T>::apply(boost::get<I>(t1), boost::get<I>(t2), strategy)
118 && tuple_equals<Tuple, I + 1, N>::apply(t1, t2, strategy);
122 template <typename Tuple, size_t I>
123 struct tuple_equals<Tuple, I, I>
125 template <typename Strategy>
126 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
132 // TODO: Consider this: Since equal_to<> is using geometry::equals() it's possible that
133 // two compared Indexables are not exactly the same! They will be spatially equal
134 // but not strictly equal. Consider 2 Segments with reversed order of points.
135 // Therefore it's possible that during the Value removal different value will be
136 // removed than the one that was passed.
139 \brief The function object comparing Values.
141 It compares Geometries using geometry::equals() function. Other types are compared using operator==.
142 The default version handles Values which are Indexables.
143 This template is also specialized for std::pair<T1, T2> and boost::tuple<...>.
145 \tparam Value The type of objects which are compared by this function object.
146 \tparam IsIndexable If true, Values are compared using boost::geometry::equals() functions.
148 template <typename Value,
149 bool IsIndexable = is_indexable<Value>::value>
152 /*! \brief The type of result returned by function object. */
153 typedef bool result_type;
156 \brief Compare values. If Value is a Geometry geometry::equals() function is used.
158 \param l First value.
159 \param r Second value.
160 \return true if values are equal.
162 template <typename Strategy>
163 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
165 return detail::equals<Value>::apply(l, r, strategy);
170 \brief The function object comparing Values.
172 This specialization compares values of type std::pair<T1, T2>.
173 It compares pairs' first values, then second values.
175 \tparam T1 The first type.
176 \tparam T2 The second type.
178 template <typename T1, typename T2>
179 struct equal_to<std::pair<T1, T2>, false>
181 /*! \brief The type of result returned by function object. */
182 typedef bool result_type;
185 \brief Compare values. If pair<> Value member is a Geometry geometry::equals() function is used.
187 \param l First value.
188 \param r Second value.
189 \return true if values are equal.
191 template <typename Strategy>
192 inline bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r,
193 Strategy const& strategy) const
195 return detail::equals<T1>::apply(l.first, r.first, strategy)
196 && detail::equals<T2>::apply(l.second, r.second, strategy);
201 \brief The function object comparing Values.
203 This specialization compares values of type boost::tuple<...>.
204 It compares all members of the tuple from the first one to the last one.
206 template <typename T0, typename T1, typename T2, typename T3, typename T4,
207 typename T5, typename T6, typename T7, typename T8, typename T9>
208 struct equal_to<boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
210 typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
212 /*! \brief The type of result returned by function object. */
213 typedef bool result_type;
216 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
218 \param l First value.
219 \param r Second value.
220 \return true if values are equal.
222 template <typename Strategy>
223 inline bool operator()(value_type const& l, value_type const& r,
224 Strategy const& strategy) const
226 return detail::tuple_equals<
227 value_type, 0, boost::tuples::length<value_type>::value
228 >::apply(l, r, strategy);
232 }}}} // namespace boost::geometry::index::detail
234 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
238 namespace boost { namespace geometry { namespace index { namespace detail {
240 template <typename Tuple, size_t I, size_t N>
241 struct std_tuple_equals
243 template <typename Strategy>
244 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
246 typedef typename std::tuple_element<I, Tuple>::type T;
248 return equals<T>::apply(std::get<I>(t1), std::get<I>(t2), strategy)
249 && std_tuple_equals<Tuple, I + 1, N>::apply(t1, t2, strategy);
253 template <typename Tuple, size_t I>
254 struct std_tuple_equals<Tuple, I, I>
256 template <typename Strategy>
257 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
264 \brief The function object comparing Values.
266 This specialization compares values of type std::tuple<Args...>.
267 It's defined if the compiler supports tuples and variadic templates.
268 It compares all members of the tuple from the first one to the last one.
270 template <typename ...Args>
271 struct equal_to<std::tuple<Args...>, false>
273 typedef std::tuple<Args...> value_type;
275 /*! \brief The type of result returned by function object. */
276 typedef bool result_type;
279 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
281 \param l First value.
282 \param r Second value.
283 \return true if values are equal.
285 template <typename Strategy>
286 bool operator()(value_type const& l, value_type const& r, Strategy const& strategy) const
288 return detail::std_tuple_equals<
289 value_type, 0, std::tuple_size<value_type>::value
290 >::apply(l, r, strategy);
294 }}}} // namespace boost::geometry::index::detail
296 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
298 namespace boost { namespace geometry { namespace index {
301 \brief The function object comparing Values.
303 The default version handles Values which are Indexables, std::pair<T1, T2>, boost::tuple<...>
304 and std::tuple<...> if STD tuples and variadic templates are supported.
305 All members are compared from left to right, Geometries using boost::geometry::equals() function,
306 other types using operator==.
308 \tparam Value The type of objects which are compared by this function object.
310 template <typename Value>
312 : detail::equal_to<Value>
314 /*! \brief The type of result returned by function object. */
315 typedef typename detail::equal_to<Value>::result_type result_type;
318 \brief Compare Values.
320 \param l First value.
321 \param r Second value.
322 \return true if Values are equal.
324 inline bool operator()(Value const& l, Value const& r) const
326 return detail::equal_to<Value>::operator()(l, r, default_strategy());
329 template <typename Strategy>
330 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
332 return detail::equal_to<Value>::operator()(l, r, strategy);
336 }}} // namespace boost::geometry::index
338 #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP