]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_construct_test.cpp
2 (c) 2012-2015 Glen Joseph Fernandes
3 <glenjofe -at- gmail.com>
5 Distributed under the Boost Software
7 http://boost.org/LICENSE_1_0.txt
9 #include <boost/core/lightweight_test.hpp>
10 #include <boost/smart_ptr/make_shared.hpp>
21 creator(const creator
<U
>&) {
23 T
* allocate(std::size_t size
) {
24 void* p
= ::operator new(size
* sizeof(T
));
25 return static_cast<T
*>(p
);
27 void deallocate(T
* memory
, std::size_t) {
32 void construct(U
* memory
) {
37 void destroy(U
* memory
) {
44 static unsigned int instances
;
56 unsigned int type::instances
= 0;
60 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
62 boost::shared_ptr
<type
[]> a1
= boost::allocate_shared
<type
[]>(creator
<void>(), 3);
63 BOOST_TEST(a1
.use_count() == 1);
64 BOOST_TEST(a1
.get() != 0);
65 BOOST_TEST(type::instances
== 3);
67 BOOST_TEST(type::instances
== 0);
70 boost::shared_ptr
<type
[3]> a1
= boost::allocate_shared
<type
[3]>(creator
<void>());
71 BOOST_TEST(a1
.use_count() == 1);
72 BOOST_TEST(a1
.get() != 0);
73 BOOST_TEST(type::instances
== 3);
75 BOOST_TEST(type::instances
== 0);
78 boost::shared_ptr
<type
[][2]> a1
= boost::allocate_shared
<type
[][2]>(creator
<void>(), 2);
79 BOOST_TEST(a1
.get() != 0);
80 BOOST_TEST(a1
.use_count() == 1);
81 BOOST_TEST(type::instances
== 4);
83 BOOST_TEST(type::instances
== 0);
86 boost::shared_ptr
<type
[2][2]> a1
= boost::allocate_shared
<type
[2][2]>(creator
<void>());
87 BOOST_TEST(a1
.get() != 0);
88 BOOST_TEST(a1
.use_count() == 1);
89 BOOST_TEST(type::instances
== 4);
91 BOOST_TEST(type::instances
== 0);
94 boost::shared_ptr
<const type
[]> a1
= boost::allocate_shared
<const type
[]>(creator
<void>(), 3);
95 BOOST_TEST(a1
.get() != 0);
96 BOOST_TEST(a1
.use_count() == 1);
97 BOOST_TEST(type::instances
== 3);
99 BOOST_TEST(type::instances
== 0);
102 boost::shared_ptr
<const type
[3]> a1
= boost::allocate_shared
<const type
[3]>(creator
<void>());
103 BOOST_TEST(a1
.get() != 0);
104 BOOST_TEST(a1
.use_count() == 1);
105 BOOST_TEST(type::instances
== 3);
107 BOOST_TEST(type::instances
== 0);
110 boost::shared_ptr
<const type
[][2]> a1
= boost::allocate_shared
<const type
[][2]>(creator
<void>(), 2);
111 BOOST_TEST(a1
.get() != 0);
112 BOOST_TEST(a1
.use_count() == 1);
113 BOOST_TEST(type::instances
== 4);
115 BOOST_TEST(type::instances
== 0);
118 boost::shared_ptr
<const type
[2][2]> a1
= boost::allocate_shared
<const type
[2][2]>(creator
<void>());
119 BOOST_TEST(a1
.get() != 0);
120 BOOST_TEST(a1
.use_count() == 1);
121 BOOST_TEST(type::instances
== 4);
123 BOOST_TEST(type::instances
== 0);
126 return boost::report_errors();