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 #include <boost/smart_ptr/allocate_unique.hpp>
13 #include <boost/core/lightweight_test.hpp>
15 template<class T = void>
22 typedef creator<U> other;
28 creator(const creator<U>&) { }
30 T* allocate(std::size_t size) {
31 return static_cast<T*>(::operator new(sizeof(T) * size));
34 void deallocate(T* ptr, std::size_t) {
35 ::operator delete(ptr);
39 template<class T, class U>
41 operator==(const creator<T>&, const creator<U>&)
46 template<class T, class U>
48 operator!=(const creator<T>&, const creator<U>&)
55 static unsigned instances;
66 void set(long double value) {
70 long double get() const {
76 type& operator=(const type&);
81 unsigned type::instances = 0;
87 boost::alloc_deleter<int,
88 boost::noinit_adaptor<creator<int> > > > result =
89 boost::allocate_unique_noinit<int>(creator<int>());
90 BOOST_TEST(result.get() != 0);
93 std::unique_ptr<const int,
94 boost::alloc_deleter<const int,
95 boost::noinit_adaptor<creator<> > > > result =
96 boost::allocate_unique_noinit<const int>(creator<>());
97 BOOST_TEST(result.get() != 0);
100 std::unique_ptr<type,
101 boost::alloc_deleter<type,
102 boost::noinit_adaptor<creator<type> > > > result =
103 boost::allocate_unique_noinit<type>(creator<type>());
104 BOOST_TEST(result.get() != 0);
105 BOOST_TEST(type::instances == 1);
107 BOOST_TEST(type::instances == 0);
110 std::unique_ptr<const type,
111 boost::alloc_deleter<const type,
112 boost::noinit_adaptor<creator<> > > > result =
113 boost::allocate_unique_noinit<const type>(creator<>());
114 BOOST_TEST(result.get() != 0);
115 BOOST_TEST(type::instances == 1);
117 BOOST_TEST(type::instances == 0);
119 return boost::report_errors();