]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | (c) 2014 Glen Joseph Fernandes | |
3 | <glenjofe -at- gmail.com> | |
4 | ||
5 | Distributed under the Boost Software | |
6 | License, Version 1.0. | |
7 | http://boost.org/LICENSE_1_0.txt | |
8 | */ | |
9 | #include <boost/config.hpp> | |
10 | #if !defined(BOOST_NO_CXX11_SMART_PTR) | |
11 | #include <boost/detail/lightweight_test.hpp> | |
12 | #include <boost/smart_ptr/make_unique.hpp> | |
13 | ||
14 | class type { | |
15 | public: | |
16 | static unsigned int instances; | |
17 | ||
18 | explicit type() { | |
19 | instances++; | |
20 | } | |
21 | ||
22 | ~type() { | |
23 | instances--; | |
24 | } | |
25 | ||
26 | private: | |
27 | type(const type&); | |
28 | type& operator=(const type&); | |
29 | }; | |
30 | ||
31 | unsigned int type::instances = 0; | |
32 | ||
33 | int main() | |
34 | { | |
35 | { | |
36 | std::unique_ptr<int[]> a1 = boost::make_unique<int[]>(3); | |
37 | BOOST_TEST(a1.get() != 0); | |
38 | BOOST_TEST(a1[0] == 0); | |
39 | BOOST_TEST(a1[1] == 0); | |
40 | BOOST_TEST(a1[2] == 0); | |
41 | } | |
42 | ||
43 | { | |
44 | std::unique_ptr<int[][2]> a1 = boost::make_unique<int[][2]>(2); | |
45 | BOOST_TEST(a1.get() != 0); | |
46 | BOOST_TEST(a1[0][0] == 0); | |
47 | BOOST_TEST(a1[0][1] == 0); | |
48 | BOOST_TEST(a1[1][0] == 0); | |
49 | BOOST_TEST(a1[1][1] == 0); | |
50 | } | |
51 | ||
52 | { | |
53 | std::unique_ptr<const int[]> a1 = boost::make_unique<const int[]>(3); | |
54 | BOOST_TEST(a1.get() != 0); | |
55 | BOOST_TEST(a1[0] == 0); | |
56 | BOOST_TEST(a1[1] == 0); | |
57 | BOOST_TEST(a1[2] == 0); | |
58 | } | |
59 | ||
60 | { | |
61 | std::unique_ptr<const int[][2]> a1 = boost::make_unique<const int[][2]>(2); | |
62 | BOOST_TEST(a1.get() != 0); | |
63 | BOOST_TEST(a1[0][0] == 0); | |
64 | BOOST_TEST(a1[0][1] == 0); | |
65 | BOOST_TEST(a1[1][0] == 0); | |
66 | BOOST_TEST(a1[1][1] == 0); | |
67 | } | |
68 | ||
69 | BOOST_TEST(type::instances == 0); | |
70 | { | |
71 | std::unique_ptr<type[]> a1 = boost::make_unique<type[]>(3); | |
72 | BOOST_TEST(a1.get() != 0); | |
73 | BOOST_TEST(type::instances == 3); | |
74 | a1.reset(); | |
75 | BOOST_TEST(type::instances == 0); | |
76 | } | |
77 | ||
78 | BOOST_TEST(type::instances == 0); | |
79 | { | |
80 | std::unique_ptr<type[][2]> a1 = boost::make_unique<type[][2]>(2); | |
81 | BOOST_TEST(a1.get() != 0); | |
82 | BOOST_TEST(type::instances == 4); | |
83 | a1.reset(); | |
84 | BOOST_TEST(type::instances == 0); | |
85 | } | |
86 | ||
87 | BOOST_TEST(type::instances == 0); | |
88 | { | |
89 | std::unique_ptr<const type[]> a1 = boost::make_unique<const type[]>(3); | |
90 | BOOST_TEST(a1.get() != 0); | |
91 | BOOST_TEST(type::instances == 3); | |
92 | a1.reset(); | |
93 | BOOST_TEST(type::instances == 0); | |
94 | } | |
95 | ||
96 | BOOST_TEST(type::instances == 0); | |
97 | { | |
98 | std::unique_ptr<const type[][2]> a1 = boost::make_unique<const type[][2]>(2); | |
99 | BOOST_TEST(a1.get() != 0); | |
100 | BOOST_TEST(type::instances == 4); | |
101 | a1.reset(); | |
102 | BOOST_TEST(type::instances == 0); | |
103 | } | |
104 | ||
105 | return boost::report_errors(); | |
106 | } | |
107 | #else | |
108 | ||
109 | int main() | |
110 | { | |
111 | return 0; | |
112 | } | |
113 | ||
114 | #endif |