comparison DEPENDENCIES/generic/include/boost/geometry/index/equal_to.hpp @ 16:2665513ce2d3

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