]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_construct_test.cpp
2 Copyright 2012-2015 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_ALLOCATOR)
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/smart_ptr/make_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 void construct(U
* ptr
) {
39 ::new(static_cast<void*>(ptr
)) U(allow());
43 void destroy(U
* ptr
) {
49 template<class T
, class U
>
51 operator==(const creator
<T
>&, const creator
<U
>&)
56 template<class T
, class U
>
58 operator!=(const creator
<T
>&, const creator
<U
>&)
65 static unsigned instances
;
67 explicit type(allow
) {
77 type
& operator=(const type
&);
80 unsigned type::instances
= 0;
85 boost::shared_ptr
<type
[]> result
=
86 boost::allocate_shared
<type
[]>(creator
<type
>(), 3);
87 BOOST_TEST(result
.get() != 0);
88 BOOST_TEST(result
.use_count() == 1);
89 BOOST_TEST(type::instances
== 3);
91 BOOST_TEST(type::instances
== 0);
94 boost::shared_ptr
<type
[3]> result
=
95 boost::allocate_shared
<type
[3]>(creator
<type
>());
96 BOOST_TEST(result
.get() != 0);
97 BOOST_TEST(result
.use_count() == 1);
98 BOOST_TEST(type::instances
== 3);
100 BOOST_TEST(type::instances
== 0);
103 boost::shared_ptr
<type
[][2]> result
=
104 boost::allocate_shared
<type
[][2]>(creator
<>(), 2);
105 BOOST_TEST(result
.get() != 0);
106 BOOST_TEST(result
.use_count() == 1);
107 BOOST_TEST(type::instances
== 4);
109 BOOST_TEST(type::instances
== 0);
112 boost::shared_ptr
<type
[2][2]> result
=
113 boost::allocate_shared
<type
[2][2]>(creator
<>());
114 BOOST_TEST(result
.get() != 0);
115 BOOST_TEST(result
.use_count() == 1);
116 BOOST_TEST(type::instances
== 4);
118 BOOST_TEST(type::instances
== 0);
121 boost::shared_ptr
<const type
[]> result
=
122 boost::allocate_shared
<const type
[]>(creator
<>(), 3);
123 BOOST_TEST(result
.get() != 0);
124 BOOST_TEST(result
.use_count() == 1);
125 BOOST_TEST(type::instances
== 3);
127 BOOST_TEST(type::instances
== 0);
130 boost::shared_ptr
<const type
[3]> result
=
131 boost::allocate_shared
<const type
[3]>(creator
<>());
132 BOOST_TEST(result
.get() != 0);
133 BOOST_TEST(result
.use_count() == 1);
134 BOOST_TEST(type::instances
== 3);
136 BOOST_TEST(type::instances
== 0);
139 boost::shared_ptr
<const type
[][2]> result
=
140 boost::allocate_shared
<const type
[][2]>(creator
<>(), 2);
141 BOOST_TEST(result
.get() != 0);
142 BOOST_TEST(result
.use_count() == 1);
143 BOOST_TEST(type::instances
== 4);
145 BOOST_TEST(type::instances
== 0);
148 boost::shared_ptr
<const type
[2][2]> result
=
149 boost::allocate_shared
<const type
[2][2]>(creator
<>());
150 BOOST_TEST(result
.get() != 0);
151 BOOST_TEST(result
.use_count() == 1);
152 BOOST_TEST(type::instances
== 4);
154 BOOST_TEST(type::instances
== 0);
156 return boost::report_errors();