]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_local_shared_arrays_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / smart_ptr / test / allocate_local_shared_arrays_test.cpp
1 /*
2 Copyright 2017 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/config.hpp>
9 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
10 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
11 !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
12 #include <boost/core/lightweight_test.hpp>
13 #include <boost/smart_ptr/make_local_shared.hpp>
14
15 template<class T = void>
16 struct creator {
17 typedef T value_type;
18
19 template<class U>
20 struct rebind {
21 typedef creator<U> other;
22 };
23
24 creator() { }
25
26 template<class U>
27 creator(const creator<U>&) { }
28
29 T* allocate(std::size_t size) {
30 return static_cast<T*>(::operator new(sizeof(T) * size));
31 }
32
33 void deallocate(T* ptr, std::size_t) {
34 ::operator delete(ptr);
35 }
36 };
37
38 template<class T, class U>
39 inline bool
40 operator==(const creator<T>&, const creator<U>&)
41 {
42 return true;
43 }
44
45 template<class T, class U>
46 inline bool
47 operator!=(const creator<T>&, const creator<U>&)
48 {
49 return false;
50 }
51
52 int main()
53 {
54 {
55 boost::local_shared_ptr<int[][2]> result =
56 boost::allocate_local_shared<int[][2]>(creator<int>(), 2, {0, 1});
57 BOOST_TEST(result[0][0] == 0);
58 BOOST_TEST(result[0][1] == 1);
59 BOOST_TEST(result[1][0] == 0);
60 BOOST_TEST(result[1][1] == 1);
61 }
62 {
63 boost::local_shared_ptr<int[2][2]> result =
64 boost::allocate_local_shared<int[2][2]>(creator<int>(), {0, 1});
65 BOOST_TEST(result[0][0] == 0);
66 BOOST_TEST(result[0][1] == 1);
67 BOOST_TEST(result[1][0] == 0);
68 BOOST_TEST(result[1][1] == 1);
69 }
70 {
71 boost::local_shared_ptr<const int[][2]> result =
72 boost::allocate_local_shared<const int[][2]>(creator<>(), 2, {0, 1});
73 BOOST_TEST(result[0][0] == 0);
74 BOOST_TEST(result[0][1] == 1);
75 BOOST_TEST(result[1][0] == 0);
76 BOOST_TEST(result[1][1] == 1);
77 }
78 {
79 boost::local_shared_ptr<const int[2][2]> result =
80 boost::allocate_local_shared<const int[2][2]>(creator<>(), {0, 1});
81 BOOST_TEST(result[0][0] == 0);
82 BOOST_TEST(result[0][1] == 1);
83 BOOST_TEST(result[1][0] == 0);
84 BOOST_TEST(result[1][1] == 1);
85 }
86 return boost::report_errors();
87 }
88 #else
89 int main()
90 {
91 return 0;
92 }
93 #endif