]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/index/test/rtree/rtree_move_pack.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / index / test / rtree / rtree_move_pack.cpp
1 // Boost.Geometry Index
2 // Unit Test
3
4 // Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <rtree/test_rtree.hpp>
11
12 #include <algorithm>
13 #include <boost/container/vector.hpp>
14 #include <boost/move/move.hpp>
15 #include <boost/move/iterator.hpp>
16
17 #include <boost/geometry/geometries/register/point.hpp>
18
19 class point_cm
20 {
21 BOOST_COPYABLE_AND_MOVABLE(point_cm)
22
23 public:
24 point_cm(double xx = 0, double yy = 0)
25 : x(xx)
26 , y(yy)
27 , moved(false)
28 {}
29 point_cm(point_cm const& other)
30 : x(other.x)
31 , y(other.y)
32 , moved(false)
33 {
34 BOOST_CHECK_MESSAGE(false, "copy not allowed");
35 }
36 point_cm & operator=(BOOST_COPY_ASSIGN_REF(point_cm) other)
37 {
38 BOOST_CHECK_MESSAGE(false, "copy not allowed");
39 x = other.x;
40 y = other.y;
41 moved = false;
42 return *this;
43 }
44 point_cm(BOOST_RV_REF(point_cm) other)
45 : x(other.x)
46 , y(other.y)
47 , moved(false)
48 {
49 BOOST_CHECK_MESSAGE(!other.moved, "only one move allowed");
50 other.moved = true;
51 }
52 point_cm & operator=(BOOST_RV_REF(point_cm) other)
53 {
54 BOOST_CHECK_MESSAGE(!other.moved, "only one move allowed");
55 x = other.x;
56 y = other.y;
57 moved = false;
58 other.moved = true;
59 return *this;
60 }
61
62 double x, y;
63 bool moved;
64 };
65
66 template <typename Point>
67 struct indexable
68 {
69 typedef Point const& result_type;
70 result_type operator()(Point const& p) const
71 {
72 BOOST_CHECK_MESSAGE(!p.moved, "can't access indexable of moved Value");
73 return p;
74 }
75 };
76
77 BOOST_GEOMETRY_REGISTER_POINT_2D(point_cm, double, bg::cs::cartesian, x, y)
78
79 template <typename Vector>
80 void append(Vector & vec, double x, double y)
81 {
82 point_cm pt(x, y);
83 BOOST_CHECK(!pt.moved);
84 vec.push_back(boost::move(pt));
85 BOOST_CHECK(pt.moved);
86 }
87
88 struct test_moved
89 {
90 test_moved(bool ex)
91 : expected(ex)
92 {}
93 template <typename Point>
94 void operator()(Point const& p) const
95 {
96 BOOST_CHECK_EQUAL(p.moved, expected);
97 }
98 bool expected;
99 };
100
101 template <typename Point, typename Params>
102 void test_rtree(Params const& params = Params())
103 {
104 // sanity check
105 boost::container::vector<Point> vec;
106 append(vec, 0, 0); append(vec, 0, 1); append(vec, 0, 2);
107 append(vec, 1, 0); append(vec, 1, 1); append(vec, 1, 2);
108 append(vec, 2, 0); append(vec, 2, 1); append(vec, 2, 2);
109
110 std::for_each(vec.begin(), vec.end(), test_moved(false));
111
112 bgi::rtree<Point, Params, indexable<Point> > rt(
113 boost::make_move_iterator(vec.begin()),
114 boost::make_move_iterator(vec.end()),
115 params);
116
117 std::for_each(vec.begin(), vec.end(), test_moved(true));
118
119 BOOST_CHECK_EQUAL(rt.size(), vec.size());
120 }
121
122
123 int test_main(int, char* [])
124 {
125 test_rtree< point_cm, bgi::linear<4> >();
126 test_rtree< point_cm, bgi::quadratic<4> >();
127 test_rtree< point_cm, bgi::rstar<4> >();
128
129 test_rtree<point_cm>(bgi::dynamic_linear(4));
130 test_rtree<point_cm>(bgi::dynamic_quadratic(4));
131 test_rtree<point_cm>(bgi::dynamic_rstar(4));
132
133 return 0;
134 }