]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/index/equal_to.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / index / equal_to.hpp
1 // Boost.Geometry Index
2 //
3 // Copyright (c) 2011-2016 Adam Wulkiewicz, Lodz, Poland.
4 //
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
8 //
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)
12
13 #ifndef BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
14 #define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
15
16 #include <boost/geometry/algorithms/detail/equals/interface.hpp>
17 #include <boost/geometry/index/indexable.hpp>
18
19 namespace boost { namespace geometry { namespace index { namespace detail
20 {
21
22 template <typename Geometry,
23 typename Tag = typename geometry::tag<Geometry>::type>
24 struct equals
25 {
26 template <typename Strategy>
27 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const&)
28 {
29 return geometry::equals(g1, g2);
30 }
31 };
32
33 template <typename Geometry>
34 struct equals<Geometry, point_tag>
35 {
36 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
37 {
38 return geometry::equals(g1, g2);
39 }
40
41 template <typename Strategy>
42 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
43 {
44 return geometry::equals(g1, g2, s);
45 }
46 };
47
48 template <typename Geometry>
49 struct equals<Geometry, box_tag>
50 {
51 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
52 {
53 return geometry::equals(g1, g2);
54 }
55
56 template <typename Strategy>
57 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
58 {
59 return geometry::equals(g1, g2, s);
60 }
61 };
62
63 template <typename Geometry>
64 struct equals<Geometry, segment_tag>
65 {
66 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
67 {
68 return geometry::equals(g1, g2);
69 }
70
71 template <typename Strategy>
72 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
73 {
74 return geometry::equals(g1, g2, s);
75 }
76 };
77
78
79 template <typename Geometry, typename Tag>
80 struct equals<Geometry *, Tag>
81 {
82 template <typename Strategy>
83 inline static bool apply(const Geometry * g1, const Geometry * g2, Strategy const&)
84 {
85 return g1 == g2;
86 }
87 };
88
89 template <typename T>
90 struct equals<T, void>
91 {
92 template <typename Strategy>
93 inline static bool apply(T const& v1, T const& v2, Strategy const&)
94 {
95 return v1 == v2;
96 }
97 };
98
99 template <typename T>
100 struct equals<T *, void>
101 {
102 template <typename Strategy>
103 inline static bool apply(const T * v1, const T * v2, Strategy const&)
104 {
105 return v1 == v2;
106 }
107 };
108
109 template <typename Tuple, size_t I, size_t N>
110 struct tuple_equals
111 {
112 template <typename Strategy>
113 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
114 {
115 typedef typename boost::tuples::element<I, Tuple>::type T;
116
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);
119 }
120 };
121
122 template <typename Tuple, size_t I>
123 struct tuple_equals<Tuple, I, I>
124 {
125 template <typename Strategy>
126 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
127 {
128 return true;
129 }
130 };
131
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.
137
138 /*!
139 \brief The function object comparing Values.
140
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<...>.
144
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.
147 */
148 template <typename Value,
149 bool IsIndexable = is_indexable<Value>::value>
150 struct equal_to
151 {
152 /*! \brief The type of result returned by function object. */
153 typedef bool result_type;
154
155 /*!
156 \brief Compare values. If Value is a Geometry geometry::equals() function is used.
157
158 \param l First value.
159 \param r Second value.
160 \return true if values are equal.
161 */
162 template <typename Strategy>
163 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
164 {
165 return detail::equals<Value>::apply(l, r, strategy);
166 }
167 };
168
169 /*!
170 \brief The function object comparing Values.
171
172 This specialization compares values of type std::pair<T1, T2>.
173 It compares pairs' first values, then second values.
174
175 \tparam T1 The first type.
176 \tparam T2 The second type.
177 */
178 template <typename T1, typename T2>
179 struct equal_to<std::pair<T1, T2>, false>
180 {
181 /*! \brief The type of result returned by function object. */
182 typedef bool result_type;
183
184 /*!
185 \brief Compare values. If pair<> Value member is a Geometry geometry::equals() function is used.
186
187 \param l First value.
188 \param r Second value.
189 \return true if values are equal.
190 */
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
194 {
195 return detail::equals<T1>::apply(l.first, r.first, strategy)
196 && detail::equals<T2>::apply(l.second, r.second, strategy);
197 }
198 };
199
200 /*!
201 \brief The function object comparing Values.
202
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.
205 */
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>
209 {
210 typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
211
212 /*! \brief The type of result returned by function object. */
213 typedef bool result_type;
214
215 /*!
216 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
217
218 \param l First value.
219 \param r Second value.
220 \return true if values are equal.
221 */
222 template <typename Strategy>
223 inline bool operator()(value_type const& l, value_type const& r,
224 Strategy const& strategy) const
225 {
226 return detail::tuple_equals<
227 value_type, 0, boost::tuples::length<value_type>::value
228 >::apply(l, r, strategy);
229 }
230 };
231
232 }}}} // namespace boost::geometry::index::detail
233
234 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
235
236 #include <tuple>
237
238 namespace boost { namespace geometry { namespace index { namespace detail {
239
240 template <typename Tuple, size_t I, size_t N>
241 struct std_tuple_equals
242 {
243 template <typename Strategy>
244 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
245 {
246 typedef typename std::tuple_element<I, Tuple>::type T;
247
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);
250 }
251 };
252
253 template <typename Tuple, size_t I>
254 struct std_tuple_equals<Tuple, I, I>
255 {
256 template <typename Strategy>
257 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
258 {
259 return true;
260 }
261 };
262
263 /*!
264 \brief The function object comparing Values.
265
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.
269 */
270 template <typename ...Args>
271 struct equal_to<std::tuple<Args...>, false>
272 {
273 typedef std::tuple<Args...> value_type;
274
275 /*! \brief The type of result returned by function object. */
276 typedef bool result_type;
277
278 /*!
279 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
280
281 \param l First value.
282 \param r Second value.
283 \return true if values are equal.
284 */
285 template <typename Strategy>
286 bool operator()(value_type const& l, value_type const& r, Strategy const& strategy) const
287 {
288 return detail::std_tuple_equals<
289 value_type, 0, std::tuple_size<value_type>::value
290 >::apply(l, r, strategy);
291 }
292 };
293
294 }}}} // namespace boost::geometry::index::detail
295
296 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
297
298 namespace boost { namespace geometry { namespace index {
299
300 /*!
301 \brief The function object comparing Values.
302
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==.
307
308 \tparam Value The type of objects which are compared by this function object.
309 */
310 template <typename Value>
311 struct equal_to
312 : detail::equal_to<Value>
313 {
314 /*! \brief The type of result returned by function object. */
315 typedef typename detail::equal_to<Value>::result_type result_type;
316
317 /*!
318 \brief Compare Values.
319
320 \param l First value.
321 \param r Second value.
322 \return true if Values are equal.
323 */
324 inline bool operator()(Value const& l, Value const& r) const
325 {
326 return detail::equal_to<Value>::operator()(l, r, default_strategy());
327 }
328
329 template <typename Strategy>
330 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
331 {
332 return detail::equal_to<Value>::operator()(l, r, strategy);
333 }
334 };
335
336 }}} // namespace boost::geometry::index
337
338 #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP