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