]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_value_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / smart_ptr / test / allocate_shared_array_value_test.cpp
1 /*
2 Copyright 2012-2015 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #include <boost/core/lightweight_test.hpp>
9 #include <boost/smart_ptr/make_shared.hpp>
10
11 template<class T = void>
12 struct creator {
13 typedef T value_type;
14
15 template<class U>
16 struct rebind {
17 typedef creator<U> other;
18 };
19
20 creator() { }
21
22 template<class U>
23 creator(const creator<U>&) { }
24
25 T* allocate(std::size_t size) {
26 return static_cast<T*>(::operator new(sizeof(T) * size));
27 }
28
29 void deallocate(T* ptr, std::size_t) {
30 ::operator delete(ptr);
31 }
32 };
33
34 template<class T, class U>
35 inline bool
36 operator==(const creator<T>&, const creator<U>&)
37 {
38 return true;
39 }
40
41 template<class T, class U>
42 inline bool
43 operator!=(const creator<T>&, const creator<U>&)
44 {
45 return false;
46 }
47
48 int main()
49 {
50 {
51 boost::shared_ptr<int[]> result =
52 boost::allocate_shared<int[]>(creator<int>(), 4, 1);
53 BOOST_TEST(result[0] == 1);
54 BOOST_TEST(result[1] == 1);
55 BOOST_TEST(result[2] == 1);
56 BOOST_TEST(result[3] == 1);
57 }
58 {
59 boost::shared_ptr<int[4]> result =
60 boost::allocate_shared<int[4]>(creator<int>(), 1);
61 BOOST_TEST(result[0] == 1);
62 BOOST_TEST(result[1] == 1);
63 BOOST_TEST(result[2] == 1);
64 BOOST_TEST(result[3] == 1);
65 }
66 {
67 boost::shared_ptr<const int[]> result =
68 boost::allocate_shared<const int[]>(creator<>(), 4, 1);
69 BOOST_TEST(result[0] == 1);
70 BOOST_TEST(result[1] == 1);
71 BOOST_TEST(result[2] == 1);
72 BOOST_TEST(result[3] == 1);
73 }
74 {
75 boost::shared_ptr<const int[4]> result =
76 boost::allocate_shared<const int[4]>(creator<>(), 1);
77 BOOST_TEST(result[0] == 1);
78 BOOST_TEST(result[1] == 1);
79 BOOST_TEST(result[2] == 1);
80 BOOST_TEST(result[3] == 1);
81 }
82 return boost::report_errors();
83 }