]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
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) | |
5 | * | |
6 | * See http://www.boost.org/libs/poly_collection for library home page. | |
7 | */ | |
8 | ||
9 | #ifndef BOOST_POLY_COLLECTION_DETAIL_NEWDELETE_ALLOCATOR_HPP | |
10 | #define BOOST_POLY_COLLECTION_DETAIL_NEWDELETE_ALLOCATOR_HPP | |
11 | ||
12 | #if defined(_MSC_VER) | |
13 | #pragma once | |
14 | #endif | |
15 | ||
16 | #include <boost/poly_collection/detail/is_constructible.hpp> | |
17 | #include <memory> | |
18 | #include <new> | |
19 | #include <utility> | |
20 | ||
21 | namespace boost{ | |
22 | ||
23 | namespace poly_collection{ | |
24 | ||
25 | namespace detail{ | |
26 | ||
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. | |
31 | */ | |
32 | ||
33 | template<typename Allocator> | |
34 | struct newdelete_allocator_adaptor:Allocator | |
35 | { | |
36 | using traits=std::allocator_traits<Allocator>; | |
37 | ||
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; | |
51 | ||
52 | template<typename U> | |
53 | struct rebind | |
54 | { | |
55 | using other=newdelete_allocator_adaptor< | |
56 | typename traits::template rebind_alloc<U>>; | |
57 | }; | |
58 | ||
59 | newdelete_allocator_adaptor()=default; | |
60 | newdelete_allocator_adaptor(const newdelete_allocator_adaptor&)=default; | |
61 | ||
62 | template< | |
63 | typename Allocator2, | |
64 | typename std::enable_if< | |
65 | is_constructible<Allocator,Allocator2>::value | |
66 | >::type* =nullptr | |
67 | > | |
68 | newdelete_allocator_adaptor(const Allocator2& x)noexcept:Allocator{x}{} | |
69 | ||
70 | template< | |
71 | typename Allocator2, | |
72 | typename std::enable_if< | |
73 | is_constructible<Allocator,Allocator2>::value | |
74 | >::type* =nullptr | |
75 | > | |
76 | newdelete_allocator_adaptor( | |
77 | const newdelete_allocator_adaptor<Allocator2>& x)noexcept: | |
78 | Allocator{static_cast<const Allocator2&>(x)}{} | |
79 | ||
80 | newdelete_allocator_adaptor& operator=( | |
81 | const newdelete_allocator_adaptor&)=default; | |
82 | ||
83 | template<typename T,typename... Args> | |
84 | void construct(T* p,Args&&... args) | |
85 | { | |
86 | ::new ((void*)p) T(std::forward<Args>(args)...); | |
87 | } | |
88 | ||
89 | template<typename T> | |
90 | void destroy(T* p) | |
91 | { | |
92 | p->~T(); | |
93 | } | |
94 | }; | |
95 | ||
96 | } /* namespace poly_collection::detail */ | |
97 | ||
98 | } /* namespace poly_collection */ | |
99 | ||
100 | } /* namespace boost */ | |
101 | ||
102 | #endif |