/* Copyright 2016-2017 Joaquin M Lopez Munoz. * 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) * * See http://www.boost.org/libs/poly_collection for library home page. */ #ifndef BOOST_POLY_COLLECTION_DETAIL_NEWDELETE_ALLOCATOR_HPP #define BOOST_POLY_COLLECTION_DETAIL_NEWDELETE_ALLOCATOR_HPP #if defined(_MSC_VER) #pragma once #endif #include #include #include #include namespace boost{ namespace poly_collection{ namespace detail{ /* In order to comply with [container.requirements.general]/3, * newdelete_allocator_adaptor overrides * Allocator::construct/destroy with vanilla new/delete implementations. * Used therefore in all auxiliary internal structures. */ template struct newdelete_allocator_adaptor:Allocator { using traits=std::allocator_traits; using value_type=typename traits::value_type; using size_type=typename traits::size_type; using difference_type=typename traits::difference_type; using pointer=typename traits::pointer; using const_pointer=typename traits::const_pointer; using void_pointer=typename traits::void_pointer; using const_void_pointer=typename traits::const_void_pointer; using propagate_on_container_copy_assignment= typename traits::propagate_on_container_copy_assignment; using propagate_on_container_move_assignment= typename traits::propagate_on_container_move_assignment; using propagate_on_container_swap= typename traits::propagate_on_container_swap; template struct rebind { using other=newdelete_allocator_adaptor< typename traits::template rebind_alloc>; }; newdelete_allocator_adaptor()=default; newdelete_allocator_adaptor(const newdelete_allocator_adaptor&)=default; template< typename Allocator2, typename std::enable_if< is_constructible::value >::type* =nullptr > newdelete_allocator_adaptor(const Allocator2& x)noexcept:Allocator{x}{} template< typename Allocator2, typename std::enable_if< is_constructible::value >::type* =nullptr > newdelete_allocator_adaptor( const newdelete_allocator_adaptor& x)noexcept: Allocator{static_cast(x)}{} newdelete_allocator_adaptor& operator=( const newdelete_allocator_adaptor&)=default; template void construct(T* p,Args&&... args) { ::new ((void*)p) T(std::forward(args)...); } template void destroy(T* p) { p->~T(); } }; } /* namespace poly_collection::detail */ } /* namespace poly_collection */ } /* namespace boost */ #endif