comparison DEPENDENCIES/generic/include/boost/geometry/index/equal_to.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
1 // Boost.Geometry Index 1 // Boost.Geometry Index
2 // 2 //
3 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. 3 // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
4 // 4 //
5 // Use, modification and distribution is subject to the Boost Software License, 5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt) 7 // http://www.boost.org/LICENSE_1_0.txt)
8 8
9 #ifndef BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP 9 #ifndef BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
10 #define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP 10 #define BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP
11 11
12 #include <boost/geometry/algorithms/equals.hpp> 12 #include <boost/geometry/algorithms/equals.hpp>
13 13 #include <boost/geometry/index/indexable.hpp>
14 namespace boost { namespace geometry { namespace index { 14
15 15 namespace boost { namespace geometry { namespace index { namespace detail {
16 namespace detail { 16
17 template <typename Geometry,
18 typename Tag = typename geometry::tag<Geometry>::type>
19 struct equals
20 {
21 inline static bool apply(Geometry const& g1, Geometry const& g2)
22 {
23 return geometry::equals(g1, g2);
24 }
25 };
17 26
18 template <typename Geometry, typename Tag> 27 template <typename Geometry, typename Tag>
19 struct equals 28 struct equals<Geometry *, Tag>
20 { 29 {
21 static bool apply(Geometry const& g1, Geometry const& g2) 30 inline static bool apply(const Geometry * g1, const Geometry * g2)
22 { 31 {
23 return geometry::equals(g1, g2); 32 return g1 == g2;
24 } 33 }
25 }; 34 };
26 35
27 template <typename T> 36 template <typename T>
28 struct equals<T, void> 37 struct equals<T, void>
29 { 38 {
30 static bool apply(T const& v1, T const& v2) 39 inline static bool apply(T const& v1, T const& v2)
31 { 40 {
32 return v1 == v2; 41 return v1 == v2;
33 } 42 }
34 }; 43 };
35 44
37 struct tuple_equals 46 struct tuple_equals
38 { 47 {
39 inline static bool apply(Tuple const& t1, Tuple const& t2) 48 inline static bool apply(Tuple const& t1, Tuple const& t2)
40 { 49 {
41 typedef typename boost::tuples::element<I, Tuple>::type T; 50 typedef typename boost::tuples::element<I, Tuple>::type T;
42 return 51
43 equals< 52 return equals<T>::apply(boost::get<I>(t1), boost::get<I>(t2))
44 T, typename geometry::traits::tag<T>::type 53 && tuple_equals<Tuple, I+1, N>::apply(t1, t2);
45 >::apply(boost::get<I>(t1), boost::get<I>(t2))
46 &&
47 tuple_equals<Tuple, I+1, N>::apply(t1, t2);
48 } 54 }
49 }; 55 };
50 56
51 template <typename Tuple, size_t I> 57 template <typename Tuple, size_t I>
52 struct tuple_equals<Tuple, I, I> 58 struct tuple_equals<Tuple, I, I>
55 { 61 {
56 return true; 62 return true;
57 } 63 }
58 }; 64 };
59 65
60 } // namespace detail 66 // TODO: Consider this: Since equal_to<> is using geometry::equals() it's possible that
67 // two compared Indexables are not exactly the same! They will be spatially equal
68 // but not strictly equal. Consider 2 Segments with reversed order of points.
69 // Therefore it's possible that during the Value removal different value will be
70 // removed than the one that was passed.
61 71
62 /*! 72 /*!
63 \brief The function object comparing Values. 73 \brief The function object comparing Values.
64 74
65 It compares Geometries using geometry::equals() function. Other types are compared using operator==. 75 It compares Geometries using geometry::equals() function. Other types are compared using operator==.
66 The default version handles Values which are Indexables. 76 The default version handles Values which are Indexables.
67 This template is also specialized for std::pair<T1, T2> and boost::tuple<...>. 77 This template is also specialized for std::pair<T1, T2> and boost::tuple<...>.
68 78
69 \tparam Value The type of objects which are compared by this function object. 79 \tparam Value The type of objects which are compared by this function object.
70 */ 80 \tparam IsIndexable If true, Values are compared using boost::geometry::equals() functions.
71 template <typename Value> 81 */
82 template <typename Value,
83 bool IsIndexable = is_indexable<Value>::value>
72 struct equal_to 84 struct equal_to
73 { 85 {
74 /*! \brief The type of result returned by function object. */ 86 /*! \brief The type of result returned by function object. */
75 typedef bool result_type; 87 typedef bool result_type;
76 88
79 91
80 \param l First value. 92 \param l First value.
81 \param r Second value. 93 \param r Second value.
82 \return true if values are equal. 94 \return true if values are equal.
83 */ 95 */
84 bool operator()(Value const& l, Value const& r) const 96 inline bool operator()(Value const& l, Value const& r) const
85 { 97 {
86 return detail::equals<Value, typename geometry::traits::tag<Value>::type>::apply(l ,r); 98 return detail::equals<Value>::apply(l ,r);
87 } 99 }
88 }; 100 };
89 101
90 /*! 102 /*!
91 \brief The function object comparing Values. 103 \brief The function object comparing Values.
95 107
96 \tparam T1 The first type. 108 \tparam T1 The first type.
97 \tparam T2 The second type. 109 \tparam T2 The second type.
98 */ 110 */
99 template <typename T1, typename T2> 111 template <typename T1, typename T2>
100 struct equal_to< std::pair<T1, T2> > 112 struct equal_to<std::pair<T1, T2>, false>
101 { 113 {
102 /*! \brief The type of result returned by function object. */ 114 /*! \brief The type of result returned by function object. */
103 typedef bool result_type; 115 typedef bool result_type;
104 116
105 /*! 117 /*!
107 119
108 \param l First value. 120 \param l First value.
109 \param r Second value. 121 \param r Second value.
110 \return true if values are equal. 122 \return true if values are equal.
111 */ 123 */
112 bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r) const 124 inline bool operator()(std::pair<T1, T2> const& l, std::pair<T1, T2> const& r) const
113 { 125 {
114 typedef detail::equals<T1, typename geometry::traits::tag<T1>::type> equals1; 126 return detail::equals<T1>::apply(l.first, r.first)
115 typedef detail::equals<T2, typename geometry::traits::tag<T2>::type> equals2; 127 && detail::equals<T2>::apply(l.second, r.second);
116
117 return equals1::apply(l.first, r.first) && equals2::apply(l.second, r.second);
118 } 128 }
119 }; 129 };
120 130
121 /*! 131 /*!
122 \brief The function object comparing Values. 132 \brief The function object comparing Values.
124 This specialization compares values of type boost::tuple<...>. 134 This specialization compares values of type boost::tuple<...>.
125 It compares all members of the tuple from the first one to the last one. 135 It compares all members of the tuple from the first one to the last one.
126 */ 136 */
127 template <typename T0, typename T1, typename T2, typename T3, typename T4, 137 template <typename T0, typename T1, typename T2, typename T3, typename T4,
128 typename T5, typename T6, typename T7, typename T8, typename T9> 138 typename T5, typename T6, typename T7, typename T8, typename T9>
129 struct equal_to< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> > 139 struct equal_to<boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
130 { 140 {
131 typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type; 141 typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
132 142
133 /*! \brief The type of result returned by function object. */ 143 /*! \brief The type of result returned by function object. */
134 typedef bool result_type; 144 typedef bool result_type;
138 148
139 \param l First value. 149 \param l First value.
140 \param r Second value. 150 \param r Second value.
141 \return true if values are equal. 151 \return true if values are equal.
142 */ 152 */
143 bool operator()(value_type const& l, value_type const& r) const 153 inline bool operator()(value_type const& l, value_type const& r) const
144 { 154 {
145 return detail::tuple_equals< 155 return detail::tuple_equals<
146 value_type, 0, boost::tuples::length<value_type>::value 156 value_type, 0, boost::tuples::length<value_type>::value
147 >::apply(l ,r); 157 >::apply(l ,r);
148 } 158 }
149 }; 159 };
150 160
151 }}} // namespace boost::geometry::index 161 }}}} // namespace boost::geometry::index::detail
152 162
153 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 163 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
154 164
155 #include <tuple> 165 #include <tuple>
156 166
157 namespace boost { namespace geometry { namespace index { 167 namespace boost { namespace geometry { namespace index { namespace detail {
158
159 namespace detail {
160 168
161 template <typename Tuple, size_t I, size_t N> 169 template <typename Tuple, size_t I, size_t N>
162 struct std_tuple_equals 170 struct std_tuple_equals
163 { 171 {
164 inline static bool apply(Tuple const& t1, Tuple const& t2) 172 inline static bool apply(Tuple const& t1, Tuple const& t2)
165 { 173 {
166 typedef typename std::tuple_element<I, Tuple>::type T; 174 typedef typename std::tuple_element<I, Tuple>::type T;
167 return 175
168 equals< 176 return equals<T>::apply(std::get<I>(t1), std::get<I>(t2))
169 T, typename geometry::traits::tag<T>::type 177 && std_tuple_equals<Tuple, I+1, N>::apply(t1, t2);
170 >::apply(std::get<I>(t1), std::get<I>(t2))
171 &&
172 std_tuple_equals<Tuple, I+1, N>::apply(t1, t2);
173 } 178 }
174 }; 179 };
175 180
176 template <typename Tuple, size_t I> 181 template <typename Tuple, size_t I>
177 struct std_tuple_equals<Tuple, I, I> 182 struct std_tuple_equals<Tuple, I, I>
179 inline static bool apply(Tuple const&, Tuple const&) 184 inline static bool apply(Tuple const&, Tuple const&)
180 { 185 {
181 return true; 186 return true;
182 } 187 }
183 }; 188 };
184
185 } // namespace detail
186 189
187 /*! 190 /*!
188 \brief The function object comparing Values. 191 \brief The function object comparing Values.
189 192
190 This specialization compares values of type std::tuple<Args...>. 193 This specialization compares values of type std::tuple<Args...>.
191 It's defined if the compiler supports tuples and variadic templates. 194 It's defined if the compiler supports tuples and variadic templates.
192 It compares all members of the tuple from the first one to the last one. 195 It compares all members of the tuple from the first one to the last one.
193 */ 196 */
194 template <typename ...Args> 197 template <typename ...Args>
195 struct equal_to< std::tuple<Args...> > 198 struct equal_to<std::tuple<Args...>, false>
196 { 199 {
197 typedef std::tuple<Args...> value_type; 200 typedef std::tuple<Args...> value_type;
198 201
199 /*! \brief The type of result returned by function object. */ 202 /*! \brief The type of result returned by function object. */
200 typedef bool result_type; 203 typedef bool result_type;
212 value_type, 0, std::tuple_size<value_type>::value 215 value_type, 0, std::tuple_size<value_type>::value
213 >::apply(l ,r); 216 >::apply(l ,r);
214 } 217 }
215 }; 218 };
216 219
220 }}}} // namespace boost::geometry::index::detail
221
222 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
223
224 namespace boost { namespace geometry { namespace index {
225
226 /*!
227 \brief The function object comparing Values.
228
229 The default version handles Values which are Indexables, std::pair<T1, T2>, boost::tuple<...>
230 and std::tuple<...> if STD tuples and variadic templates are supported.
231 All members are compared from left to right, Geometries using boost::geometry::equals() function,
232 other types using operator==.
233
234 \tparam Value The type of objects which are compared by this function object.
235 */
236 template <typename Value>
237 struct equal_to
238 : detail::equal_to<Value>
239 {
240 /*! \brief The type of result returned by function object. */
241 typedef typename detail::equal_to<Value>::result_type result_type;
242
243 /*!
244 \brief Compare Values.
245
246 \param l First value.
247 \param r Second value.
248 \return true if Values are equal.
249 */
250 inline bool operator()(Value const& l, Value const& r) const
251 {
252 return detail::equal_to<Value>::operator()(l ,r);
253 }
254 };
255
217 }}} // namespace boost::geometry::index 256 }}} // namespace boost::geometry::index
218 257
219 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
220
221 #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP 258 #endif // BOOST_GEOMETRY_INDEX_EQUAL_TO_HPP