]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/index/equal_to.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / geometry / index / equal_to.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry Index
2//
b32b8144 3// Copyright (c) 2011-2016 Adam Wulkiewicz, Lodz, Poland.
7c673cae 4//
1e59de90
TL
5// This file was modified by Oracle on 2019-2020.
6// Modifications copyright (c) 2019-2020 Oracle and/or its affiliates.
92f5a8d4
TL
7// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8//
7c673cae
FG
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
b32b8144 16#include <boost/geometry/algorithms/detail/equals/interface.hpp>
7c673cae
FG
17#include <boost/geometry/index/indexable.hpp>
18
92f5a8d4
TL
19namespace boost { namespace geometry { namespace index { namespace detail
20{
7c673cae
FG
21
22template <typename Geometry,
23 typename Tag = typename geometry::tag<Geometry>::type>
24struct equals
25{
92f5a8d4
TL
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
33template <typename Geometry>
34struct equals<Geometry, point_tag>
35{
36 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
7c673cae
FG
37 {
38 return geometry::equals(g1, g2);
39 }
92f5a8d4
TL
40
41 template <typename Strategy>
1e59de90 42 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
92f5a8d4 43 {
1e59de90 44 return geometry::equals(g1, g2, s);
92f5a8d4 45 }
7c673cae
FG
46};
47
92f5a8d4
TL
48template <typename Geometry>
49struct 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>
1e59de90 57 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
92f5a8d4 58 {
1e59de90 59 return geometry::equals(g1, g2, s);
92f5a8d4
TL
60 }
61};
62
63template <typename Geometry>
64struct 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 {
1e59de90 74 return geometry::equals(g1, g2, s);
92f5a8d4
TL
75 }
76};
77
78
7c673cae
FG
79template <typename Geometry, typename Tag>
80struct equals<Geometry *, Tag>
81{
92f5a8d4
TL
82 template <typename Strategy>
83 inline static bool apply(const Geometry * g1, const Geometry * g2, Strategy const&)
7c673cae
FG
84 {
85 return g1 == g2;
86 }
87};
88
89template <typename T>
90struct equals<T, void>
91{
92f5a8d4
TL
92 template <typename Strategy>
93 inline static bool apply(T const& v1, T const& v2, Strategy const&)
7c673cae
FG
94 {
95 return v1 == v2;
96 }
97};
98
b32b8144
FG
99template <typename T>
100struct equals<T *, void>
101{
92f5a8d4
TL
102 template <typename Strategy>
103 inline static bool apply(const T * v1, const T * v2, Strategy const&)
b32b8144
FG
104 {
105 return v1 == v2;
106 }
107};
108
7c673cae
FG
109template <typename Tuple, size_t I, size_t N>
110struct tuple_equals
111{
92f5a8d4
TL
112 template <typename Strategy>
113 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
7c673cae
FG
114 {
115 typedef typename boost::tuples::element<I, Tuple>::type T;
116
92f5a8d4
TL
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);
7c673cae
FG
119 }
120};
121
122template <typename Tuple, size_t I>
123struct tuple_equals<Tuple, I, I>
124{
92f5a8d4
TL
125 template <typename Strategy>
126 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
7c673cae
FG
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
141It compares Geometries using geometry::equals() function. Other types are compared using operator==.
142The default version handles Values which are Indexables.
143This 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*/
148template <typename Value,
149 bool IsIndexable = is_indexable<Value>::value>
150struct 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 */
92f5a8d4
TL
162 template <typename Strategy>
163 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
7c673cae 164 {
92f5a8d4 165 return detail::equals<Value>::apply(l, r, strategy);
7c673cae
FG
166 }
167};
168
169/*!
170\brief The function object comparing Values.
171
172This specialization compares values of type std::pair<T1, T2>.
173It compares pairs' first values, then second values.
174
175\tparam T1 The first type.
176\tparam T2 The second type.
177*/
178template <typename T1, typename T2>
179struct 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 */
92f5a8d4
TL
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
7c673cae 194 {
92f5a8d4
TL
195 return detail::equals<T1>::apply(l.first, r.first, strategy)
196 && detail::equals<T2>::apply(l.second, r.second, strategy);
7c673cae
FG
197 }
198};
199
200/*!
201\brief The function object comparing Values.
202
203This specialization compares values of type boost::tuple<...>.
204It compares all members of the tuple from the first one to the last one.
205*/
206template <typename T0, typename T1, typename T2, typename T3, typename T4,
207 typename T5, typename T6, typename T7, typename T8, typename T9>
208struct 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 */
92f5a8d4
TL
222 template <typename Strategy>
223 inline bool operator()(value_type const& l, value_type const& r,
224 Strategy const& strategy) const
7c673cae
FG
225 {
226 return detail::tuple_equals<
227 value_type, 0, boost::tuples::length<value_type>::value
92f5a8d4 228 >::apply(l, r, strategy);
7c673cae
FG
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
238namespace boost { namespace geometry { namespace index { namespace detail {
239
240template <typename Tuple, size_t I, size_t N>
241struct std_tuple_equals
242{
92f5a8d4
TL
243 template <typename Strategy>
244 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
7c673cae
FG
245 {
246 typedef typename std::tuple_element<I, Tuple>::type T;
247
92f5a8d4
TL
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);
7c673cae
FG
250 }
251};
252
253template <typename Tuple, size_t I>
254struct std_tuple_equals<Tuple, I, I>
255{
92f5a8d4
TL
256 template <typename Strategy>
257 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
7c673cae
FG
258 {
259 return true;
260 }
261};
262
263/*!
264\brief The function object comparing Values.
265
266This specialization compares values of type std::tuple<Args...>.
267It's defined if the compiler supports tuples and variadic templates.
268It compares all members of the tuple from the first one to the last one.
269*/
270template <typename ...Args>
271struct 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 */
92f5a8d4
TL
285 template <typename Strategy>
286 bool operator()(value_type const& l, value_type const& r, Strategy const& strategy) const
7c673cae
FG
287 {
288 return detail::std_tuple_equals<
289 value_type, 0, std::tuple_size<value_type>::value
92f5a8d4 290 >::apply(l, r, strategy);
7c673cae
FG
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
298namespace boost { namespace geometry { namespace index {
299
300/*!
301\brief The function object comparing Values.
302
303The default version handles Values which are Indexables, std::pair<T1, T2>, boost::tuple<...>
304and std::tuple<...> if STD tuples and variadic templates are supported.
305All members are compared from left to right, Geometries using boost::geometry::equals() function,
306other types using operator==.
307
308\tparam Value The type of objects which are compared by this function object.
309*/
310template <typename Value>
311struct 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 {
92f5a8d4
TL
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);
7c673cae
FG
333 }
334};
335
336}}} // namespace boost::geometry::index
337
338#endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP