2 Copyright 2007 Tobias Schwinger
4 Copyright 2019 Glen Joseph Fernandes
7 Distributed under the Boost Software License, Version 1.0.
8 (http://www.boost.org/LICENSE_1_0.txt)
10 #include <boost/functional/factory.hpp>
11 #include <boost/core/lightweight_test.hpp>
12 #include <boost/smart_ptr/shared_ptr.hpp>
37 typedef creator<U> other;
43 creator(const creator<U>&) { }
45 T* allocate(std::size_t size) {
47 return static_cast<T*>(::operator new(sizeof(T) * size));
50 void deallocate(T* ptr, std::size_t) {
52 ::operator delete(ptr);
57 int creator<T>::count = 0;
59 template<class T, class U>
61 operator==(const creator<T>&, const creator<U>&)
66 template<class T, class U>
68 operator!=(const creator<T>&, const creator<U>&)
78 boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>,
80 boost::factory_alloc_for_pointee_and_deleter>()(a, b));
81 BOOST_TEST(creator<sum>::count == 1);
82 BOOST_TEST(s->get() == 3);
84 BOOST_TEST(creator<sum>::count == 0);
86 boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>,
88 boost::factory_passes_alloc_to_smart_pointer>()(a, b));
89 BOOST_TEST(creator<sum>::count == 1);
90 BOOST_TEST(s->get() == 3);
92 BOOST_TEST(creator<sum>::count == 0);
93 return boost::report_errors();