1 /*
2 Copyright 2017 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4 
5 Distributed 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 
14 template<class T = void>
15 struct creator {
16     typedef T value_type;
17 
18     template<class U>
19     struct rebind {
20         typedef creator<U> other;
21     };
22 
creatorcreator23     creator() { }
24 
25     template<class U>
creatorcreator26     creator(const creator<U>&) { }
27 
allocatecreator28     T* allocate(std::size_t size) {
29         return static_cast<T*>(::operator new(sizeof(T) * size));
30     }
31 
deallocatecreator32     void deallocate(T* ptr, std::size_t) {
33         ::operator delete(ptr);
34     }
35 };
36 
37 template<class T, class U>
38 inline bool
operator ==(const creator<T> &,const creator<U> &)39 operator==(const creator<T>&, const creator<U>&)
40 {
41     return true;
42 }
43 
44 template<class T, class U>
45 inline bool
operator !=(const creator<T> &,const creator<U> &)46 operator!=(const creator<T>&, const creator<U>&)
47 {
48     return false;
49 }
50 
main()51 int main()
52 {
53     {
54         boost::local_shared_ptr<int[]> result =
55             boost::allocate_local_shared<int[]>(creator<int>(), 4, 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]>(creator<int>(), 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[]>(creator<>(), 4, 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]>(creator<>(), 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
main()88 int main()
89 {
90     return 0;
91 }
92 #endif
93