// Copyright 2011 Daniel James. // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include "../objects/test.hpp" template struct SimpleAllocator { typedef Tp value_type; SimpleAllocator() { } template SimpleAllocator(const SimpleAllocator& other) { } Tp *allocate(std::size_t n) { return static_cast(::operator new(n * sizeof(Tp))); } void deallocate(Tp* p, std::size_t) { ::operator delete((void*) p); } }; template void test_simple_allocator() { test::check_instances check_; typedef boost::unordered::detail::allocator_traits< SimpleAllocator > traits; BOOST_MPL_ASSERT((boost::is_same >)); BOOST_MPL_ASSERT((boost::is_same)); BOOST_MPL_ASSERT((boost::is_same)); BOOST_MPL_ASSERT((boost::is_same)); //BOOST_MPL_ASSERT((boost::is_same)); //BOOST_MPL_ASSERT((boost::is_same)); BOOST_MPL_ASSERT((boost::is_same)); #if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 1 BOOST_MPL_ASSERT((boost::is_same::type>)); #else BOOST_MPL_ASSERT((boost::is_same)); #endif BOOST_TEST(!traits::propagate_on_container_copy_assignment::value); BOOST_TEST(!traits::propagate_on_container_move_assignment::value); BOOST_TEST(!traits::propagate_on_container_swap::value); // rebind_alloc // rebind_traits SimpleAllocator a; T* ptr1 = traits::allocate(a, 1); //T* ptr2 = traits::allocate(a, 1, static_cast(ptr1)); traits::construct(a, ptr1, T(10)); //traits::construct(a, ptr2, T(30), ptr1); BOOST_TEST(*ptr1 == T(10)); //BOOST_TEST(*ptr2 == T(30)); traits::destroy(a, ptr1); //traits::destroy(a, ptr2); //traits::deallocate(a, ptr2, 1); traits::deallocate(a, ptr1, 1); traits::max_size(a); } int main() { test_simple_allocator(); test_simple_allocator(); return boost::report_errors(); }