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/core/lightweight_test.hpp>
9#include <boost/smart_ptr/make_shared.hpp>
10
11template<class T = void>
12struct 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
34template<class T, class U>
35inline bool
36operator==(const creator<T>&, const creator<U>&)
37{
38 return true;
39}
40
41template<class T, class U>
42inline bool
43operator!=(const creator<T>&, const creator<U>&)
44{
45 return false;
46}
47
48int main()
49{
50 {
51 boost::shared_ptr<int[]> result =
52 boost::allocate_shared<int[]>(allocator: creator<int>(), count: 4, value: 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);
57 }
58 {
59 boost::shared_ptr<int[4]> result =
60 boost::allocate_shared<int[4]>(allocator: creator<int>(), value: 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);
65 }
66 {
67 boost::shared_ptr<const int[]> result =
68 boost::allocate_shared<const int[]>(allocator: creator<>(), count: 4, value: 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);
73 }
74 {
75 boost::shared_ptr<const int[4]> result =
76 boost::allocate_shared<const int[4]>(allocator: creator<>(), value: 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);
81 }
82 return boost::report_errors();
83}
84

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