]>
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 FG |
7 | */ |
8 | #include <boost/core/lightweight_test.hpp> | |
9 | #include <boost/smart_ptr/make_shared.hpp> | |
10 | ||
b32b8144 FG |
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 | ||
7c673cae FG |
48 | int main() |
49 | { | |
50 | { | |
b32b8144 FG |
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); | |
7c673cae FG |
57 | } |
58 | { | |
b32b8144 FG |
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); | |
7c673cae FG |
65 | } |
66 | { | |
b32b8144 FG |
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); | |
7c673cae FG |
73 | } |
74 | { | |
b32b8144 FG |
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); | |
7c673cae FG |
81 | } |
82 | return boost::report_errors(); | |
83 | } |