1/*
2Copyright 2012-2015 Glen Joseph Fernandes
3(glenjofe@gmail.com)
4
5Distributed 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
13template<class T = void>
14struct 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
36template<class T, class U>
37inline bool
38operator==(const creator<T>&, const creator<U>&)
39{
40 return true;
41}
42
43template<class T, class U>
44inline bool
45operator!=(const creator<T>&, const creator<U>&)
46{
47 return false;
48}
49
50int main()
51{
52 {
53 boost::shared_ptr<int[][2]> result =
54 boost::allocate_shared<int[][2]>(allocator: creator<int>(), count: 2, value: {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]>(allocator: creator<int>(), value: {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]>(allocator: creator<>(), count: 2, value: {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]>(allocator: creator<>(), value: {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
87int main()
88{
89 return 0;
90}
91#endif
92

source code of boost/libs/smart_ptr/test/allocate_shared_arrays_test.cpp