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 >= 46000) && \
11 !defined(BOOST_NO_CXX11_SMART_PTR) && \
12 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
13 #include <boost/smart_ptr/allocate_unique.hpp>
14 #include <boost/core/lightweight_test.hpp>
16 template<class T = void>
23 typedef creator<U> other;
29 creator(const creator<U>&) { }
31 T* allocate(std::size_t size) {
32 return static_cast<T*>(::operator new(sizeof(T) * size));
35 void deallocate(T* ptr, std::size_t) {
36 ::operator delete(ptr);
40 template<class T, class U>
42 operator==(const creator<T>&, const creator<U>&)
47 template<class T, class U>
49 operator!=(const creator<T>&, const creator<U>&)
56 static unsigned instances;
58 type(int v1, int v2, int v3, int v4, int v5)
59 : sum_(v1 + v2 + v3 + v4 + v5) {
75 type& operator=(const type&);
78 unsigned type::instances = 0;
82 BOOST_TEST(type::instances == 0);
85 boost::alloc_deleter<type, creator<type> > > result =
86 boost::allocate_unique<type>(creator<type>(), 1, 2, 3, 4, 5);
87 BOOST_TEST(result.get() != 0);
88 BOOST_TEST(type::instances == 1);
89 BOOST_TEST(result->sum() == 15);
91 BOOST_TEST(type::instances == 0);
93 BOOST_TEST(type::instances == 0);
95 std::unique_ptr<const type,
96 boost::alloc_deleter<const type, creator<> > > result =
97 boost::allocate_unique<const type>(creator<>(), 1, 2, 3, 4, 5);
98 BOOST_TEST(result.get() != 0);
99 BOOST_TEST(type::instances == 1);
100 BOOST_TEST(result->sum() == 15);
102 BOOST_TEST(type::instances == 0);
104 return boost::report_errors();