]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | /* |
b32b8144 FG |
2 | Copyright 2012-2015 Glen Joseph Fernandes |
3 | (glenjofe@gmail.com) | |
7c673cae | 4 | |
b32b8144 FG |
5 | Distributed under the Boost Software License, Version 1.0. |
6 | (http://www.boost.org/LICENSE_1_0.txt) | |
7c673cae | 7 | */ |
b32b8144 FG |
8 | #include <boost/config.hpp> |
9 | #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) | |
7c673cae FG |
10 | #include <boost/core/lightweight_test.hpp> |
11 | #include <boost/smart_ptr/make_shared.hpp> | |
12 | ||
b32b8144 FG |
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 | ||
22 | creator() { } | |
23 | ||
24 | template<class U> | |
25 | creator(const creator<U>&) { } | |
26 | ||
27 | T* allocate(std::size_t size) { | |
28 | return static_cast<T*>(::operator new(sizeof(T) * size)); | |
29 | } | |
30 | ||
31 | void deallocate(T* ptr, std::size_t) { | |
32 | ::operator delete(ptr); | |
33 | } | |
34 | }; | |
35 | ||
36 | template<class T, class U> | |
37 | inline bool | |
38 | operator==(const creator<T>&, const creator<U>&) | |
39 | { | |
40 | return true; | |
41 | } | |
42 | ||
43 | template<class T, class U> | |
44 | inline bool | |
45 | operator!=(const creator<T>&, const creator<U>&) | |
46 | { | |
47 | return false; | |
48 | } | |
49 | ||
7c673cae FG |
50 | int main() |
51 | { | |
7c673cae | 52 | { |
b32b8144 FG |
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); | |
7c673cae FG |
59 | } |
60 | { | |
b32b8144 FG |
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); | |
7c673cae FG |
67 | } |
68 | { | |
b32b8144 FG |
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); | |
7c673cae FG |
75 | } |
76 | { | |
b32b8144 FG |
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); | |
7c673cae | 83 | } |
7c673cae FG |
84 | return boost::report_errors(); |
85 | } | |
b32b8144 FG |
86 | #else |
87 | int main() | |
88 | { | |
89 | return 0; | |
90 | } | |
91 | #endif |