]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/make_shared_array_noinit_test.cpp
2 Copyright 2012-2015 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/align/is_aligned.hpp>
9 #include <boost/core/lightweight_test.hpp>
10 #include <boost/smart_ptr/make_shared.hpp>
11 #include <boost/smart_ptr/weak_ptr.hpp>
12 #include <boost/type_traits/alignment_of.hpp>
16 static unsigned instances
;
27 void set(long double value
) {
31 long double get() const {
37 type
& operator=(const type
&);
42 unsigned type::instances
= 0;
47 boost::shared_ptr
<int[]> result
=
48 boost::make_shared_noinit
<int[]>(3);
49 BOOST_TEST(result
.get() != 0);
50 BOOST_TEST(result
.use_count() == 1);
51 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
52 boost::alignment_of
<int>::value
));
55 boost::shared_ptr
<int[3]> result
=
56 boost::make_shared_noinit
<int[3]>();
57 BOOST_TEST(result
.get() != 0);
58 BOOST_TEST(result
.use_count() == 1);
59 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
60 boost::alignment_of
<int>::value
));
63 boost::shared_ptr
<int[][2]> result
=
64 boost::make_shared_noinit
<int[][2]>(2);
65 BOOST_TEST(result
.get() != 0);
66 BOOST_TEST(result
.use_count() == 1);
67 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
68 boost::alignment_of
<int>::value
));
71 boost::shared_ptr
<int[2][2]> result
=
72 boost::make_shared_noinit
<int[2][2]>();
73 BOOST_TEST(result
.get() != 0);
74 BOOST_TEST(result
.use_count() == 1);
75 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
76 boost::alignment_of
<int>::value
));
79 boost::shared_ptr
<const int[]> result
=
80 boost::make_shared_noinit
<const int[]>(3);
81 BOOST_TEST(result
.get() != 0);
82 BOOST_TEST(result
.use_count() == 1);
83 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
84 boost::alignment_of
<int>::value
));
87 boost::shared_ptr
<const int[3]> result
=
88 boost::make_shared_noinit
<const int[3]>();
89 BOOST_TEST(result
.get() != 0);
90 BOOST_TEST(result
.use_count() == 1);
91 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
92 boost::alignment_of
<int>::value
));
95 boost::shared_ptr
<const int[][2]> result
=
96 boost::make_shared_noinit
<const int[][2]>(2);
97 BOOST_TEST(result
.get() != 0);
98 BOOST_TEST(result
.use_count() == 1);
99 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
100 boost::alignment_of
<int>::value
));
103 boost::shared_ptr
<const int[2][2]> result
=
104 boost::make_shared_noinit
<const int[2][2]>();
105 BOOST_TEST(result
.get() != 0);
106 BOOST_TEST(result
.use_count() == 1);
107 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
108 boost::alignment_of
<int>::value
));
111 boost::shared_ptr
<type
[]> result
=
112 boost::make_shared_noinit
<type
[]>(3);
113 BOOST_TEST(result
.get() != 0);
114 BOOST_TEST(result
.use_count() == 1);
115 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
116 boost::alignment_of
<type
>::value
));
117 BOOST_TEST(type::instances
== 3);
118 boost::weak_ptr
<type
[]> other
= result
;
120 BOOST_TEST(type::instances
== 0);
123 boost::shared_ptr
<type
[3]> result
=
124 boost::make_shared_noinit
<type
[3]>();
125 BOOST_TEST(result
.get() != 0);
126 BOOST_TEST(result
.use_count() == 1);
127 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
128 boost::alignment_of
<type
>::value
));
129 BOOST_TEST(type::instances
== 3);
130 boost::weak_ptr
<type
[3]> other
= result
;
132 BOOST_TEST(type::instances
== 0);
135 boost::shared_ptr
<type
[][2]> result
=
136 boost::make_shared_noinit
<type
[][2]>(2);
137 BOOST_TEST(result
.get() != 0);
138 BOOST_TEST(result
.use_count() == 1);
139 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
140 boost::alignment_of
<type
>::value
));
141 BOOST_TEST(type::instances
== 4);
142 boost::weak_ptr
<type
[][2]> other
= result
;
144 BOOST_TEST(type::instances
== 0);
147 boost::shared_ptr
<type
[2][2]> result
=
148 boost::make_shared_noinit
<type
[2][2]>();
149 BOOST_TEST(result
.get() != 0);
150 BOOST_TEST(result
.use_count() == 1);
151 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
152 boost::alignment_of
<type
>::value
));
153 BOOST_TEST(type::instances
== 4);
154 boost::weak_ptr
<type
[2][2]> other
= result
;
156 BOOST_TEST(type::instances
== 0);
159 boost::shared_ptr
<const type
[]> result
=
160 boost::make_shared_noinit
<const type
[]>(3);
161 BOOST_TEST(result
.get() != 0);
162 BOOST_TEST(result
.use_count() == 1);
163 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
164 boost::alignment_of
<type
>::value
));
165 BOOST_TEST(type::instances
== 3);
166 boost::weak_ptr
<const type
[]> other
= result
;
168 BOOST_TEST(type::instances
== 0);
171 boost::shared_ptr
<const type
[3]> result
=
172 boost::make_shared_noinit
<const type
[3]>();
173 BOOST_TEST(result
.get() != 0);
174 BOOST_TEST(result
.use_count() == 1);
175 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
176 boost::alignment_of
<type
>::value
));
177 BOOST_TEST(type::instances
== 3);
178 boost::weak_ptr
<const type
[3]> other
= result
;
180 BOOST_TEST(type::instances
== 0);
183 boost::shared_ptr
<const type
[][2]> result
=
184 boost::make_shared_noinit
<const type
[][2]>(2);
185 BOOST_TEST(result
.get() != 0);
186 BOOST_TEST(result
.use_count() == 1);
187 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
188 boost::alignment_of
<type
>::value
));
189 BOOST_TEST(type::instances
== 4);
190 boost::weak_ptr
<const type
[][2]> other
= result
;
192 BOOST_TEST(type::instances
== 0);
195 boost::shared_ptr
<const type
[2][2]> result
=
196 boost::make_shared_noinit
<const type
[2][2]>();
197 BOOST_TEST(result
.get() != 0);
198 BOOST_TEST(result
.use_count() == 1);
199 BOOST_TEST(boost::alignment::is_aligned(result
.get(),
200 boost::alignment_of
<type
>::value
));
201 BOOST_TEST(type::instances
== 4);
202 boost::weak_ptr
<const type
[2][2]> other
= result
;
204 BOOST_TEST(type::instances
== 0);
206 return boost::report_errors();