1 /* Copyright 2016-2017 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 #ifndef BOOST_POLY_COLLECTION_DETAIL_NEWDELETE_ALLOCATOR_HPP
10 #define BOOST_POLY_COLLECTION_DETAIL_NEWDELETE_ALLOCATOR_HPP
16 #include <boost/poly_collection/detail/is_constructible.hpp>
23 namespace poly_collection{
27 /* In order to comply with [container.requirements.general]/3,
28 * newdelete_allocator_adaptor<Allocator> overrides
29 * Allocator::construct/destroy with vanilla new/delete implementations.
30 * Used therefore in all auxiliary internal structures.
33 template<typename Allocator>
34 struct newdelete_allocator_adaptor:Allocator
36 using traits=std::allocator_traits<Allocator>;
38 using value_type=typename traits::value_type;
39 using size_type=typename traits::size_type;
40 using difference_type=typename traits::difference_type;
41 using pointer=typename traits::pointer;
42 using const_pointer=typename traits::const_pointer;
43 using void_pointer=typename traits::void_pointer;
44 using const_void_pointer=typename traits::const_void_pointer;
45 using propagate_on_container_copy_assignment=
46 typename traits::propagate_on_container_copy_assignment;
47 using propagate_on_container_move_assignment=
48 typename traits::propagate_on_container_move_assignment;
49 using propagate_on_container_swap=
50 typename traits::propagate_on_container_swap;
55 using other=newdelete_allocator_adaptor<
56 typename traits::template rebind_alloc<U>>;
59 newdelete_allocator_adaptor()=default;
60 newdelete_allocator_adaptor(const newdelete_allocator_adaptor&)=default;
64 typename std::enable_if<
65 is_constructible<Allocator,Allocator2>::value
68 newdelete_allocator_adaptor(const Allocator2& x)noexcept:Allocator{x}{}
72 typename std::enable_if<
73 is_constructible<Allocator,Allocator2>::value
76 newdelete_allocator_adaptor(
77 const newdelete_allocator_adaptor<Allocator2>& x)noexcept:
78 Allocator{static_cast<const Allocator2&>(x)}{}
80 newdelete_allocator_adaptor& operator=(
81 const newdelete_allocator_adaptor&)=default;
83 template<typename T,typename... Args>
84 void construct(T* p,Args&&... args)
86 ::new ((void*)p) T(std::forward<Args>(args)...);
96 } /* namespace poly_collection::detail */
98 } /* namespace poly_collection */
100 } /* namespace boost */