1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | #ifndef _ALLOCATOR_H |
44 | #define _ALLOCATOR_H 1 |
45 | |
46 | #include <bits/c++allocator.h> |
47 | #include <bits/memoryfwd.h> |
48 | #if __cplusplus >= 201103L |
49 | #include <type_traits> |
50 | #endif |
51 | |
52 | #define __cpp_lib_incomplete_container_elements 201505 |
53 | #if __cplusplus >= 201103L |
54 | # define __cpp_lib_allocator_is_always_equal 201411 |
55 | #endif |
56 | |
57 | namespace std _GLIBCXX_VISIBILITY(default) |
58 | { |
59 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | template<> |
68 | class allocator<void> |
69 | { |
70 | public: |
71 | typedef size_t size_type; |
72 | typedef ptrdiff_t difference_type; |
73 | typedef void* pointer; |
74 | typedef const void* const_pointer; |
75 | typedef void value_type; |
76 | |
77 | template<typename _Tp1> |
78 | struct rebind |
79 | { typedef allocator<_Tp1> other; }; |
80 | |
81 | #if __cplusplus >= 201103L |
82 | |
83 | |
84 | typedef true_type propagate_on_container_move_assignment; |
85 | |
86 | typedef true_type is_always_equal; |
87 | |
88 | template<typename _Up, typename... _Args> |
89 | void |
90 | construct(_Up* __p, _Args&&... __args) |
91 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } |
92 | |
93 | template<typename _Up> |
94 | void |
95 | destroy(_Up* __p) { __p->~_Up(); } |
96 | #endif |
97 | }; |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | template<typename _Tp> |
108 | class allocator: public __allocator_base<_Tp> |
109 | { |
110 | public: |
111 | typedef size_t size_type; |
112 | typedef ptrdiff_t difference_type; |
113 | typedef _Tp* pointer; |
114 | typedef const _Tp* const_pointer; |
115 | typedef _Tp& reference; |
116 | typedef const _Tp& const_reference; |
117 | typedef _Tp value_type; |
118 | |
119 | template<typename _Tp1> |
120 | struct rebind |
121 | { typedef allocator<_Tp1> other; }; |
122 | |
123 | #if __cplusplus >= 201103L |
124 | |
125 | |
126 | typedef true_type propagate_on_container_move_assignment; |
127 | |
128 | typedef true_type is_always_equal; |
129 | #endif |
130 | |
131 | allocator() throw() { } |
132 | |
133 | allocator(const allocator& __a) throw() |
134 | : __allocator_base<_Tp>(__a) { } |
135 | |
136 | template<typename _Tp1> |
137 | allocator(const allocator<_Tp1>&) throw() { } |
138 | |
139 | ~allocator() throw() { } |
140 | |
141 | |
142 | }; |
143 | |
144 | template<typename _T1, typename _T2> |
145 | inline bool |
146 | operator==(const allocator<_T1>&, const allocator<_T2>&) |
147 | _GLIBCXX_USE_NOEXCEPT |
148 | { return true; } |
149 | |
150 | template<typename _Tp> |
151 | inline bool |
152 | operator==(const allocator<_Tp>&, const allocator<_Tp>&) |
153 | _GLIBCXX_USE_NOEXCEPT |
154 | { return true; } |
155 | |
156 | template<typename _T1, typename _T2> |
157 | inline bool |
158 | operator!=(const allocator<_T1>&, const allocator<_T2>&) |
159 | _GLIBCXX_USE_NOEXCEPT |
160 | { return false; } |
161 | |
162 | template<typename _Tp> |
163 | inline bool |
164 | operator!=(const allocator<_Tp>&, const allocator<_Tp>&) |
165 | _GLIBCXX_USE_NOEXCEPT |
166 | { return false; } |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | #if _GLIBCXX_EXTERN_TEMPLATE |
173 | extern template class allocator<char>; |
174 | extern template class allocator<wchar_t>; |
175 | #endif |
176 | |
177 | |
178 | #undef __allocator_base |
179 | |
180 | |
181 | template<typename _Alloc, bool = __is_empty(_Alloc)> |
182 | struct __alloc_swap |
183 | { static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } }; |
184 | |
185 | template<typename _Alloc> |
186 | struct __alloc_swap<_Alloc, false> |
187 | { |
188 | static void |
189 | _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT |
190 | { |
191 | |
192 | if (__one != __two) |
193 | swap(__one, __two); |
194 | } |
195 | }; |
196 | |
197 | |
198 | template<typename _Alloc, bool = __is_empty(_Alloc)> |
199 | struct __alloc_neq |
200 | { |
201 | static bool |
202 | _S_do_it(const _Alloc&, const _Alloc&) |
203 | { return false; } |
204 | }; |
205 | |
206 | template<typename _Alloc> |
207 | struct __alloc_neq<_Alloc, false> |
208 | { |
209 | static bool |
210 | _S_do_it(const _Alloc& __one, const _Alloc& __two) |
211 | { return __one != __two; } |
212 | }; |
213 | |
214 | #if __cplusplus >= 201103L |
215 | template<typename _Tp, bool |
216 | = __or_<is_copy_constructible<typename _Tp::value_type>, |
217 | is_nothrow_move_constructible<typename _Tp::value_type>>::value> |
218 | struct __shrink_to_fit_aux |
219 | { static bool _S_do_it(_Tp&) noexcept { return false; } }; |
220 | |
221 | template<typename _Tp> |
222 | struct __shrink_to_fit_aux<_Tp, true> |
223 | { |
224 | static bool |
225 | _S_do_it(_Tp& __c) noexcept |
226 | { |
227 | #if __cpp_exceptions |
228 | try |
229 | { |
230 | _Tp(__make_move_if_noexcept_iterator(__c.begin()), |
231 | __make_move_if_noexcept_iterator(__c.end()), |
232 | __c.get_allocator()).swap(__c); |
233 | return true; |
234 | } |
235 | catch(...) |
236 | { return false; } |
237 | #else |
238 | return false; |
239 | #endif |
240 | } |
241 | }; |
242 | #endif |
243 | |
244 | _GLIBCXX_END_NAMESPACE_VERSION |
245 | } |
246 | |
247 | #endif |
248 | |