1/*
2Copyright 2017 Glen Joseph Fernandes
3(glenjofe@gmail.com)
4
5Distributed under the Boost Software License, Version 1.0.
6(http://www.boost.org/LICENSE_1_0.txt)
7*/
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>
16
17class type {
18public:
19 static unsigned instances;
20
21 type()
22 : value_(0.0) {
23 ++instances;
24 }
25
26 ~type() {
27 --instances;
28 }
29
30 void set(long double value) {
31 value_ = value;
32 }
33
34 long double get() const {
35 return value_;
36 }
37
38private:
39 type(const type&);
40 type& operator=(const type&);
41
42 long double value_;
43};
44
45unsigned type::instances = 0;
46
47int main()
48{
49 {
50 boost::local_shared_ptr<int[]> result =
51 boost::make_local_shared_noinit<int[]>(size: 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 }
57 {
58 boost::local_shared_ptr<int[3]> result =
59 boost::make_local_shared_noinit<int[3]>();
60 BOOST_TEST(result.get() != 0);
61 BOOST_TEST(result.local_use_count() == 1);
62 BOOST_TEST(boost::alignment::is_aligned(result.get(),
63 boost::alignment_of<int>::value));
64 }
65 {
66 boost::local_shared_ptr<int[][2]> result =
67 boost::make_local_shared_noinit<int[][2]>(size: 2);
68 BOOST_TEST(result.get() != 0);
69 BOOST_TEST(result.local_use_count() == 1);
70 BOOST_TEST(boost::alignment::is_aligned(result.get(),
71 boost::alignment_of<int>::value));
72 }
73 {
74 boost::local_shared_ptr<int[2][2]> result =
75 boost::make_local_shared_noinit<int[2][2]>();
76 BOOST_TEST(result.get() != 0);
77 BOOST_TEST(result.local_use_count() == 1);
78 BOOST_TEST(boost::alignment::is_aligned(result.get(),
79 boost::alignment_of<int>::value));
80 }
81 {
82 boost::local_shared_ptr<const int[]> result =
83 boost::make_local_shared_noinit<const int[]>(size: 3);
84 BOOST_TEST(result.get() != 0);
85 BOOST_TEST(result.local_use_count() == 1);
86 BOOST_TEST(boost::alignment::is_aligned(result.get(),
87 boost::alignment_of<int>::value));
88 }
89 {
90 boost::local_shared_ptr<const int[3]> result =
91 boost::make_local_shared_noinit<const int[3]>();
92 BOOST_TEST(result.get() != 0);
93 BOOST_TEST(result.local_use_count() == 1);
94 BOOST_TEST(boost::alignment::is_aligned(result.get(),
95 boost::alignment_of<int>::value));
96 }
97 {
98 boost::local_shared_ptr<const int[][2]> result =
99 boost::make_local_shared_noinit<const int[][2]>(size: 2);
100 BOOST_TEST(result.get() != 0);
101 BOOST_TEST(result.local_use_count() == 1);
102 BOOST_TEST(boost::alignment::is_aligned(result.get(),
103 boost::alignment_of<int>::value));
104 }
105 {
106 boost::local_shared_ptr<const int[2][2]> result =
107 boost::make_local_shared_noinit<const int[2][2]>();
108 BOOST_TEST(result.get() != 0);
109 BOOST_TEST(result.local_use_count() == 1);
110 BOOST_TEST(boost::alignment::is_aligned(result.get(),
111 boost::alignment_of<int>::value));
112 }
113 {
114 boost::local_shared_ptr<type[]> result =
115 boost::make_local_shared_noinit<type[]>(size: 3);
116 BOOST_TEST(result.get() != 0);
117 BOOST_TEST(result.local_use_count() == 1);
118 BOOST_TEST(boost::alignment::is_aligned(result.get(),
119 boost::alignment_of<type>::value));
120 BOOST_TEST(type::instances == 3);
121 boost::weak_ptr<type[]> other = result;
122 result.reset();
123 BOOST_TEST(type::instances == 0);
124 }
125 {
126 boost::local_shared_ptr<type[3]> result =
127 boost::make_local_shared_noinit<type[3]>();
128 BOOST_TEST(result.get() != 0);
129 BOOST_TEST(result.local_use_count() == 1);
130 BOOST_TEST(boost::alignment::is_aligned(result.get(),
131 boost::alignment_of<type>::value));
132 BOOST_TEST(type::instances == 3);
133 boost::weak_ptr<type[3]> other = result;
134 result.reset();
135 BOOST_TEST(type::instances == 0);
136 }
137 {
138 boost::local_shared_ptr<type[][2]> result =
139 boost::make_local_shared_noinit<type[][2]>(size: 2);
140 BOOST_TEST(result.get() != 0);
141 BOOST_TEST(result.local_use_count() == 1);
142 BOOST_TEST(boost::alignment::is_aligned(result.get(),
143 boost::alignment_of<type>::value));
144 BOOST_TEST(type::instances == 4);
145 boost::weak_ptr<type[][2]> other = result;
146 result.reset();
147 BOOST_TEST(type::instances == 0);
148 }
149 {
150 boost::local_shared_ptr<type[2][2]> result =
151 boost::make_local_shared_noinit<type[2][2]>();
152 BOOST_TEST(result.get() != 0);
153 BOOST_TEST(result.local_use_count() == 1);
154 BOOST_TEST(boost::alignment::is_aligned(result.get(),
155 boost::alignment_of<type>::value));
156 BOOST_TEST(type::instances == 4);
157 boost::weak_ptr<type[2][2]> other = result;
158 result.reset();
159 BOOST_TEST(type::instances == 0);
160 }
161 {
162 boost::local_shared_ptr<const type[]> result =
163 boost::make_local_shared_noinit<const type[]>(size: 3);
164 BOOST_TEST(result.get() != 0);
165 BOOST_TEST(result.local_use_count() == 1);
166 BOOST_TEST(boost::alignment::is_aligned(result.get(),
167 boost::alignment_of<type>::value));
168 BOOST_TEST(type::instances == 3);
169 boost::weak_ptr<const type[]> other = result;
170 result.reset();
171 BOOST_TEST(type::instances == 0);
172 }
173 {
174 boost::local_shared_ptr<const type[3]> result =
175 boost::make_local_shared_noinit<const type[3]>();
176 BOOST_TEST(result.get() != 0);
177 BOOST_TEST(result.local_use_count() == 1);
178 BOOST_TEST(boost::alignment::is_aligned(result.get(),
179 boost::alignment_of<type>::value));
180 BOOST_TEST(type::instances == 3);
181 boost::weak_ptr<const type[3]> other = result;
182 result.reset();
183 BOOST_TEST(type::instances == 0);
184 }
185 {
186 boost::local_shared_ptr<const type[][2]> result =
187 boost::make_local_shared_noinit<const type[][2]>(size: 2);
188 BOOST_TEST(result.get() != 0);
189 BOOST_TEST(result.local_use_count() == 1);
190 BOOST_TEST(boost::alignment::is_aligned(result.get(),
191 boost::alignment_of<type>::value));
192 BOOST_TEST(type::instances == 4);
193 boost::weak_ptr<const type[][2]> other = result;
194 result.reset();
195 BOOST_TEST(type::instances == 0);
196 }
197 {
198 boost::local_shared_ptr<const type[2][2]> result =
199 boost::make_local_shared_noinit<const type[2][2]>();
200 BOOST_TEST(result.get() != 0);
201 BOOST_TEST(result.local_use_count() == 1);
202 BOOST_TEST(boost::alignment::is_aligned(result.get(),
203 boost::alignment_of<type>::value));
204 BOOST_TEST(type::instances == 4);
205 boost::weak_ptr<const type[2][2]> other = result;
206 result.reset();
207 BOOST_TEST(type::instances == 0);
208 }
209 return boost::report_errors();
210}
211#else
212int main()
213{
214 return 0;
215}
216#endif
217

source code of boost/libs/smart_ptr/test/make_local_shared_array_noinit_test.cpp