]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/index/equal_to.hpp
import new upstream nautilus stable release 14.2.8
[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//
92f5a8d4
TL
5// This file was modified by Oracle on 2019.
6// Modifications copyright (c) 2019 Oracle and/or its affiliates.
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>
42 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const&)
43 {
44 return geometry::equals(g1, g2, typename Strategy::within_point_point_strategy_type());
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>
57 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const&)
58 {
59 // NOTE: there is no strategy for equals(box, box) so pass dummy variable
60 // TODO: there should be a strategy even if it is the same for all CSes in case undefined_cs was used
61 return geometry::equals(g1, g2, 0);
62 }
63};
64
65template <typename Geometry>
66struct equals<Geometry, segment_tag>
67{
68 inline static bool apply(Geometry const& g1, Geometry const& g2, default_strategy const&)
69 {
70 return geometry::equals(g1, g2);
71 }
72
73 template <typename Strategy>
74 inline static bool apply(Geometry const& g1, Geometry const& g2, Strategy const& s)
75 {
76 return geometry::equals(g1, g2, s.get_relate_segment_segment_strategy());
77 }
78};
79
80
7c673cae
FG
81template <typename Geometry, typename Tag>
82struct equals<Geometry *, Tag>
83{
92f5a8d4
TL
84 template <typename Strategy>
85 inline static bool apply(const Geometry * g1, const Geometry * g2, Strategy const&)
7c673cae
FG
86 {
87 return g1 == g2;
88 }
89};
90
91template <typename T>
92struct equals<T, void>
93{
92f5a8d4
TL
94 template <typename Strategy>
95 inline static bool apply(T const& v1, T const& v2, Strategy const&)
7c673cae
FG
96 {
97 return v1 == v2;
98 }
99};
100
b32b8144
FG
101template <typename T>
102struct equals<T *, void>
103{
92f5a8d4
TL
104 template <typename Strategy>
105 inline static bool apply(const T * v1, const T * v2, Strategy const&)
b32b8144
FG
106 {
107 return v1 == v2;
108 }
109};
110
7c673cae
FG
111template <typename Tuple, size_t I, size_t N>
112struct tuple_equals
113{
92f5a8d4
TL
114 template <typename Strategy>
115 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
7c673cae
FG
116 {
117 typedef typename boost::tuples::element<I, Tuple>::type T;
118
92f5a8d4
TL
119 return equals<T>::apply(boost::get<I>(t1), boost::get<I>(t2), strategy)
120 && tuple_equals<Tuple, I + 1, N>::apply(t1, t2, strategy);
7c673cae
FG
121 }
122};
123
124template <typename Tuple, size_t I>
125struct tuple_equals<Tuple, I, I>
126{
92f5a8d4
TL
127 template <typename Strategy>
128 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
7c673cae
FG
129 {
130 return true;
131 }
132};
133
134// TODO: Consider this: Since equal_to<> is using geometry::equals() it's possible that
135// two compared Indexables are not exactly the same! They will be spatially equal
136// but not strictly equal. Consider 2 Segments with reversed order of points.
137// Therefore it's possible that during the Value removal different value will be
138// removed than the one that was passed.
139
140/*!
141\brief The function object comparing Values.
142
143It compares Geometries using geometry::equals() function. Other types are compared using operator==.
144The default version handles Values which are Indexables.
145This template is also specialized for std::pair<T1, T2> and boost::tuple<...>.
146
147\tparam Value The type of objects which are compared by this function object.
148\tparam IsIndexable If true, Values are compared using boost::geometry::equals() functions.
149*/
150template <typename Value,
151 bool IsIndexable = is_indexable<Value>::value>
152struct equal_to
153{
154 /*! \brief The type of result returned by function object. */
155 typedef bool result_type;
156
157 /*!
158 \brief Compare values. If Value is a Geometry geometry::equals() function is used.
159
160 \param l First value.
161 \param r Second value.
162 \return true if values are equal.
163 */
92f5a8d4
TL
164 template <typename Strategy>
165 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
7c673cae 166 {
92f5a8d4 167 return detail::equals<Value>::apply(l, r, strategy);
7c673cae
FG
168 }
169};
170
171/*!
172\brief The function object comparing Values.
173
174This specialization compares values of type std::pair<T1, T2>.
175It compares pairs' first values, then second values.
176
177\tparam T1 The first type.
178\tparam T2 The second type.
179*/
180template <typename T1, typename T2>
181struct equal_to<std::pair<T1, T2>, false>
182{
183 /*! \brief The type of result returned by function object. */
184 typedef bool result_type;
185
186 /*!
187 \brief Compare values. If pair<> Value member is a Geometry geometry::equals() function is used.
188
189 \param l First value.
190 \param r Second value.
191 \return true if values are equal.
192 */
92f5a8d4
TL
193 template <typename Strategy>
194 inline bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r,
195 Strategy const& strategy) const
7c673cae 196 {
92f5a8d4
TL
197 return detail::equals<T1>::apply(l.first, r.first, strategy)
198 && detail::equals<T2>::apply(l.second, r.second, strategy);
7c673cae
FG
199 }
200};
201
202/*!
203\brief The function object comparing Values.
204
205This specialization compares values of type boost::tuple<...>.
206It compares all members of the tuple from the first one to the last one.
207*/
208template <typename T0, typename T1, typename T2, typename T3, typename T4,
209 typename T5, typename T6, typename T7, typename T8, typename T9>
210struct equal_to<boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
211{
212 typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
213
214 /*! \brief The type of result returned by function object. */
215 typedef bool result_type;
216
217 /*!
218 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
219
220 \param l First value.
221 \param r Second value.
222 \return true if values are equal.
223 */
92f5a8d4
TL
224 template <typename Strategy>
225 inline bool operator()(value_type const& l, value_type const& r,
226 Strategy const& strategy) const
7c673cae
FG
227 {
228 return detail::tuple_equals<
229 value_type, 0, boost::tuples::length<value_type>::value
92f5a8d4 230 >::apply(l, r, strategy);
7c673cae
FG
231 }
232};
233
234}}}} // namespace boost::geometry::index::detail
235
236#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
237
238#include <tuple>
239
240namespace boost { namespace geometry { namespace index { namespace detail {
241
242template <typename Tuple, size_t I, size_t N>
243struct std_tuple_equals
244{
92f5a8d4
TL
245 template <typename Strategy>
246 inline static bool apply(Tuple const& t1, Tuple const& t2, Strategy const& strategy)
7c673cae
FG
247 {
248 typedef typename std::tuple_element<I, Tuple>::type T;
249
92f5a8d4
TL
250 return equals<T>::apply(std::get<I>(t1), std::get<I>(t2), strategy)
251 && std_tuple_equals<Tuple, I + 1, N>::apply(t1, t2, strategy);
7c673cae
FG
252 }
253};
254
255template <typename Tuple, size_t I>
256struct std_tuple_equals<Tuple, I, I>
257{
92f5a8d4
TL
258 template <typename Strategy>
259 inline static bool apply(Tuple const&, Tuple const&, Strategy const&)
7c673cae
FG
260 {
261 return true;
262 }
263};
264
265/*!
266\brief The function object comparing Values.
267
268This specialization compares values of type std::tuple<Args...>.
269It's defined if the compiler supports tuples and variadic templates.
270It compares all members of the tuple from the first one to the last one.
271*/
272template <typename ...Args>
273struct equal_to<std::tuple<Args...>, false>
274{
275 typedef std::tuple<Args...> value_type;
276
277 /*! \brief The type of result returned by function object. */
278 typedef bool result_type;
279
280 /*!
281 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
282
283 \param l First value.
284 \param r Second value.
285 \return true if values are equal.
286 */
92f5a8d4
TL
287 template <typename Strategy>
288 bool operator()(value_type const& l, value_type const& r, Strategy const& strategy) const
7c673cae
FG
289 {
290 return detail::std_tuple_equals<
291 value_type, 0, std::tuple_size<value_type>::value
92f5a8d4 292 >::apply(l, r, strategy);
7c673cae
FG
293 }
294};
295
296}}}} // namespace boost::geometry::index::detail
297
298#endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
299
300namespace boost { namespace geometry { namespace index {
301
302/*!
303\brief The function object comparing Values.
304
305The default version handles Values which are Indexables, std::pair<T1, T2>, boost::tuple<...>
306and std::tuple<...> if STD tuples and variadic templates are supported.
307All members are compared from left to right, Geometries using boost::geometry::equals() function,
308other types using operator==.
309
310\tparam Value The type of objects which are compared by this function object.
311*/
312template <typename Value>
313struct equal_to
314 : detail::equal_to<Value>
315{
316 /*! \brief The type of result returned by function object. */
317 typedef typename detail::equal_to<Value>::result_type result_type;
318
319 /*!
320 \brief Compare Values.
321
322 \param l First value.
323 \param r Second value.
324 \return true if Values are equal.
325 */
326 inline bool operator()(Value const& l, Value const& r) const
327 {
92f5a8d4
TL
328 return detail::equal_to<Value>::operator()(l, r, default_strategy());
329 }
330
331 template <typename Strategy>
332 inline bool operator()(Value const& l, Value const& r, Strategy const& strategy) const
333 {
334 return detail::equal_to<Value>::operator()(l, r, strategy);
7c673cae
FG
335 }
336};
337
338}}} // namespace boost::geometry::index
339
340#endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP