• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright 2014 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_SMART_PTR)
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/smart_ptr/make_unique.hpp>
12 
13 class type {
14 public:
15     static unsigned instances;
16 
type()17     type() {
18         ++instances;
19     }
20 
~type()21     ~type() {
22         --instances;
23     }
24 
25 private:
26     type(const type&);
27     type& operator=(const type&);
28 };
29 
30 unsigned type::instances = 0;
31 
main()32 int main()
33 {
34     {
35         std::unique_ptr<int[]> result = boost::make_unique<int[]>(3);
36         BOOST_TEST(result.get() != 0);
37         BOOST_TEST(result[0] == 0);
38         BOOST_TEST(result[1] == 0);
39         BOOST_TEST(result[2] == 0);
40     }
41     {
42         std::unique_ptr<int[][2]> result =
43             boost::make_unique<int[][2]>(2);
44         BOOST_TEST(result.get() != 0);
45         BOOST_TEST(result[0][0] == 0);
46         BOOST_TEST(result[0][1] == 0);
47         BOOST_TEST(result[1][0] == 0);
48         BOOST_TEST(result[1][1] == 0);
49     }
50     {
51         std::unique_ptr<const int[]> result =
52             boost::make_unique<const int[]>(3);
53         BOOST_TEST(result.get() != 0);
54         BOOST_TEST(result[0] == 0);
55         BOOST_TEST(result[1] == 0);
56         BOOST_TEST(result[2] == 0);
57     }
58     {
59         std::unique_ptr<const int[][2]> result =
60             boost::make_unique<const int[][2]>(2);
61         BOOST_TEST(result.get() != 0);
62         BOOST_TEST(result[0][0] == 0);
63         BOOST_TEST(result[0][1] == 0);
64         BOOST_TEST(result[1][0] == 0);
65         BOOST_TEST(result[1][1] == 0);
66     }
67     BOOST_TEST(type::instances == 0);
68     {
69         std::unique_ptr<type[]> result =
70             boost::make_unique<type[]>(3);
71         BOOST_TEST(result.get() != 0);
72         BOOST_TEST(type::instances == 3);
73         result.reset();
74         BOOST_TEST(type::instances == 0);
75     }
76     BOOST_TEST(type::instances == 0);
77     {
78         std::unique_ptr<type[][2]> result =
79             boost::make_unique<type[][2]>(2);
80         BOOST_TEST(result.get() != 0);
81         BOOST_TEST(type::instances == 4);
82         result.reset();
83         BOOST_TEST(type::instances == 0);
84     }
85     BOOST_TEST(type::instances == 0);
86     {
87         std::unique_ptr<const type[]> result =
88             boost::make_unique<const type[]>(3);
89         BOOST_TEST(result.get() != 0);
90         BOOST_TEST(type::instances == 3);
91         result.reset();
92         BOOST_TEST(type::instances == 0);
93     }
94     BOOST_TEST(type::instances == 0);
95     {
96         std::unique_ptr<const type[][2]> result =
97             boost::make_unique<const type[][2]>(2);
98         BOOST_TEST(result.get() != 0);
99         BOOST_TEST(type::instances == 4);
100         result.reset();
101         BOOST_TEST(type::instances == 0);
102     }
103     return boost::report_errors();
104 }
105 #else
main()106 int main()
107 {
108     return 0;
109 }
110 #endif
111