]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/make_local_shared_array_test.cpp
2 Copyright 2017 Glen Joseph Fernandes
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
8 #include <boost/config.hpp>
9 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
10 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
11 #include <boost/align/is_aligned.hpp>
12 #include <boost/core/lightweight_test.hpp>
13 #include <boost/smart_ptr/make_local_shared.hpp>
14 #include <boost/smart_ptr/weak_ptr.hpp>
15 #include <boost/type_traits/alignment_of.hpp>
19 static unsigned instances
;
30 void set(long double value
) {
34 long double get() const {
40 type
& operator=(const type
&);
45 unsigned type::instances
= 0;
50 boost::local_shared_ptr
<int[]> result
=
51 boost::make_local_shared
<int[]>(3);
52 BOOST_TEST(result
.get() != 0);
53 BOOST_TEST(result
.local_use_count() == 1);
54 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
55 boost::alignment_of
<int>::value
));
56 BOOST_TEST(result
[0] == 0);
57 BOOST_TEST(result
[1] == 0);
58 BOOST_TEST(result
[2] == 0);
61 boost::local_shared_ptr
<int[3]> result
=
62 boost::make_local_shared
<int[3]>();
63 BOOST_TEST(result
.get() != 0);
64 BOOST_TEST(result
.local_use_count() == 1);
65 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
66 boost::alignment_of
<int>::value
));
67 BOOST_TEST(result
[0] == 0);
68 BOOST_TEST(result
[1] == 0);
69 BOOST_TEST(result
[2] == 0);
72 boost::local_shared_ptr
<int[][2]> result
=
73 boost::make_local_shared
<int[][2]>(2);
74 BOOST_TEST(result
.get() != 0);
75 BOOST_TEST(result
.local_use_count() == 1);
76 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
77 boost::alignment_of
<int>::value
));
78 BOOST_TEST(result
[0][0] == 0);
79 BOOST_TEST(result
[0][1] == 0);
80 BOOST_TEST(result
[1][0] == 0);
81 BOOST_TEST(result
[1][1] == 0);
84 boost::local_shared_ptr
<int[2][2]> result
=
85 boost::make_local_shared
<int[2][2]>();
86 BOOST_TEST(result
.get() != 0);
87 BOOST_TEST(result
.local_use_count() == 1);
88 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
89 boost::alignment_of
<int>::value
));
90 BOOST_TEST(result
[0][0] == 0);
91 BOOST_TEST(result
[0][1] == 0);
92 BOOST_TEST(result
[1][0] == 0);
93 BOOST_TEST(result
[1][1] == 0);
96 boost::local_shared_ptr
<const int[]> result
=
97 boost::make_local_shared
<const int[]>(3);
98 BOOST_TEST(result
.get() != 0);
99 BOOST_TEST(result
.local_use_count() == 1);
100 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
101 boost::alignment_of
<int>::value
));
102 BOOST_TEST(result
[0] == 0);
103 BOOST_TEST(result
[1] == 0);
104 BOOST_TEST(result
[2] == 0);
107 boost::local_shared_ptr
<const int[3]> result
=
108 boost::make_local_shared
<const int[3]>();
109 BOOST_TEST(result
.get() != 0);
110 BOOST_TEST(result
.local_use_count() == 1);
111 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
112 boost::alignment_of
<int>::value
));
113 BOOST_TEST(result
[0] == 0);
114 BOOST_TEST(result
[1] == 0);
115 BOOST_TEST(result
[2] == 0);
118 boost::local_shared_ptr
<const int[][2]> result
=
119 boost::make_local_shared
<const int[][2]>(2);
120 BOOST_TEST(result
.get() != 0);
121 BOOST_TEST(result
.local_use_count() == 1);
122 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
123 boost::alignment_of
<int>::value
));
124 BOOST_TEST(result
[0][0] == 0);
125 BOOST_TEST(result
[0][1] == 0);
126 BOOST_TEST(result
[1][0] == 0);
127 BOOST_TEST(result
[1][1] == 0);
130 boost::local_shared_ptr
<const int[2][2]> result
=
131 boost::make_local_shared
<const int[2][2]>();
132 BOOST_TEST(result
.get() != 0);
133 BOOST_TEST(result
.local_use_count() == 1);
134 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
135 boost::alignment_of
<int>::value
));
136 BOOST_TEST(result
[0][0] == 0);
137 BOOST_TEST(result
[0][1] == 0);
138 BOOST_TEST(result
[1][0] == 0);
139 BOOST_TEST(result
[1][1] == 0);
142 boost::local_shared_ptr
<type
[]> result
=
143 boost::make_local_shared
<type
[]>(3);
144 BOOST_TEST(result
.get() != 0);
145 BOOST_TEST(result
.local_use_count() == 1);
146 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
147 boost::alignment_of
<type
>::value
));
148 BOOST_TEST(type::instances
== 3);
149 boost::weak_ptr
<type
[]> w1
= result
;
151 BOOST_TEST(type::instances
== 0);
154 boost::local_shared_ptr
<type
[3]> result
=
155 boost::make_local_shared
<type
[3]>();
156 BOOST_TEST(result
.get() != 0);
157 BOOST_TEST(result
.local_use_count() == 1);
158 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
159 boost::alignment_of
<type
>::value
));
160 BOOST_TEST(type::instances
== 3);
161 boost::weak_ptr
<type
[3]> w1
= result
;
163 BOOST_TEST(type::instances
== 0);
166 boost::local_shared_ptr
<type
[][2]> result
=
167 boost::make_local_shared
<type
[][2]>(2);
168 BOOST_TEST(result
.get() != 0);
169 BOOST_TEST(result
.local_use_count() == 1);
170 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
171 boost::alignment_of
<type
>::value
));
172 BOOST_TEST(type::instances
== 4);
174 BOOST_TEST(type::instances
== 0);
177 boost::local_shared_ptr
<type
[2][2]> result
=
178 boost::make_local_shared
<type
[2][2]>();
179 BOOST_TEST(result
.get() != 0);
180 BOOST_TEST(result
.local_use_count() == 1);
181 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
182 boost::alignment_of
<type
>::value
));
183 BOOST_TEST(type::instances
== 4);
185 BOOST_TEST(type::instances
== 0);
188 boost::local_shared_ptr
<const type
[]> result
=
189 boost::make_local_shared
<const type
[]>(3);
190 BOOST_TEST(result
.get() != 0);
191 BOOST_TEST(result
.local_use_count() == 1);
192 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
193 boost::alignment_of
<type
>::value
));
194 BOOST_TEST(type::instances
== 3);
196 BOOST_TEST(type::instances
== 0);
199 boost::local_shared_ptr
<const type
[3]> result
=
200 boost::make_local_shared
<const type
[3]>();
201 BOOST_TEST(result
.get() != 0);
202 BOOST_TEST(result
.local_use_count() == 1);
203 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
204 boost::alignment_of
<type
>::value
));
205 BOOST_TEST(type::instances
== 3);
207 BOOST_TEST(type::instances
== 0);
210 boost::local_shared_ptr
<const type
[][2]> result
=
211 boost::make_local_shared
<const type
[][2]>(2);
212 BOOST_TEST(result
.get() != 0);
213 BOOST_TEST(result
.local_use_count() == 1);
214 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
215 boost::alignment_of
<type
>::value
));
216 BOOST_TEST(type::instances
== 4);
218 BOOST_TEST(type::instances
== 0);
221 boost::local_shared_ptr
<const type
[2][2]> result
=
222 boost::make_local_shared
<const type
[2][2]>();
223 BOOST_TEST(result
.get() != 0);
224 BOOST_TEST(result
.local_use_count() == 1);
225 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
226 boost::alignment_of
<type
>::value
));
227 BOOST_TEST(type::instances
== 4);
229 BOOST_TEST(type::instances
== 0);
231 return boost::report_errors();