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

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