]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_construct_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / smart_ptr / test / allocate_shared_array_construct_test.cpp
1 /*
2 (c) 2012-2015 Glen Joseph Fernandes
3 <glenjofe -at- gmail.com>
4
5 Distributed under the Boost Software
6 License, Version 1.0.
7 http://boost.org/LICENSE_1_0.txt
8 */
9 #include <boost/core/lightweight_test.hpp>
10 #include <boost/smart_ptr/make_shared.hpp>
11
12 struct tag { };
13
14 template<typename T>
15 class creator {
16 public:
17 typedef T value_type;
18 creator() {
19 }
20 template<typename U>
21 creator(const creator<U>&) {
22 }
23 T* allocate(std::size_t size) {
24 void* p = ::operator new(size * sizeof(T));
25 return static_cast<T*>(p);
26 }
27 void deallocate(T* memory, std::size_t) {
28 void* p = memory;
29 ::operator delete(p);
30 }
31 template<typename U>
32 void construct(U* memory) {
33 void* p = memory;
34 ::new(p) U(tag());
35 }
36 template<typename U>
37 void destroy(U* memory) {
38 memory->~U();
39 }
40 };
41
42 class type {
43 public:
44 static unsigned int instances;
45 explicit type(tag) {
46 instances++;
47 }
48 type(const type&) {
49 instances++;
50 }
51 ~type() {
52 instances--;
53 }
54 };
55
56 unsigned int type::instances = 0;
57
58 int main()
59 {
60 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
61 {
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);
66 a1.reset();
67 BOOST_TEST(type::instances == 0);
68 }
69 {
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);
74 a1.reset();
75 BOOST_TEST(type::instances == 0);
76 }
77 {
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);
82 a1.reset();
83 BOOST_TEST(type::instances == 0);
84 }
85 {
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);
90 a1.reset();
91 BOOST_TEST(type::instances == 0);
92 }
93 {
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);
98 a1.reset();
99 BOOST_TEST(type::instances == 0);
100 }
101 {
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);
106 a1.reset();
107 BOOST_TEST(type::instances == 0);
108 }
109 {
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);
114 a1.reset();
115 BOOST_TEST(type::instances == 0);
116 }
117 {
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);
122 a1.reset();
123 BOOST_TEST(type::instances == 0);
124 }
125 #endif
126 return boost::report_errors();
127 }