1 /*
2  * Copyright (c) 2014 Glen Joseph Fernandes
3  * glenfe at live dot com
4  *
5  * Distributed under the Boost Software License,
6  * Version 1.0. (See accompanying file LICENSE_1_0.txt
7  * or copy at 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_array.hpp>
13 
14 class type {
15 public:
16     static unsigned int instances;
17 
type()18     explicit type() {
19         instances++;
20     }
21 
~type()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 
main()33 int main() {
34     {
35         std::unique_ptr<int[]> a1 = boost::make_unique<int[]>(3);
36         BOOST_TEST(a1.get() != 0);
37         BOOST_TEST(a1[0] == 0);
38         BOOST_TEST(a1[1] == 0);
39         BOOST_TEST(a1[2] == 0);
40     }
41 
42     {
43         std::unique_ptr<int[][2]> a1 = boost::make_unique<int[][2]>(2);
44         BOOST_TEST(a1.get() != 0);
45         BOOST_TEST(a1[0][0] == 0);
46         BOOST_TEST(a1[0][1] == 0);
47         BOOST_TEST(a1[1][0] == 0);
48         BOOST_TEST(a1[1][1] == 0);
49     }
50 
51     {
52         std::unique_ptr<const int[]> a1 = boost::make_unique<const int[]>(3);
53         BOOST_TEST(a1.get() != 0);
54         BOOST_TEST(a1[0] == 0);
55         BOOST_TEST(a1[1] == 0);
56         BOOST_TEST(a1[2] == 0);
57     }
58 
59     {
60         std::unique_ptr<const int[][2]> a1 = boost::make_unique<const int[][2]>(2);
61         BOOST_TEST(a1.get() != 0);
62         BOOST_TEST(a1[0][0] == 0);
63         BOOST_TEST(a1[0][1] == 0);
64         BOOST_TEST(a1[1][0] == 0);
65         BOOST_TEST(a1[1][1] == 0);
66     }
67 
68     BOOST_TEST(type::instances == 0);
69     {
70         std::unique_ptr<type[]> a1 = boost::make_unique<type[]>(3);
71         BOOST_TEST(a1.get() != 0);
72         BOOST_TEST(type::instances == 3);
73         a1.reset();
74         BOOST_TEST(type::instances == 0);
75     }
76 
77     BOOST_TEST(type::instances == 0);
78     {
79         std::unique_ptr<type[][2]> a1 = boost::make_unique<type[][2]>(2);
80         BOOST_TEST(a1.get() != 0);
81         BOOST_TEST(type::instances == 4);
82         a1.reset();
83         BOOST_TEST(type::instances == 0);
84     }
85 
86     BOOST_TEST(type::instances == 0);
87     {
88         std::unique_ptr<const type[]> a1 = boost::make_unique<const type[]>(3);
89         BOOST_TEST(a1.get() != 0);
90         BOOST_TEST(type::instances == 3);
91         a1.reset();
92         BOOST_TEST(type::instances == 0);
93     }
94 
95     BOOST_TEST(type::instances == 0);
96     {
97         std::unique_ptr<const type[][2]> a1 = boost::make_unique<const type[][2]>(2);
98         BOOST_TEST(a1.get() != 0);
99         BOOST_TEST(type::instances == 4);
100         a1.reset();
101         BOOST_TEST(type::instances == 0);
102     }
103 
104     return boost::report_errors();
105 }
106 #else
107 
main()108 int main() {
109     return 0;
110 }
111 
112 #endif
113