2 Copyright 2017 Glen Joseph Fernandes
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
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>
15 template<class T
= void>
21 typedef creator
<U
> other
;
27 creator(const creator
<U
>&) { }
29 T
* allocate(std::size_t size
) {
30 return static_cast<T
*>(::operator new(sizeof(T
) * size
));
33 void deallocate(T
* ptr
, std::size_t) {
34 ::operator delete(ptr
);
38 template<class T
, class U
>
40 operator==(const creator
<T
>&, const creator
<U
>&)
45 template<class T
, class U
>
47 operator!=(const creator
<T
>&, const creator
<U
>&)
53 : public boost::enable_shared_from_this
<type
> {
55 static unsigned instances
;
67 type
& operator=(const type
&);
70 unsigned type::instances
= 0;
74 BOOST_TEST(type::instances
== 0);
76 boost::local_shared_ptr
<type
[]> result
=
77 boost::allocate_local_shared
<type
[]>(creator
<type
>(), 3);
79 result
[0].shared_from_this();
80 BOOST_ERROR("shared_from_this did not throw");
82 BOOST_TEST(type::instances
== 3);
85 BOOST_TEST(type::instances
== 0);
87 boost::local_shared_ptr
<type
[]> result
=
88 boost::allocate_local_shared_noinit
<type
[]>(creator
<>(), 3);
90 result
[0].shared_from_this();
91 BOOST_ERROR("shared_from_this did not throw");
93 BOOST_TEST(type::instances
== 3);
96 return boost::report_errors();