• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright 2017 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4 
5 Distributed 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 
17 class type {
18 public:
19     static unsigned instances;
20 
type()21     type()
22         : value_(0.0) {
23         ++instances;
24     }
25 
~type()26     ~type() {
27         --instances;
28     }
29 
set(long double value)30     void set(long double value) {
31         value_ = value;
32     }
33 
get() const34     long double get() const {
35         return value_;
36     }
37 
38 private:
39     type(const type&);
40     type& operator=(const type&);
41 
42     long double value_;
43 };
44 
45 unsigned type::instances = 0;
46 
main()47 int main()
48 {
49     {
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);
59     }
60     {
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);
70     }
71     {
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);
82     }
83     {
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);
94     }
95     {
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);
105     }
106     {
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);
116     }
117     {
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);
128     }
129     {
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);
140     }
141     {
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;
150         result.reset();
151         BOOST_TEST(type::instances == 0);
152     }
153     {
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;
162         result.reset();
163         BOOST_TEST(type::instances == 0);
164     }
165     {
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);
173         result.reset();
174         BOOST_TEST(type::instances == 0);
175     }
176     {
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);
184         result.reset();
185         BOOST_TEST(type::instances == 0);
186     }
187     {
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);
195         result.reset();
196         BOOST_TEST(type::instances == 0);
197     }
198     {
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);
206         result.reset();
207         BOOST_TEST(type::instances == 0);
208     }
209     {
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);
217         result.reset();
218         BOOST_TEST(type::instances == 0);
219     }
220     {
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);
228         result.reset();
229         BOOST_TEST(type::instances == 0);
230     }
231     return boost::report_errors();
232 }
233 #else
main()234 int main()
235 {
236     return 0;
237 }
238 #endif
239