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