]>
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) | |
10 | #include <boost/detail/lightweight_test.hpp> | |
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 = boost::make_unique<int>(); |
36 | BOOST_TEST(result.get() != 0); | |
37 | BOOST_TEST(*result == 0); | |
7c673cae | 38 | } |
7c673cae | 39 | { |
b32b8144 FG |
40 | std::unique_ptr<const int> result = |
41 | boost::make_unique<const int>(); | |
42 | BOOST_TEST(result.get() != 0); | |
43 | BOOST_TEST(*result == 0); | |
7c673cae | 44 | } |
7c673cae FG |
45 | BOOST_TEST(type::instances == 0); |
46 | { | |
b32b8144 FG |
47 | std::unique_ptr<type> result = |
48 | boost::make_unique<type>(); | |
49 | BOOST_TEST(result.get() != 0); | |
7c673cae | 50 | BOOST_TEST(type::instances == 1); |
b32b8144 | 51 | result.reset(); |
7c673cae FG |
52 | BOOST_TEST(type::instances == 0); |
53 | } | |
7c673cae FG |
54 | BOOST_TEST(type::instances == 0); |
55 | { | |
b32b8144 FG |
56 | std::unique_ptr<const type> result = |
57 | boost::make_unique<const type>(); | |
58 | BOOST_TEST(result.get() != 0); | |
7c673cae | 59 | BOOST_TEST(type::instances == 1); |
b32b8144 | 60 | result.reset(); |
7c673cae FG |
61 | BOOST_TEST(type::instances == 0); |
62 | } | |
7c673cae FG |
63 | return boost::report_errors(); |
64 | } | |
65 | #else | |
7c673cae FG |
66 | int main() |
67 | { | |
68 | return 0; | |
69 | } | |
7c673cae | 70 | #endif |