]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_local_shared_array_construct_test.cpp
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 !defined(BOOST_NO_CXX11_ALLOCATOR)
12 #include <boost/core/lightweight_test.hpp>
13 #include <boost/smart_ptr/make_local_shared.hpp>
17 template<class T
= void>
23 typedef creator
<U
> other
;
29 creator(const creator
<U
>&) { }
31 T
* allocate(std::size_t size
) {
32 return static_cast<T
*>(::operator new(sizeof(T
) * size
));
35 void deallocate(T
* ptr
, std::size_t) {
36 ::operator delete(ptr
);
40 void construct(U
* ptr
) {
41 ::new(static_cast<void*>(ptr
)) U(allow());
45 void destroy(U
* ptr
) {
51 template<class T
, class U
>
53 operator==(const creator
<T
>&, const creator
<U
>&)
58 template<class T
, class U
>
60 operator!=(const creator
<T
>&, const creator
<U
>&)
67 static unsigned instances
;
69 explicit type(allow
) {
79 type
& operator=(const type
&);
82 unsigned type::instances
= 0;
87 boost::local_shared_ptr
<type
[]> result
=
88 boost::allocate_local_shared
<type
[]>(creator
<type
>(), 3);
89 BOOST_TEST(result
.get() != 0);
90 BOOST_TEST(result
.local_use_count() == 1);
91 BOOST_TEST(type::instances
== 3);
93 BOOST_TEST(type::instances
== 0);
96 boost::local_shared_ptr
<type
[3]> result
=
97 boost::allocate_local_shared
<type
[3]>(creator
<type
>());
98 BOOST_TEST(result
.get() != 0);
99 BOOST_TEST(result
.local_use_count() == 1);
100 BOOST_TEST(type::instances
== 3);
102 BOOST_TEST(type::instances
== 0);
105 boost::local_shared_ptr
<type
[][2]> result
=
106 boost::allocate_local_shared
<type
[][2]>(creator
<>(), 2);
107 BOOST_TEST(result
.get() != 0);
108 BOOST_TEST(result
.local_use_count() == 1);
109 BOOST_TEST(type::instances
== 4);
111 BOOST_TEST(type::instances
== 0);
114 boost::local_shared_ptr
<type
[2][2]> result
=
115 boost::allocate_local_shared
<type
[2][2]>(creator
<>());
116 BOOST_TEST(result
.get() != 0);
117 BOOST_TEST(result
.local_use_count() == 1);
118 BOOST_TEST(type::instances
== 4);
120 BOOST_TEST(type::instances
== 0);
123 boost::local_shared_ptr
<const type
[]> result
=
124 boost::allocate_local_shared
<const type
[]>(creator
<>(), 3);
125 BOOST_TEST(result
.get() != 0);
126 BOOST_TEST(result
.local_use_count() == 1);
127 BOOST_TEST(type::instances
== 3);
129 BOOST_TEST(type::instances
== 0);
132 boost::local_shared_ptr
<const type
[3]> result
=
133 boost::allocate_local_shared
<const type
[3]>(creator
<>());
134 BOOST_TEST(result
.get() != 0);
135 BOOST_TEST(result
.local_use_count() == 1);
136 BOOST_TEST(type::instances
== 3);
138 BOOST_TEST(type::instances
== 0);
141 boost::local_shared_ptr
<const type
[][2]> result
=
142 boost::allocate_local_shared
<const type
[][2]>(creator
<>(), 2);
143 BOOST_TEST(result
.get() != 0);
144 BOOST_TEST(result
.local_use_count() == 1);
145 BOOST_TEST(type::instances
== 4);
147 BOOST_TEST(type::instances
== 0);
150 boost::local_shared_ptr
<const type
[2][2]> result
=
151 boost::allocate_local_shared
<const type
[2][2]>(creator
<>());
152 BOOST_TEST(result
.get() != 0);
153 BOOST_TEST(result
.local_use_count() == 1);
154 BOOST_TEST(type::instances
== 4);
156 BOOST_TEST(type::instances
== 0);
158 return boost::report_errors();