Chris@16
|
1 // Boost.Geometry Index
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
|
Chris@16
|
4 //
|
Chris@16
|
5 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 #ifndef BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
|
Chris@16
|
10 #define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/geometry/algorithms/equals.hpp>
|
Chris@16
|
13
|
Chris@16
|
14 namespace boost { namespace geometry { namespace index {
|
Chris@16
|
15
|
Chris@16
|
16 namespace detail {
|
Chris@16
|
17
|
Chris@16
|
18 template <typename Geometry, typename Tag>
|
Chris@16
|
19 struct equals
|
Chris@16
|
20 {
|
Chris@16
|
21 static bool apply(Geometry const& g1, Geometry const& g2)
|
Chris@16
|
22 {
|
Chris@16
|
23 return geometry::equals(g1, g2);
|
Chris@16
|
24 }
|
Chris@16
|
25 };
|
Chris@16
|
26
|
Chris@16
|
27 template <typename T>
|
Chris@16
|
28 struct equals<T, void>
|
Chris@16
|
29 {
|
Chris@16
|
30 static bool apply(T const& v1, T const& v2)
|
Chris@16
|
31 {
|
Chris@16
|
32 return v1 == v2;
|
Chris@16
|
33 }
|
Chris@16
|
34 };
|
Chris@16
|
35
|
Chris@16
|
36 template <typename Tuple, size_t I, size_t N>
|
Chris@16
|
37 struct tuple_equals
|
Chris@16
|
38 {
|
Chris@16
|
39 inline static bool apply(Tuple const& t1, Tuple const& t2)
|
Chris@16
|
40 {
|
Chris@16
|
41 typedef typename boost::tuples::element<I, Tuple>::type T;
|
Chris@16
|
42 return
|
Chris@16
|
43 equals<
|
Chris@16
|
44 T, typename geometry::traits::tag<T>::type
|
Chris@16
|
45 >::apply(boost::get<I>(t1), boost::get<I>(t2))
|
Chris@16
|
46 &&
|
Chris@16
|
47 tuple_equals<Tuple, I+1, N>::apply(t1, t2);
|
Chris@16
|
48 }
|
Chris@16
|
49 };
|
Chris@16
|
50
|
Chris@16
|
51 template <typename Tuple, size_t I>
|
Chris@16
|
52 struct tuple_equals<Tuple, I, I>
|
Chris@16
|
53 {
|
Chris@16
|
54 inline static bool apply(Tuple const&, Tuple const&)
|
Chris@16
|
55 {
|
Chris@16
|
56 return true;
|
Chris@16
|
57 }
|
Chris@16
|
58 };
|
Chris@16
|
59
|
Chris@16
|
60 } // namespace detail
|
Chris@16
|
61
|
Chris@16
|
62 /*!
|
Chris@16
|
63 \brief The function object comparing Values.
|
Chris@16
|
64
|
Chris@16
|
65 It compares Geometries using geometry::equals() function. Other types are compared using operator==.
|
Chris@16
|
66 The default version handles Values which are Indexables.
|
Chris@16
|
67 This template is also specialized for std::pair<T1, T2> and boost::tuple<...>.
|
Chris@16
|
68
|
Chris@16
|
69 \tparam Value The type of objects which are compared by this function object.
|
Chris@16
|
70 */
|
Chris@16
|
71 template <typename Value>
|
Chris@16
|
72 struct equal_to
|
Chris@16
|
73 {
|
Chris@16
|
74 /*! \brief The type of result returned by function object. */
|
Chris@16
|
75 typedef bool result_type;
|
Chris@16
|
76
|
Chris@16
|
77 /*!
|
Chris@16
|
78 \brief Compare values. If Value is a Geometry geometry::equals() function is used.
|
Chris@16
|
79
|
Chris@16
|
80 \param l First value.
|
Chris@16
|
81 \param r Second value.
|
Chris@16
|
82 \return true if values are equal.
|
Chris@16
|
83 */
|
Chris@16
|
84 bool operator()(Value const& l, Value const& r) const
|
Chris@16
|
85 {
|
Chris@16
|
86 return detail::equals<Value, typename geometry::traits::tag<Value>::type>::apply(l ,r);
|
Chris@16
|
87 }
|
Chris@16
|
88 };
|
Chris@16
|
89
|
Chris@16
|
90 /*!
|
Chris@16
|
91 \brief The function object comparing Values.
|
Chris@16
|
92
|
Chris@16
|
93 This specialization compares values of type std::pair<T1, T2>.
|
Chris@16
|
94 It compares pairs' first values, then second values.
|
Chris@16
|
95
|
Chris@16
|
96 \tparam T1 The first type.
|
Chris@16
|
97 \tparam T2 The second type.
|
Chris@16
|
98 */
|
Chris@16
|
99 template <typename T1, typename T2>
|
Chris@16
|
100 struct equal_to< std::pair<T1, T2> >
|
Chris@16
|
101 {
|
Chris@16
|
102 /*! \brief The type of result returned by function object. */
|
Chris@16
|
103 typedef bool result_type;
|
Chris@16
|
104
|
Chris@16
|
105 /*!
|
Chris@16
|
106 \brief Compare values. If pair<> Value member is a Geometry geometry::equals() function is used.
|
Chris@16
|
107
|
Chris@16
|
108 \param l First value.
|
Chris@16
|
109 \param r Second value.
|
Chris@16
|
110 \return true if values are equal.
|
Chris@16
|
111 */
|
Chris@16
|
112 bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r) const
|
Chris@16
|
113 {
|
Chris@16
|
114 typedef detail::equals<T1, typename geometry::traits::tag<T1>::type> equals1;
|
Chris@16
|
115 typedef detail::equals<T2, typename geometry::traits::tag<T2>::type> equals2;
|
Chris@16
|
116
|
Chris@16
|
117 return equals1::apply(l.first, r.first) && equals2::apply(l.second, r.second);
|
Chris@16
|
118 }
|
Chris@16
|
119 };
|
Chris@16
|
120
|
Chris@16
|
121 /*!
|
Chris@16
|
122 \brief The function object comparing Values.
|
Chris@16
|
123
|
Chris@16
|
124 This specialization compares values of type boost::tuple<...>.
|
Chris@16
|
125 It compares all members of the tuple from the first one to the last one.
|
Chris@16
|
126 */
|
Chris@16
|
127 template <typename T0, typename T1, typename T2, typename T3, typename T4,
|
Chris@16
|
128 typename T5, typename T6, typename T7, typename T8, typename T9>
|
Chris@16
|
129 struct equal_to< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
|
Chris@16
|
130 {
|
Chris@16
|
131 typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
|
Chris@16
|
132
|
Chris@16
|
133 /*! \brief The type of result returned by function object. */
|
Chris@16
|
134 typedef bool result_type;
|
Chris@16
|
135
|
Chris@16
|
136 /*!
|
Chris@16
|
137 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
|
Chris@16
|
138
|
Chris@16
|
139 \param l First value.
|
Chris@16
|
140 \param r Second value.
|
Chris@16
|
141 \return true if values are equal.
|
Chris@16
|
142 */
|
Chris@16
|
143 bool operator()(value_type const& l, value_type const& r) const
|
Chris@16
|
144 {
|
Chris@16
|
145 return detail::tuple_equals<
|
Chris@16
|
146 value_type, 0, boost::tuples::length<value_type>::value
|
Chris@16
|
147 >::apply(l ,r);
|
Chris@16
|
148 }
|
Chris@16
|
149 };
|
Chris@16
|
150
|
Chris@16
|
151 }}} // namespace boost::geometry::index
|
Chris@16
|
152
|
Chris@16
|
153 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
154
|
Chris@16
|
155 #include <tuple>
|
Chris@16
|
156
|
Chris@16
|
157 namespace boost { namespace geometry { namespace index {
|
Chris@16
|
158
|
Chris@16
|
159 namespace detail {
|
Chris@16
|
160
|
Chris@16
|
161 template <typename Tuple, size_t I, size_t N>
|
Chris@16
|
162 struct std_tuple_equals
|
Chris@16
|
163 {
|
Chris@16
|
164 inline static bool apply(Tuple const& t1, Tuple const& t2)
|
Chris@16
|
165 {
|
Chris@16
|
166 typedef typename std::tuple_element<I, Tuple>::type T;
|
Chris@16
|
167 return
|
Chris@16
|
168 equals<
|
Chris@16
|
169 T, typename geometry::traits::tag<T>::type
|
Chris@16
|
170 >::apply(std::get<I>(t1), std::get<I>(t2))
|
Chris@16
|
171 &&
|
Chris@16
|
172 std_tuple_equals<Tuple, I+1, N>::apply(t1, t2);
|
Chris@16
|
173 }
|
Chris@16
|
174 };
|
Chris@16
|
175
|
Chris@16
|
176 template <typename Tuple, size_t I>
|
Chris@16
|
177 struct std_tuple_equals<Tuple, I, I>
|
Chris@16
|
178 {
|
Chris@16
|
179 inline static bool apply(Tuple const&, Tuple const&)
|
Chris@16
|
180 {
|
Chris@16
|
181 return true;
|
Chris@16
|
182 }
|
Chris@16
|
183 };
|
Chris@16
|
184
|
Chris@16
|
185 } // namespace detail
|
Chris@16
|
186
|
Chris@16
|
187 /*!
|
Chris@16
|
188 \brief The function object comparing Values.
|
Chris@16
|
189
|
Chris@16
|
190 This specialization compares values of type std::tuple<Args...>.
|
Chris@16
|
191 It's defined if the compiler supports tuples and variadic templates.
|
Chris@16
|
192 It compares all members of the tuple from the first one to the last one.
|
Chris@16
|
193 */
|
Chris@16
|
194 template <typename ...Args>
|
Chris@16
|
195 struct equal_to< std::tuple<Args...> >
|
Chris@16
|
196 {
|
Chris@16
|
197 typedef std::tuple<Args...> value_type;
|
Chris@16
|
198
|
Chris@16
|
199 /*! \brief The type of result returned by function object. */
|
Chris@16
|
200 typedef bool result_type;
|
Chris@16
|
201
|
Chris@16
|
202 /*!
|
Chris@16
|
203 \brief Compare values. If tuple<> Value member is a Geometry geometry::equals() function is used.
|
Chris@16
|
204
|
Chris@16
|
205 \param l First value.
|
Chris@16
|
206 \param r Second value.
|
Chris@16
|
207 \return true if values are equal.
|
Chris@16
|
208 */
|
Chris@16
|
209 bool operator()(value_type const& l, value_type const& r) const
|
Chris@16
|
210 {
|
Chris@16
|
211 return detail::std_tuple_equals<
|
Chris@16
|
212 value_type, 0, std::tuple_size<value_type>::value
|
Chris@16
|
213 >::apply(l ,r);
|
Chris@16
|
214 }
|
Chris@16
|
215 };
|
Chris@16
|
216
|
Chris@16
|
217 }}} // namespace boost::geometry::index
|
Chris@16
|
218
|
Chris@16
|
219 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
220
|
Chris@16
|
221 #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
|