1/*
2Copyright 2017 Glen Joseph Fernandes
3(glenjofe@gmail.com)
4
5Distributed 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_RVALUE_REFERENCES) && \
10 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
11#include <boost/core/lightweight_test.hpp>
12#include <boost/smart_ptr/enable_shared_from_this.hpp>
13#include <boost/smart_ptr/make_local_shared.hpp>
14
15class type
16 : public boost::enable_shared_from_this<type> {
17public:
18 static unsigned instances;
19
20 type() {
21 ++instances;
22 }
23
24 ~type() {
25 --instances;
26 }
27
28private:
29 type(const type&);
30 type& operator=(const type&);
31};
32
33unsigned type::instances = 0;
34
35int main()
36{
37 BOOST_TEST(type::instances == 0);
38 {
39 boost::local_shared_ptr<type[]> result =
40 boost::make_local_shared<type[]>(size: 3);
41 try {
42 result[0].shared_from_this();
43 BOOST_ERROR("shared_from_this did not throw");
44 } catch (...) {
45 BOOST_TEST(type::instances == 3);
46 }
47 }
48 BOOST_TEST(type::instances == 0);
49 {
50 boost::local_shared_ptr<type[3]> result =
51 boost::make_local_shared_noinit<type[3]>();
52 try {
53 result[0].shared_from_this();
54 BOOST_ERROR("shared_from_this did not throw");
55 } catch (...) {
56 BOOST_TEST(type::instances == 3);
57 }
58 }
59 return boost::report_errors();
60}
61#else
62int main()
63{
64 return 0;
65}
66#endif
67

source code of boost/libs/smart_ptr/test/make_local_shared_array_esft_test.cpp