/* Copyright 2019 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_ALLOCATOR) #include #include class type { public: explicit type(int x) : value_(x) { } int value() const { return value_; } static int count; private: type(const type&); type& operator=(const type&); int value_; }; int type::count = 0; template struct creator { typedef T value_type; creator() { } template creator(const creator&) { } T* allocate(std::size_t size) { return static_cast(::operator new(sizeof(T) * size)); } void deallocate(T* ptr, std::size_t) { ::operator delete(ptr); } template void construct(type* ptr, const V& value) { ::new(static_cast(ptr)) type(value + 1); ++type::count; } void destroy(type* ptr) { ptr->~type(); --type::count; } }; int main() { creator a; type* p = a.allocate(1); boost::alloc_construct(a, p, 1); BOOST_TEST_EQ(type::count, 1); BOOST_TEST_EQ(p->value(), 2); boost::alloc_destroy(a, p); BOOST_TEST_EQ(type::count, 0); return boost::report_errors(); } #else int main() { return 0; } #endif