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 | |
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 = boost::make_unique_noinit<int>(); |
36 | BOOST_TEST(result.get() != 0); |
37 | } |
38 | BOOST_TEST(type::instances == 0); |
39 | { |
40 | std::unique_ptr<type> result = |
41 | boost::make_unique_noinit<type>(); |
42 | BOOST_TEST(result.get() != 0); |
43 | BOOST_TEST(type::instances == 1); |
44 | result.reset(); |
45 | BOOST_TEST(type::instances == 0); |
46 | } |
47 | BOOST_TEST(type::instances == 0); |
48 | { |
49 | std::unique_ptr<const type> result = |
50 | boost::make_unique_noinit<const type>(); |
51 | BOOST_TEST(result.get() != 0); |
52 | BOOST_TEST(type::instances == 1); |
53 | result.reset(); |
54 | BOOST_TEST(type::instances == 0); |
55 | } |
56 | return boost::report_errors(); |
57 | } |
58 | #else |
59 | int main() |
60 | { |
61 | return 0; |
62 | } |
63 | #endif |
64 |