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