]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | /* |
b32b8144 FG |
2 | Copyright 2012-2015 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/core/lightweight_test.hpp> | |
9 | #include <boost/smart_ptr/enable_shared_from_this.hpp> | |
10 | #include <boost/smart_ptr/make_shared.hpp> | |
11 | ||
12 | class type | |
13 | : public boost::enable_shared_from_this<type> { | |
14 | public: | |
b32b8144 FG |
15 | static unsigned instances; |
16 | ||
17 | type() { | |
18 | ++instances; | |
7c673cae | 19 | } |
b32b8144 | 20 | |
7c673cae | 21 | ~type() { |
b32b8144 | 22 | --instances; |
7c673cae | 23 | } |
b32b8144 | 24 | |
7c673cae FG |
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 | BOOST_TEST(type::instances == 0); | |
35 | { | |
b32b8144 FG |
36 | boost::shared_ptr<type[]> result = |
37 | boost::make_shared<type[]>(3); | |
7c673cae | 38 | try { |
b32b8144 | 39 | result[0].shared_from_this(); |
7c673cae FG |
40 | BOOST_ERROR("shared_from_this did not throw"); |
41 | } catch (...) { | |
42 | BOOST_TEST(type::instances == 3); | |
43 | } | |
44 | } | |
45 | BOOST_TEST(type::instances == 0); | |
46 | { | |
b32b8144 FG |
47 | boost::shared_ptr<type[3]> result = |
48 | boost::make_shared_noinit<type[3]>(); | |
7c673cae | 49 | try { |
b32b8144 | 50 | result[0].shared_from_this(); |
7c673cae FG |
51 | BOOST_ERROR("shared_from_this did not throw"); |
52 | } catch (...) { | |
53 | BOOST_TEST(type::instances == 3); | |
54 | } | |
55 | } | |
56 | return boost::report_errors(); | |
57 | } |