]>
Commit | Line | Data |
---|---|---|
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/detail/lightweight_test.hpp> | |
11 | #include <boost/smart_ptr/make_unique.hpp> | |
12 | ||
13 | class type { | |
14 | public: | |
15 | static unsigned instances; | |
16 | ||
17 | type() { | |
18 | ++instances; | |
19 | } | |
20 | ||
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 | ||
32 | int main() | |
33 | { | |
34 | { | |
35 | std::unique_ptr<int[]> result = | |
36 | boost::make_unique_noinit<int[]>(3); | |
37 | BOOST_TEST(result.get() != 0); | |
38 | } | |
39 | { | |
40 | std::unique_ptr<int[][2]> result = | |
41 | boost::make_unique_noinit<int[][2]>(2); | |
42 | BOOST_TEST(result.get() != 0); | |
43 | } | |
44 | BOOST_TEST(type::instances == 0); | |
45 | { | |
46 | std::unique_ptr<type[]> result = | |
47 | boost::make_unique_noinit<type[]>(3); | |
48 | BOOST_TEST(result.get() != 0); | |
49 | BOOST_TEST(type::instances == 3); | |
50 | result.reset(); | |
51 | BOOST_TEST(type::instances == 0); | |
52 | } | |
53 | BOOST_TEST(type::instances == 0); | |
54 | { | |
55 | std::unique_ptr<type[][2]> result = | |
56 | boost::make_unique_noinit<type[][2]>(2); | |
57 | BOOST_TEST(result.get() != 0); | |
58 | BOOST_TEST(type::instances == 4); | |
59 | result.reset(); | |
60 | BOOST_TEST(type::instances == 0); | |
61 | } | |
62 | BOOST_TEST(type::instances == 0); | |
63 | { | |
64 | std::unique_ptr<const type[]> result = | |
65 | boost::make_unique_noinit<const type[]>(3); | |
66 | BOOST_TEST(result.get() != 0); | |
67 | BOOST_TEST(type::instances == 3); | |
68 | result.reset(); | |
69 | BOOST_TEST(type::instances == 0); | |
70 | } | |
71 | BOOST_TEST(type::instances == 0); | |
72 | { | |
73 | std::unique_ptr<const type[][2]> result = | |
74 | boost::make_unique_noinit<const type[][2]>(2); | |
75 | BOOST_TEST(result.get() != 0); | |
76 | BOOST_TEST(type::instances == 4); | |
77 | result.reset(); | |
78 | BOOST_TEST(type::instances == 0); | |
79 | } | |
80 | return boost::report_errors(); | |
81 | } | |
82 | #else | |
83 | int main() | |
84 | { | |
85 | return 0; | |
86 | } | |
87 | #endif |