]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Boost.Geometry |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2021 Oracle and/or its affiliates. | |
5 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
6 | ||
7 | // Use, modification and distribution is subject to the Boost Software License, | |
8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
9 | // http://www.boost.org/LICENSE_1_0.txt) | |
10 | ||
11 | ||
12 | #include <iterator> | |
13 | #include <vector> | |
14 | ||
15 | #include <geometry_test_common.hpp> | |
16 | ||
17 | #include <boost/geometry/core/visit.hpp> | |
18 | #include <boost/geometry/geometries/adapted/boost_any.hpp> | |
19 | #include <boost/geometry/geometries/adapted/boost_variant.hpp> | |
20 | #include <boost/geometry/geometries/adapted/boost_variant2.hpp> | |
21 | #include <boost/geometry/geometries/adapted/std_any.hpp> | |
22 | #include <boost/geometry/geometries/adapted/std_variant.hpp> | |
23 | #include <boost/geometry/geometries/geometries.hpp> | |
24 | #include <boost/geometry/util/type_traits.hpp> | |
25 | ||
26 | ||
27 | using point_t = bg::model::point<double, 2, bg::cs::cartesian>; | |
28 | using linestring_t = bg::model::linestring<point_t>; | |
29 | using polygon_t = bg::model::polygon<point_t>; | |
30 | ||
31 | ||
32 | namespace boost { namespace geometry { namespace traits | |
33 | { | |
34 | ||
35 | template <> | |
36 | struct geometry_types<boost::any> | |
37 | { | |
38 | typedef util::type_sequence<point_t, linestring_t, polygon_t> type; | |
39 | }; | |
40 | ||
41 | #ifndef BOOST_NO_CXX17_HDR_ANY | |
42 | ||
43 | template <> | |
44 | struct geometry_types<std::any> | |
45 | { | |
46 | typedef util::type_sequence<point_t, linestring_t, polygon_t> type; | |
47 | }; | |
48 | ||
49 | #endif // BOOST_NO_CXX17_HDR_ANY | |
50 | ||
51 | }}} | |
52 | ||
53 | ||
54 | template <typename DynamicGeometry> | |
55 | void test_all() | |
56 | { | |
57 | DynamicGeometry dg = point_t(1, 2); | |
58 | bg::traits::visit<DynamicGeometry>::apply([](auto g) | |
59 | { | |
60 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
61 | BOOST_STATIC_ASSERT(! std::is_const<decltype(g)>::value); | |
62 | }, dg); | |
63 | bg::traits::visit<DynamicGeometry>::apply([](auto const g) | |
64 | { | |
65 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
66 | BOOST_STATIC_ASSERT(std::is_const<decltype(g)>::value); | |
67 | }, dg); | |
68 | bg::traits::visit<DynamicGeometry>::apply([](auto & g) | |
69 | { | |
70 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
71 | BOOST_STATIC_ASSERT(! std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
72 | }, dg); | |
73 | bg::traits::visit<DynamicGeometry>::apply([](auto const& g) | |
74 | { | |
75 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
76 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
77 | }, dg); | |
78 | ||
79 | DynamicGeometry const cdg = point_t(3, 4); | |
80 | bg::traits::visit<DynamicGeometry>::apply([](auto g) | |
81 | { | |
82 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
83 | BOOST_STATIC_ASSERT(! std::is_const<decltype(g)>::value); | |
84 | }, cdg); | |
85 | bg::traits::visit<DynamicGeometry>::apply([](auto const g) | |
86 | { | |
87 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
88 | BOOST_STATIC_ASSERT(std::is_const<decltype(g)>::value); | |
89 | }, cdg); | |
90 | bg::traits::visit<DynamicGeometry>::apply([](auto & g) | |
91 | { | |
92 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
93 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
94 | }, cdg); | |
95 | bg::traits::visit<DynamicGeometry>::apply([](auto const& g) | |
96 | { | |
97 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
98 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
99 | }, cdg); | |
100 | ||
101 | ||
102 | bg::traits::visit<DynamicGeometry>::apply([](auto && g) | |
103 | { | |
104 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
105 | BOOST_STATIC_ASSERT(! std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
106 | BOOST_STATIC_ASSERT(! std::is_rvalue_reference<decltype(g)>::value); | |
107 | }, dg); | |
108 | bg::traits::visit<DynamicGeometry>::apply([](auto && g) | |
109 | { | |
110 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
111 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
112 | BOOST_STATIC_ASSERT(! std::is_rvalue_reference<decltype(g)>::value); | |
113 | }, cdg); | |
114 | bg::traits::visit<DynamicGeometry>::apply([](auto && g) | |
115 | { | |
116 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
117 | BOOST_STATIC_ASSERT(! std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
118 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g)>::value); | |
119 | }, std::move(dg)); | |
120 | bg::traits::visit<DynamicGeometry>::apply([](auto && g) | |
121 | { | |
122 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
123 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
124 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g)>::value); | |
125 | }, std::move(cdg)); | |
126 | bg::traits::visit<DynamicGeometry>::apply([](auto && g) | |
127 | { | |
128 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
129 | BOOST_STATIC_ASSERT(! std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
130 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g)>::value); | |
131 | }, DynamicGeometry{ point_t(1, 2) }); | |
132 | ||
133 | ||
134 | bg::traits::visit<DynamicGeometry, DynamicGeometry>::apply([](auto && g1, auto && g2) | |
135 | { | |
136 | BOOST_CHECK(bg::util::is_point<decltype(g1)>::value); | |
137 | BOOST_CHECK(bg::util::is_point<decltype(g2)>::value); | |
138 | BOOST_STATIC_ASSERT(! std::is_const<std::remove_reference_t<decltype(g1)>>::value); | |
139 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g2)>>::value); | |
140 | BOOST_STATIC_ASSERT(! std::is_rvalue_reference<decltype(g1)>::value); | |
141 | BOOST_STATIC_ASSERT(! std::is_rvalue_reference<decltype(g2)>::value); | |
142 | }, dg, cdg); | |
143 | ||
144 | bg::traits::visit<DynamicGeometry, DynamicGeometry>::apply([](auto && g1, auto && g2) | |
145 | { | |
146 | BOOST_CHECK(bg::util::is_point<decltype(g1)>::value); | |
147 | BOOST_CHECK(bg::util::is_point<decltype(g2)>::value); | |
148 | BOOST_STATIC_ASSERT(! std::is_const<std::remove_reference_t<decltype(g1)>>::value); | |
149 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g2)>>::value); | |
150 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g1)>::value); | |
151 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g2)>::value); | |
152 | }, std::move(dg), std::move(cdg)); | |
153 | ||
154 | bg::traits::visit<DynamicGeometry, DynamicGeometry>::apply([](auto && g1, auto && g2) | |
155 | { | |
156 | BOOST_CHECK(bg::util::is_point<decltype(g2)>::value); | |
157 | BOOST_CHECK(bg::util::is_point<decltype(g1)>::value); | |
158 | BOOST_STATIC_ASSERT(!std::is_const<std::remove_reference_t<decltype(g2)>>::value); | |
159 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g1)>>::value); | |
160 | BOOST_STATIC_ASSERT(!std::is_rvalue_reference<decltype(g2)>::value); | |
161 | BOOST_STATIC_ASSERT(!std::is_rvalue_reference<decltype(g1)>::value); | |
162 | }, cdg, dg); | |
163 | ||
164 | bg::traits::visit<DynamicGeometry, DynamicGeometry>::apply([](auto && g1, auto && g2) | |
165 | { | |
166 | BOOST_CHECK(bg::util::is_point<decltype(g2)>::value); | |
167 | BOOST_CHECK(bg::util::is_point<decltype(g1)>::value); | |
168 | BOOST_STATIC_ASSERT(!std::is_const<std::remove_reference_t<decltype(g2)>>::value); | |
169 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g1)>>::value); | |
170 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g2)>::value); | |
171 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g1)>::value); | |
172 | }, std::move(cdg), std::move(dg)); | |
173 | ||
174 | ||
175 | std::vector<DynamicGeometry> v = { DynamicGeometry{ point_t(1, 2) } }; | |
176 | std::vector<DynamicGeometry> const cv = { DynamicGeometry{ point_t(1, 2) } }; | |
177 | ||
178 | bg::traits::iter_visit<std::vector<DynamicGeometry>>::apply([](auto && g) | |
179 | { | |
180 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
181 | BOOST_STATIC_ASSERT(! std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
182 | BOOST_STATIC_ASSERT(! std::is_rvalue_reference<decltype(g)>::value); | |
183 | }, v.begin()); | |
184 | ||
185 | bg::traits::iter_visit<std::vector<DynamicGeometry>>::apply([](auto && g) | |
186 | { | |
187 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
188 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
189 | BOOST_STATIC_ASSERT(! std::is_rvalue_reference<decltype(g)>::value); | |
190 | }, cv.begin()); | |
191 | ||
192 | bg::traits::iter_visit<std::vector<DynamicGeometry>>::apply([](auto && g) | |
193 | { | |
194 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
195 | BOOST_STATIC_ASSERT(! std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
196 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g)>::value); | |
197 | }, std::make_move_iterator(v.begin())); | |
198 | ||
199 | bg::traits::iter_visit<std::vector<DynamicGeometry>>::apply([](auto && g) | |
200 | { | |
201 | BOOST_CHECK(bg::util::is_point<decltype(g)>::value); | |
202 | BOOST_STATIC_ASSERT(std::is_const<std::remove_reference_t<decltype(g)>>::value); | |
203 | BOOST_STATIC_ASSERT(std::is_rvalue_reference<decltype(g)>::value); | |
204 | }, std::make_move_iterator(cv.begin())); | |
205 | } | |
206 | ||
207 | int test_main(int, char* []) | |
208 | { | |
209 | test_all<boost::any>(); | |
210 | test_all<boost::variant<point_t, linestring_t, polygon_t>>(); | |
211 | test_all<boost::variant2::variant<point_t, linestring_t, polygon_t>>(); | |
212 | ||
213 | #ifndef BOOST_NO_CXX17_HDR_ANY | |
214 | test_all<std::any>(); | |
215 | #endif | |
216 | #ifndef BOOST_NO_CXX17_HDR_VARIANT | |
217 | test_all<std::variant<point_t, linestring_t, polygon_t>>(); | |
218 | #endif | |
219 | ||
220 | return 0; | |
221 | } |