]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/poly_collection/test/test_erasure.cpp
1 /* Copyright 2016-2017 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 #include "test_erasure.hpp"
11 #include <boost/core/lightweight_test.hpp>
13 #include "any_types.hpp"
14 #include "base_types.hpp"
15 #include "function_types.hpp"
16 #include "test_utilities.hpp"
18 using namespace test_utilities
;
20 template<typename Type
,typename PolyCollection
>
21 void test_local_erase(const PolyCollection
& p2
)
23 using size_type
=typename
PolyCollection::size_type
;
25 for(size_type i
=0;i
<p2
.template size
<Type
>();++i
){
27 auto it
=p
.erase(p
.template cbegin
<Type
>()+i
);
28 BOOST_TEST(it
-p
.template begin
<Type
>()==(std::ptrdiff_t)i
);
29 BOOST_TEST(p
.template size
<Type
>()==p2
.template size
<Type
>()-1);
33 template<typename Type
,typename PolyCollection
>
34 void test_local_range_erase(const PolyCollection
& p2
)
36 using size_type
=typename
PolyCollection::size_type
;
38 for(size_type i
=0;i
<=p2
.template size
<Type
>();++i
){
39 for(size_type j
=i
;j
<=p2
.template size
<Type
>();++j
){
41 auto first
=p
.template cbegin
<Type
>()+i
,
42 last
=p
.template cbegin
<Type
>()+j
;
43 auto it
=p
.erase(first
,last
);
44 BOOST_TEST(it
-p
.template begin
<Type
>()==(std::ptrdiff_t)i
);
45 BOOST_TEST(p
.template size
<Type
>()==p2
.template size
<Type
>()-(j
-i
));
50 template<typename Type
,typename PolyCollection
>
51 void test_local_clear(const PolyCollection
& p2
)
54 p
.template clear
<Type
>();
55 BOOST_TEST(p
.template empty
<Type
>());
56 BOOST_TEST(p
.size()==p2
.size()-p2
.template size
<Type
>());
59 template<typename PolyCollection
,typename ValueFactory
,typename
... Types
>
62 using size_type
=typename
PolyCollection::size_type
;
67 fill
<constraints
<is_copy_constructible
>,Types
...>(p2
,v
,5);
68 auto sit
=p2
.segment_traversal().begin();
69 p2
.clear(sit
->type_info());
71 p2
.clear(sit
->type_info());
73 for(size_type i
=0;i
<p2
.size();++i
){
75 auto it
=p
.erase(std::next(p
.cbegin(),i
));
76 BOOST_TEST(std::distance(p
.begin(),it
)==(std::ptrdiff_t)i
);
77 BOOST_TEST(p
.size()==p2
.size()-1);
80 for(auto s
:p2
.segment_traversal()){
81 auto& info
=s
.type_info();
82 for(size_type i
=0;i
<p2
.size(info
);++i
){
84 auto it
=p
.erase(p
.cbegin(info
)+i
);
85 BOOST_TEST(it
-p
.begin(info
)==(std::ptrdiff_t)i
);
86 BOOST_TEST(p
.size(info
)==p2
.size(info
)-1);
91 p2
.template is_registered
<Types
>()?test_local_erase
<Types
>(p2
),0:0)...);
93 for(size_type i
=0;i
<=p2
.size();++i
){
94 for(size_type j
=i
;j
<=p2
.size();++j
){
96 auto first
=std::next(p
.cbegin(),i
),
97 last
=std::next(p
.cbegin(),j
);
98 auto it
=p
.erase(first
,last
);
99 BOOST_TEST(std::distance(p
.begin(),it
)==(std::ptrdiff_t)i
);
100 BOOST_TEST(p
.size()==p2
.size()-(j
-i
));
104 for(auto s
:p2
.segment_traversal()){
105 auto& info
=s
.type_info();
106 for(size_type i
=0;i
<=p2
.size(info
);++i
){
107 for(size_type j
=i
;j
<=p2
.size(info
);++j
){
109 auto first
=p
.cbegin(info
)+i
,
110 last
=p
.cbegin(info
)+j
;
111 auto it
=p
.erase(first
,last
);
112 BOOST_TEST(it
-p
.begin(info
)==(std::ptrdiff_t)i
);
113 BOOST_TEST(p
.size(info
)==p2
.size(info
)-(j
-i
));
118 do_((p2
.template is_registered
<Types
>()?
119 test_local_range_erase
<Types
>(p2
),0:0)...);
123 BOOST_TEST(p
.empty());
125 for(auto s
:p2
.segment_traversal()){
126 auto& info
=s
.type_info();
129 BOOST_TEST(p
.empty(info
));
130 BOOST_TEST(p
.size()==p2
.size()-p2
.size(info
));
133 do_((p2
.template is_registered
<Types
>()?
134 test_local_clear
<Types
>(p2
),0:0)...);
140 any_types::collection
,auto_increment
,
141 any_types::t1
,any_types::t2
,any_types::t3
,
142 any_types::t4
,any_types::t5
>();
144 base_types::collection
,auto_increment
,
145 base_types::t1
,base_types::t2
,base_types::t3
,
146 base_types::t4
,base_types::t5
>();
148 function_types::collection
,auto_increment
,
149 function_types::t1
,function_types::t2
,function_types::t3
,
150 function_types::t4
,function_types::t5
>();