2 Copyright 2019 Glen Joseph Fernandes
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
8 #include <boost/config.hpp>
9 #if (!defined(BOOST_LIBSTDCXX_VERSION) || \
10 BOOST_LIBSTDCXX_VERSION >= 48000) && \
11 !defined(BOOST_NO_CXX11_SMART_PTR) && \
12 !defined(BOOST_NO_CXX11_ALLOCATOR)
13 #include <boost/smart_ptr/allocate_unique.hpp>
14 #include <boost/core/lightweight_test.hpp>
18 template<class T = void>
24 typedef creator<U> other;
30 creator(const creator<U>&) { }
32 T* allocate(std::size_t size) {
33 return static_cast<T*>(::operator new(sizeof(T) * size));
36 void deallocate(T* ptr, std::size_t) {
37 ::operator delete(ptr);
41 void construct(U* ptr) {
42 ::new(static_cast<void*>(ptr)) U(allow());
46 void destroy(U* ptr) {
52 template<class T, class U>
54 operator==(const creator<T>&, const creator<U>&)
59 template<class T, class U>
61 operator!=(const creator<T>&, const creator<U>&)
68 static unsigned instances;
70 explicit type(allow) {
80 type& operator=(const type&);
83 unsigned type::instances = 0;
88 std::unique_ptr<type[],
89 boost::alloc_deleter<type[], creator<type> > > result =
90 boost::allocate_unique<type[]>(creator<type>(), 3);
91 BOOST_TEST(result.get() != 0);
92 BOOST_TEST(type::instances == 3);
94 BOOST_TEST(type::instances == 0);
97 std::unique_ptr<type[],
98 boost::alloc_deleter<type[3], creator<type> > > result =
99 boost::allocate_unique<type[3]>(creator<type>());
100 BOOST_TEST(result.get() != 0);
101 BOOST_TEST(type::instances == 3);
103 BOOST_TEST(type::instances == 0);
106 std::unique_ptr<type[][2],
107 boost::alloc_deleter<type[][2], creator<> > > result =
108 boost::allocate_unique<type[][2]>(creator<>(), 2);
109 BOOST_TEST(result.get() != 0);
110 BOOST_TEST(type::instances == 4);
112 BOOST_TEST(type::instances == 0);
115 std::unique_ptr<type[][2],
116 boost::alloc_deleter<type[2][2], creator<> > > result =
117 boost::allocate_unique<type[2][2]>(creator<>());
118 BOOST_TEST(result.get() != 0);
119 BOOST_TEST(type::instances == 4);
121 BOOST_TEST(type::instances == 0);
124 std::unique_ptr<const type[],
125 boost::alloc_deleter<const type[], creator<> > > result =
126 boost::allocate_unique<const type[]>(creator<>(), 3);
127 BOOST_TEST(result.get() != 0);
128 BOOST_TEST(type::instances == 3);
130 BOOST_TEST(type::instances == 0);
133 std::unique_ptr<const type[],
134 boost::alloc_deleter<const type[3], creator<> > > result =
135 boost::allocate_unique<const type[3]>(creator<>());
136 BOOST_TEST(result.get() != 0);
137 BOOST_TEST(type::instances == 3);
139 BOOST_TEST(type::instances == 0);
142 std::unique_ptr<const type[][2],
143 boost::alloc_deleter<const type[][2], creator<> > > result =
144 boost::allocate_unique<const type[][2]>(creator<>(), 2);
145 BOOST_TEST(result.get() != 0);
146 BOOST_TEST(type::instances == 4);
148 BOOST_TEST(type::instances == 0);
151 std::unique_ptr<const type[][2],
152 boost::alloc_deleter<const type[2][2], creator<> > > result =
153 boost::allocate_unique<const type[2][2]>(creator<>());
154 BOOST_TEST(result.get() != 0);
155 BOOST_TEST(type::instances == 4);
157 BOOST_TEST(type::instances == 0);
159 return boost::report_errors();