Chris@16
|
1
|
Chris@16
|
2 // Copyright 2005-2011 Daniel James.
|
Chris@16
|
3 // Copyright 2009 Pablo Halpern.
|
Chris@16
|
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 // See http://www.boost.org/libs/unordered for documentation
|
Chris@16
|
8
|
Chris@16
|
9 #ifndef BOOST_UNORDERED_ALLOCATE_HPP
|
Chris@16
|
10 #define BOOST_UNORDERED_ALLOCATE_HPP
|
Chris@16
|
11
|
Chris@101
|
12 #include <boost/config.hpp>
|
Chris@101
|
13 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
14 #pragma once
|
Chris@16
|
15 #endif
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/unordered/detail/fwd.hpp>
|
Chris@16
|
18 #include <boost/move/move.hpp>
|
Chris@16
|
19 #include <boost/preprocessor/cat.hpp>
|
Chris@16
|
20 #include <boost/preprocessor/inc.hpp>
|
Chris@16
|
21 #include <boost/preprocessor/dec.hpp>
|
Chris@16
|
22 #include <boost/preprocessor/repetition/enum.hpp>
|
Chris@16
|
23 #include <boost/preprocessor/repetition/enum_params.hpp>
|
Chris@16
|
24 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
Chris@16
|
25 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
Chris@16
|
26 #include <boost/type_traits/is_class.hpp>
|
Chris@16
|
27 #include <boost/type_traits/add_lvalue_reference.hpp>
|
Chris@16
|
28 #include <boost/tuple/tuple.hpp>
|
Chris@16
|
29 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
30 #include <boost/utility/addressof.hpp>
|
Chris@16
|
31 #include <boost/detail/select_type.hpp>
|
Chris@16
|
32 #include <boost/assert.hpp>
|
Chris@16
|
33 #include <utility>
|
Chris@16
|
34
|
Chris@16
|
35 #if !defined(BOOST_NO_CXX11_HDR_TUPLE)
|
Chris@16
|
36 #include <tuple>
|
Chris@16
|
37 #endif
|
Chris@16
|
38
|
Chris@16
|
39 #if defined(BOOST_MSVC)
|
Chris@16
|
40 #pragma warning(push)
|
Chris@16
|
41 #pragma warning(disable:4512) // assignment operator could not be generated.
|
Chris@16
|
42 #pragma warning(disable:4345) // behavior change: an object of POD type
|
Chris@16
|
43 // constructed with an initializer of the form ()
|
Chris@16
|
44 // will be default-initialized.
|
Chris@16
|
45 #endif
|
Chris@16
|
46
|
Chris@16
|
47 #define BOOST_UNORDERED_EMPLACE_LIMIT 10
|
Chris@16
|
48
|
Chris@16
|
49 namespace boost { namespace unordered { namespace detail {
|
Chris@16
|
50
|
Chris@16
|
51 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
52 // Bits and pieces for implementing traits
|
Chris@16
|
53
|
Chris@16
|
54 template <typename T> typename boost::add_lvalue_reference<T>::type make();
|
Chris@16
|
55 struct choice9 { typedef char (&type)[9]; };
|
Chris@16
|
56 struct choice8 : choice9 { typedef char (&type)[8]; };
|
Chris@16
|
57 struct choice7 : choice8 { typedef char (&type)[7]; };
|
Chris@16
|
58 struct choice6 : choice7 { typedef char (&type)[6]; };
|
Chris@16
|
59 struct choice5 : choice6 { typedef char (&type)[5]; };
|
Chris@16
|
60 struct choice4 : choice5 { typedef char (&type)[4]; };
|
Chris@16
|
61 struct choice3 : choice4 { typedef char (&type)[3]; };
|
Chris@16
|
62 struct choice2 : choice3 { typedef char (&type)[2]; };
|
Chris@16
|
63 struct choice1 : choice2 { typedef char (&type)[1]; };
|
Chris@16
|
64 choice1 choose();
|
Chris@16
|
65
|
Chris@16
|
66 typedef choice1::type yes_type;
|
Chris@16
|
67 typedef choice2::type no_type;
|
Chris@16
|
68
|
Chris@16
|
69 struct private_type
|
Chris@16
|
70 {
|
Chris@16
|
71 private_type const &operator,(int) const;
|
Chris@16
|
72 };
|
Chris@16
|
73
|
Chris@16
|
74 template <typename T>
|
Chris@16
|
75 no_type is_private_type(T const&);
|
Chris@16
|
76 yes_type is_private_type(private_type const&);
|
Chris@16
|
77
|
Chris@16
|
78 struct convert_from_anything {
|
Chris@16
|
79 template <typename T>
|
Chris@16
|
80 convert_from_anything(T const&);
|
Chris@16
|
81 };
|
Chris@16
|
82
|
Chris@16
|
83 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
84 // emplace_args
|
Chris@16
|
85 //
|
Chris@16
|
86 // Either forwarding variadic arguments, or storing the arguments in
|
Chris@16
|
87 // emplace_args##n
|
Chris@16
|
88
|
Chris@16
|
89 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
90
|
Chris@16
|
91 #define BOOST_UNORDERED_EMPLACE_TEMPLATE typename... Args
|
Chris@16
|
92 #define BOOST_UNORDERED_EMPLACE_ARGS BOOST_FWD_REF(Args)... args
|
Chris@16
|
93 #define BOOST_UNORDERED_EMPLACE_FORWARD boost::forward<Args>(args)...
|
Chris@16
|
94
|
Chris@16
|
95 #define BOOST_UNORDERED_EMPLACE_ARGS1(a0) a0
|
Chris@16
|
96 #define BOOST_UNORDERED_EMPLACE_ARGS2(a0, a1) a0, a1
|
Chris@16
|
97 #define BOOST_UNORDERED_EMPLACE_ARGS3(a0, a1, a2) a0, a1, a2
|
Chris@16
|
98
|
Chris@16
|
99 #else
|
Chris@16
|
100
|
Chris@16
|
101 #define BOOST_UNORDERED_EMPLACE_TEMPLATE typename Args
|
Chris@16
|
102 #define BOOST_UNORDERED_EMPLACE_ARGS Args const& args
|
Chris@16
|
103 #define BOOST_UNORDERED_EMPLACE_FORWARD args
|
Chris@16
|
104
|
Chris@16
|
105 #define BOOST_UNORDERED_FWD_PARAM(z, n, a) \
|
Chris@16
|
106 BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(a, n)
|
Chris@16
|
107
|
Chris@16
|
108 #define BOOST_UNORDERED_CALL_FORWARD(z, i, a) \
|
Chris@16
|
109 boost::forward<BOOST_PP_CAT(A,i)>(BOOST_PP_CAT(a,i))
|
Chris@16
|
110
|
Chris@16
|
111 #define BOOST_UNORDERED_EARGS(z, n, _) \
|
Chris@16
|
112 template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
Chris@16
|
113 struct BOOST_PP_CAT(emplace_args, n) \
|
Chris@16
|
114 { \
|
Chris@16
|
115 BOOST_PP_REPEAT_##z(n, BOOST_UNORDERED_EARGS_MEMBER, _) \
|
Chris@16
|
116 BOOST_PP_CAT(emplace_args, n) ( \
|
Chris@16
|
117 BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, Arg, b) \
|
Chris@16
|
118 ) : BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_EARGS_INIT, _) \
|
Chris@16
|
119 {} \
|
Chris@16
|
120 \
|
Chris@16
|
121 }; \
|
Chris@16
|
122 \
|
Chris@16
|
123 template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
Chris@16
|
124 inline BOOST_PP_CAT(emplace_args, n) < \
|
Chris@16
|
125 BOOST_PP_ENUM_PARAMS_Z(z, n, A) \
|
Chris@16
|
126 > create_emplace_args( \
|
Chris@16
|
127 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, b) \
|
Chris@16
|
128 ) \
|
Chris@16
|
129 { \
|
Chris@16
|
130 BOOST_PP_CAT(emplace_args, n) < \
|
Chris@16
|
131 BOOST_PP_ENUM_PARAMS_Z(z, n, A) \
|
Chris@16
|
132 > e(BOOST_PP_ENUM_PARAMS_Z(z, n, b)); \
|
Chris@16
|
133 return e; \
|
Chris@16
|
134 }
|
Chris@16
|
135
|
Chris@16
|
136 #define BOOST_UNORDERED_EMPLACE_ARGS1 create_emplace_args
|
Chris@16
|
137 #define BOOST_UNORDERED_EMPLACE_ARGS2 create_emplace_args
|
Chris@16
|
138 #define BOOST_UNORDERED_EMPLACE_ARGS3 create_emplace_args
|
Chris@16
|
139
|
Chris@16
|
140 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
141
|
Chris@16
|
142 #define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \
|
Chris@16
|
143 typedef BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(Arg, n); \
|
Chris@16
|
144 BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n);
|
Chris@16
|
145
|
Chris@16
|
146 #define BOOST_UNORDERED_EARGS_INIT(z, n, _) \
|
Chris@16
|
147 BOOST_PP_CAT(a, n)( \
|
Chris@16
|
148 boost::forward<BOOST_PP_CAT(A,n)>(BOOST_PP_CAT(b, n)))
|
Chris@16
|
149
|
Chris@16
|
150 #else
|
Chris@16
|
151
|
Chris@16
|
152 #define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \
|
Chris@16
|
153 typedef typename boost::add_lvalue_reference<BOOST_PP_CAT(A, n)>::type \
|
Chris@16
|
154 BOOST_PP_CAT(Arg, n); \
|
Chris@16
|
155 BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n);
|
Chris@16
|
156
|
Chris@16
|
157 #define BOOST_UNORDERED_EARGS_INIT(z, n, _) \
|
Chris@16
|
158 BOOST_PP_CAT(a, n)(BOOST_PP_CAT(b, n))
|
Chris@16
|
159
|
Chris@16
|
160 #endif
|
Chris@16
|
161
|
Chris@16
|
162 BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EARGS,
|
Chris@16
|
163 _)
|
Chris@16
|
164
|
Chris@16
|
165 #undef BOOST_UNORDERED_DEFINE_EMPLACE_ARGS
|
Chris@16
|
166 #undef BOOST_UNORDERED_EARGS_MEMBER
|
Chris@16
|
167 #undef BOOST_UNORDERED_EARGS_INIT
|
Chris@16
|
168
|
Chris@16
|
169 #endif
|
Chris@16
|
170
|
Chris@16
|
171 }}}
|
Chris@16
|
172
|
Chris@16
|
173 ////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
174 //
|
Chris@16
|
175 // Pick which version of allocator_traits to use
|
Chris@16
|
176 //
|
Chris@16
|
177 // 0 = Own partial implementation
|
Chris@16
|
178 // 1 = std::allocator_traits
|
Chris@16
|
179 // 2 = boost::container::allocator_traits
|
Chris@16
|
180
|
Chris@16
|
181 #if !defined(BOOST_UNORDERED_USE_ALLOCATOR_TRAITS)
|
Chris@16
|
182 # if defined(__GXX_EXPERIMENTAL_CXX0X__) && \
|
Chris@16
|
183 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
|
Chris@16
|
184 # define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 0
|
Chris@16
|
185 # elif defined(BOOST_MSVC)
|
Chris@16
|
186 # if BOOST_MSVC < 1400
|
Chris@16
|
187 // Use container's allocator_traits for older versions of Visual
|
Chris@16
|
188 // C++ as I don't test with them.
|
Chris@16
|
189 # define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 2
|
Chris@16
|
190 # endif
|
Chris@16
|
191 # endif
|
Chris@16
|
192 #endif
|
Chris@16
|
193
|
Chris@16
|
194 #if !defined(BOOST_UNORDERED_USE_ALLOCATOR_TRAITS)
|
Chris@16
|
195 # define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 0
|
Chris@16
|
196 #endif
|
Chris@16
|
197
|
Chris@16
|
198 ////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
199 //
|
Chris@16
|
200 // Some utilities for implementing allocator_traits, but useful elsewhere so
|
Chris@16
|
201 // they're always defined.
|
Chris@16
|
202
|
Chris@16
|
203 #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
Chris@16
|
204 # include <type_traits>
|
Chris@16
|
205 #endif
|
Chris@16
|
206
|
Chris@16
|
207 namespace boost { namespace unordered { namespace detail {
|
Chris@16
|
208
|
Chris@16
|
209 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
210 // Integral_constrant, true_type, false_type
|
Chris@16
|
211 //
|
Chris@16
|
212 // Uses the standard versions if available.
|
Chris@16
|
213
|
Chris@16
|
214 #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
Chris@16
|
215
|
Chris@16
|
216 using std::integral_constant;
|
Chris@16
|
217 using std::true_type;
|
Chris@16
|
218 using std::false_type;
|
Chris@16
|
219
|
Chris@16
|
220 #else
|
Chris@16
|
221
|
Chris@16
|
222 template <typename T, T Value>
|
Chris@16
|
223 struct integral_constant { enum { value = Value }; };
|
Chris@16
|
224
|
Chris@16
|
225 typedef boost::unordered::detail::integral_constant<bool, true> true_type;
|
Chris@16
|
226 typedef boost::unordered::detail::integral_constant<bool, false> false_type;
|
Chris@16
|
227
|
Chris@16
|
228 #endif
|
Chris@16
|
229
|
Chris@16
|
230 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
231 // Explicitly call a destructor
|
Chris@16
|
232
|
Chris@16
|
233 #if defined(BOOST_MSVC)
|
Chris@16
|
234 #pragma warning(push)
|
Chris@16
|
235 #pragma warning(disable:4100) // unreferenced formal parameter
|
Chris@16
|
236 #endif
|
Chris@16
|
237
|
Chris@16
|
238 namespace func {
|
Chris@16
|
239 template <class T>
|
Chris@16
|
240 inline void destroy(T* x) {
|
Chris@16
|
241 x->~T();
|
Chris@16
|
242 }
|
Chris@16
|
243 }
|
Chris@16
|
244
|
Chris@16
|
245 #if defined(BOOST_MSVC)
|
Chris@16
|
246 #pragma warning(pop)
|
Chris@16
|
247 #endif
|
Chris@16
|
248
|
Chris@16
|
249 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
250 // Expression test mechanism
|
Chris@16
|
251 //
|
Chris@16
|
252 // When SFINAE expressions are available, define
|
Chris@16
|
253 // BOOST_UNORDERED_HAS_FUNCTION which can check if a function call is
|
Chris@16
|
254 // supported by a class, otherwise define BOOST_UNORDERED_HAS_MEMBER which
|
Chris@16
|
255 // can detect if a class has the specified member, but not that it has the
|
Chris@16
|
256 // correct type, this is good enough for a passable impression of
|
Chris@16
|
257 // allocator_traits.
|
Chris@16
|
258
|
Chris@16
|
259 #if !defined(BOOST_NO_SFINAE_EXPR)
|
Chris@16
|
260
|
Chris@16
|
261 template <typename T, unsigned int> struct expr_test;
|
Chris@16
|
262 template <typename T> struct expr_test<T, sizeof(char)> : T {};
|
Chris@16
|
263
|
Chris@16
|
264 # define BOOST_UNORDERED_CHECK_EXPRESSION(count, result, expression) \
|
Chris@16
|
265 template <typename U> \
|
Chris@16
|
266 static typename boost::unordered::detail::expr_test< \
|
Chris@16
|
267 BOOST_PP_CAT(choice, result), \
|
Chris@16
|
268 sizeof(for_expr_test(( \
|
Chris@16
|
269 (expression), \
|
Chris@16
|
270 0)))>::type test( \
|
Chris@16
|
271 BOOST_PP_CAT(choice, count))
|
Chris@16
|
272
|
Chris@16
|
273 # define BOOST_UNORDERED_DEFAULT_EXPRESSION(count, result) \
|
Chris@16
|
274 template <typename U> \
|
Chris@16
|
275 static BOOST_PP_CAT(choice, result)::type test( \
|
Chris@16
|
276 BOOST_PP_CAT(choice, count))
|
Chris@16
|
277
|
Chris@16
|
278 # define BOOST_UNORDERED_HAS_FUNCTION(name, thing, args, _) \
|
Chris@16
|
279 struct BOOST_PP_CAT(has_, name) \
|
Chris@16
|
280 { \
|
Chris@16
|
281 template <typename U> static char for_expr_test(U const&); \
|
Chris@16
|
282 BOOST_UNORDERED_CHECK_EXPRESSION(1, 1, \
|
Chris@16
|
283 boost::unordered::detail::make< thing >().name args); \
|
Chris@16
|
284 BOOST_UNORDERED_DEFAULT_EXPRESSION(2, 2); \
|
Chris@16
|
285 \
|
Chris@16
|
286 enum { value = sizeof(test<T>(choose())) == sizeof(choice1::type) };\
|
Chris@16
|
287 }
|
Chris@16
|
288
|
Chris@16
|
289 #else
|
Chris@16
|
290
|
Chris@16
|
291 template <typename T> struct identity { typedef T type; };
|
Chris@16
|
292
|
Chris@16
|
293 # define BOOST_UNORDERED_CHECK_MEMBER(count, result, name, member) \
|
Chris@16
|
294 \
|
Chris@16
|
295 typedef typename boost::unordered::detail::identity<member>::type \
|
Chris@16
|
296 BOOST_PP_CAT(check, count); \
|
Chris@16
|
297 \
|
Chris@16
|
298 template <BOOST_PP_CAT(check, count) e> \
|
Chris@16
|
299 struct BOOST_PP_CAT(test, count) { \
|
Chris@16
|
300 typedef BOOST_PP_CAT(choice, result) type; \
|
Chris@16
|
301 }; \
|
Chris@16
|
302 \
|
Chris@16
|
303 template <class U> static typename \
|
Chris@16
|
304 BOOST_PP_CAT(test, count)<&U::name>::type \
|
Chris@16
|
305 test(BOOST_PP_CAT(choice, count))
|
Chris@16
|
306
|
Chris@16
|
307 # define BOOST_UNORDERED_DEFAULT_MEMBER(count, result) \
|
Chris@16
|
308 template <class U> static BOOST_PP_CAT(choice, result)::type \
|
Chris@16
|
309 test(BOOST_PP_CAT(choice, count))
|
Chris@16
|
310
|
Chris@16
|
311 # define BOOST_UNORDERED_HAS_MEMBER(name) \
|
Chris@16
|
312 struct BOOST_PP_CAT(has_, name) \
|
Chris@16
|
313 { \
|
Chris@16
|
314 struct impl { \
|
Chris@16
|
315 struct base_mixin { int name; }; \
|
Chris@16
|
316 struct base : public T, public base_mixin {}; \
|
Chris@16
|
317 \
|
Chris@16
|
318 BOOST_UNORDERED_CHECK_MEMBER(1, 1, name, int base_mixin::*); \
|
Chris@16
|
319 BOOST_UNORDERED_DEFAULT_MEMBER(2, 2); \
|
Chris@16
|
320 \
|
Chris@16
|
321 enum { value = sizeof(choice2::type) == \
|
Chris@16
|
322 sizeof(test<base>(choose())) \
|
Chris@16
|
323 }; \
|
Chris@16
|
324 }; \
|
Chris@16
|
325 \
|
Chris@16
|
326 enum { value = impl::value }; \
|
Chris@16
|
327 }
|
Chris@16
|
328
|
Chris@16
|
329 #endif
|
Chris@16
|
330
|
Chris@16
|
331 }}}
|
Chris@16
|
332
|
Chris@16
|
333 ////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
334 //
|
Chris@16
|
335 // Allocator traits
|
Chris@16
|
336 //
|
Chris@16
|
337 // First our implementation, then later light wrappers around the alternatives
|
Chris@16
|
338
|
Chris@16
|
339 #if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 0
|
Chris@16
|
340
|
Chris@16
|
341 # include <boost/limits.hpp>
|
Chris@16
|
342 # include <boost/utility/enable_if.hpp>
|
Chris@16
|
343 # include <boost/pointer_to_other.hpp>
|
Chris@16
|
344 # if defined(BOOST_NO_SFINAE_EXPR)
|
Chris@16
|
345 # include <boost/type_traits/is_same.hpp>
|
Chris@16
|
346 # endif
|
Chris@16
|
347
|
Chris@16
|
348 # if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
Chris@16
|
349 !defined(BOOST_NO_SFINAE_EXPR)
|
Chris@16
|
350 # define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 1
|
Chris@16
|
351 # else
|
Chris@16
|
352 # define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 0
|
Chris@16
|
353 # endif
|
Chris@16
|
354
|
Chris@16
|
355 namespace boost { namespace unordered { namespace detail {
|
Chris@16
|
356
|
Chris@16
|
357 // TODO: Does this match std::allocator_traits<Alloc>::rebind_alloc<T>?
|
Chris@16
|
358 template <typename Alloc, typename T>
|
Chris@16
|
359 struct rebind_wrap
|
Chris@16
|
360 {
|
Chris@16
|
361 typedef typename Alloc::BOOST_NESTED_TEMPLATE rebind<T>::other type;
|
Chris@16
|
362 };
|
Chris@16
|
363
|
Chris@16
|
364 # if defined(BOOST_MSVC) && BOOST_MSVC <= 1400
|
Chris@16
|
365
|
Chris@16
|
366 # define BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(tname) \
|
Chris@16
|
367 template <typename Tp, typename Default> \
|
Chris@16
|
368 struct default_type_ ## tname { \
|
Chris@16
|
369 \
|
Chris@16
|
370 template <typename X> \
|
Chris@16
|
371 static choice1::type test(choice1, typename X::tname* = 0); \
|
Chris@16
|
372 \
|
Chris@16
|
373 template <typename X> \
|
Chris@16
|
374 static choice2::type test(choice2, void* = 0); \
|
Chris@16
|
375 \
|
Chris@16
|
376 struct DefaultWrap { typedef Default tname; }; \
|
Chris@16
|
377 \
|
Chris@16
|
378 enum { value = (1 == sizeof(test<Tp>(choose()))) }; \
|
Chris@16
|
379 \
|
Chris@16
|
380 typedef typename boost::detail::if_true<value>:: \
|
Chris@16
|
381 BOOST_NESTED_TEMPLATE then<Tp, DefaultWrap> \
|
Chris@16
|
382 ::type::tname type; \
|
Chris@16
|
383 }
|
Chris@16
|
384
|
Chris@16
|
385 # else
|
Chris@16
|
386
|
Chris@16
|
387 template <typename T, typename T2>
|
Chris@16
|
388 struct sfinae : T2 {};
|
Chris@16
|
389
|
Chris@16
|
390 # define BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(tname) \
|
Chris@16
|
391 template <typename Tp, typename Default> \
|
Chris@16
|
392 struct default_type_ ## tname { \
|
Chris@16
|
393 \
|
Chris@16
|
394 template <typename X> \
|
Chris@16
|
395 static typename boost::unordered::detail::sfinae< \
|
Chris@16
|
396 typename X::tname, choice1>::type \
|
Chris@16
|
397 test(choice1); \
|
Chris@16
|
398 \
|
Chris@16
|
399 template <typename X> \
|
Chris@16
|
400 static choice2::type test(choice2); \
|
Chris@16
|
401 \
|
Chris@16
|
402 struct DefaultWrap { typedef Default tname; }; \
|
Chris@16
|
403 \
|
Chris@16
|
404 enum { value = (1 == sizeof(test<Tp>(choose()))) }; \
|
Chris@16
|
405 \
|
Chris@16
|
406 typedef typename boost::detail::if_true<value>:: \
|
Chris@16
|
407 BOOST_NESTED_TEMPLATE then<Tp, DefaultWrap> \
|
Chris@16
|
408 ::type::tname type; \
|
Chris@16
|
409 }
|
Chris@16
|
410
|
Chris@16
|
411 # endif
|
Chris@16
|
412
|
Chris@16
|
413 # define BOOST_UNORDERED_DEFAULT_TYPE(T,tname, arg) \
|
Chris@16
|
414 typename default_type_ ## tname<T, arg>::type
|
Chris@16
|
415
|
Chris@16
|
416 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(pointer);
|
Chris@16
|
417 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(const_pointer);
|
Chris@16
|
418 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(void_pointer);
|
Chris@16
|
419 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(const_void_pointer);
|
Chris@16
|
420 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(difference_type);
|
Chris@16
|
421 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(size_type);
|
Chris@16
|
422 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(propagate_on_container_copy_assignment);
|
Chris@16
|
423 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(propagate_on_container_move_assignment);
|
Chris@16
|
424 BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(propagate_on_container_swap);
|
Chris@16
|
425
|
Chris@16
|
426 # if !defined(BOOST_NO_SFINAE_EXPR)
|
Chris@16
|
427
|
Chris@16
|
428 template <typename T>
|
Chris@16
|
429 BOOST_UNORDERED_HAS_FUNCTION(
|
Chris@16
|
430 select_on_container_copy_construction, U const, (), 0
|
Chris@16
|
431 );
|
Chris@16
|
432
|
Chris@16
|
433 template <typename T>
|
Chris@16
|
434 BOOST_UNORDERED_HAS_FUNCTION(
|
Chris@16
|
435 max_size, U const, (), 0
|
Chris@16
|
436 );
|
Chris@16
|
437
|
Chris@16
|
438 # if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
439
|
Chris@16
|
440 template <typename T, typename ValueType, typename... Args>
|
Chris@16
|
441 BOOST_UNORDERED_HAS_FUNCTION(
|
Chris@16
|
442 construct, U, (
|
Chris@16
|
443 boost::unordered::detail::make<ValueType*>(),
|
Chris@16
|
444 boost::unordered::detail::make<Args const>()...), 2
|
Chris@16
|
445 );
|
Chris@16
|
446
|
Chris@16
|
447 # else
|
Chris@16
|
448
|
Chris@16
|
449 template <typename T, typename ValueType>
|
Chris@16
|
450 BOOST_UNORDERED_HAS_FUNCTION(
|
Chris@16
|
451 construct, U, (
|
Chris@16
|
452 boost::unordered::detail::make<ValueType*>(),
|
Chris@16
|
453 boost::unordered::detail::make<ValueType const>()), 2
|
Chris@16
|
454 );
|
Chris@16
|
455
|
Chris@16
|
456 # endif
|
Chris@16
|
457
|
Chris@16
|
458 template <typename T, typename ValueType>
|
Chris@16
|
459 BOOST_UNORDERED_HAS_FUNCTION(
|
Chris@16
|
460 destroy, U, (boost::unordered::detail::make<ValueType*>()), 1
|
Chris@16
|
461 );
|
Chris@16
|
462
|
Chris@16
|
463 # else
|
Chris@16
|
464
|
Chris@16
|
465 template <typename T>
|
Chris@16
|
466 BOOST_UNORDERED_HAS_MEMBER(select_on_container_copy_construction);
|
Chris@16
|
467
|
Chris@16
|
468 template <typename T>
|
Chris@16
|
469 BOOST_UNORDERED_HAS_MEMBER(max_size);
|
Chris@16
|
470
|
Chris@16
|
471 template <typename T, typename ValueType>
|
Chris@16
|
472 BOOST_UNORDERED_HAS_MEMBER(construct);
|
Chris@16
|
473
|
Chris@16
|
474 template <typename T, typename ValueType>
|
Chris@16
|
475 BOOST_UNORDERED_HAS_MEMBER(destroy);
|
Chris@16
|
476
|
Chris@16
|
477 # endif
|
Chris@16
|
478
|
Chris@16
|
479 namespace func
|
Chris@16
|
480 {
|
Chris@16
|
481
|
Chris@16
|
482 template <typename Alloc>
|
Chris@16
|
483 inline Alloc call_select_on_container_copy_construction(const Alloc& rhs,
|
Chris@16
|
484 typename boost::enable_if_c<
|
Chris@16
|
485 boost::unordered::detail::
|
Chris@16
|
486 has_select_on_container_copy_construction<Alloc>::value, void*
|
Chris@16
|
487 >::type = 0)
|
Chris@16
|
488 {
|
Chris@16
|
489 return rhs.select_on_container_copy_construction();
|
Chris@16
|
490 }
|
Chris@16
|
491
|
Chris@16
|
492 template <typename Alloc>
|
Chris@16
|
493 inline Alloc call_select_on_container_copy_construction(const Alloc& rhs,
|
Chris@16
|
494 typename boost::disable_if_c<
|
Chris@16
|
495 boost::unordered::detail::
|
Chris@16
|
496 has_select_on_container_copy_construction<Alloc>::value, void*
|
Chris@16
|
497 >::type = 0)
|
Chris@16
|
498 {
|
Chris@16
|
499 return rhs;
|
Chris@16
|
500 }
|
Chris@16
|
501
|
Chris@16
|
502 template <typename SizeType, typename Alloc>
|
Chris@16
|
503 inline SizeType call_max_size(const Alloc& a,
|
Chris@16
|
504 typename boost::enable_if_c<
|
Chris@16
|
505 boost::unordered::detail::has_max_size<Alloc>::value, void*
|
Chris@16
|
506 >::type = 0)
|
Chris@16
|
507 {
|
Chris@16
|
508 return a.max_size();
|
Chris@16
|
509 }
|
Chris@16
|
510
|
Chris@16
|
511 template <typename SizeType, typename Alloc>
|
Chris@16
|
512 inline SizeType call_max_size(const Alloc&, typename boost::disable_if_c<
|
Chris@16
|
513 boost::unordered::detail::has_max_size<Alloc>::value, void*
|
Chris@16
|
514 >::type = 0)
|
Chris@16
|
515 {
|
Chris@16
|
516 return (std::numeric_limits<SizeType>::max)();
|
Chris@16
|
517 }
|
Chris@16
|
518
|
Chris@16
|
519 } // namespace func.
|
Chris@16
|
520
|
Chris@16
|
521 template <typename Alloc>
|
Chris@16
|
522 struct allocator_traits
|
Chris@16
|
523 {
|
Chris@16
|
524 typedef Alloc allocator_type;
|
Chris@16
|
525 typedef typename Alloc::value_type value_type;
|
Chris@16
|
526
|
Chris@16
|
527 typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, pointer, value_type*)
|
Chris@16
|
528 pointer;
|
Chris@16
|
529
|
Chris@16
|
530 template <typename T>
|
Chris@16
|
531 struct pointer_to_other : boost::pointer_to_other<pointer, T> {};
|
Chris@16
|
532
|
Chris@16
|
533 typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, const_pointer,
|
Chris@16
|
534 typename pointer_to_other<const value_type>::type)
|
Chris@16
|
535 const_pointer;
|
Chris@16
|
536
|
Chris@16
|
537 //typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, void_pointer,
|
Chris@16
|
538 // typename pointer_to_other<void>::type)
|
Chris@16
|
539 // void_pointer;
|
Chris@16
|
540 //
|
Chris@16
|
541 //typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, const_void_pointer,
|
Chris@16
|
542 // typename pointer_to_other<const void>::type)
|
Chris@16
|
543 // const_void_pointer;
|
Chris@16
|
544
|
Chris@16
|
545 typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, difference_type,
|
Chris@16
|
546 std::ptrdiff_t) difference_type;
|
Chris@16
|
547
|
Chris@16
|
548 typedef BOOST_UNORDERED_DEFAULT_TYPE(Alloc, size_type, std::size_t)
|
Chris@16
|
549 size_type;
|
Chris@16
|
550
|
Chris@16
|
551 // TODO: rebind_alloc and rebind_traits
|
Chris@16
|
552
|
Chris@16
|
553 static pointer allocate(Alloc& a, size_type n)
|
Chris@16
|
554 { return a.allocate(n); }
|
Chris@16
|
555
|
Chris@16
|
556 // I never use this, so I'll just comment it out for now.
|
Chris@16
|
557 //
|
Chris@16
|
558 //static pointer allocate(Alloc& a, size_type n,
|
Chris@16
|
559 // const_void_pointer hint)
|
Chris@16
|
560 // { return DEFAULT_FUNC(allocate, pointer)(a, n, hint); }
|
Chris@16
|
561
|
Chris@16
|
562 static void deallocate(Alloc& a, pointer p, size_type n)
|
Chris@16
|
563 { a.deallocate(p, n); }
|
Chris@16
|
564
|
Chris@16
|
565 public:
|
Chris@16
|
566
|
Chris@16
|
567 # if BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT
|
Chris@16
|
568
|
Chris@16
|
569 template <typename T, typename... Args>
|
Chris@16
|
570 static typename boost::enable_if_c<
|
Chris@16
|
571 boost::unordered::detail::has_construct<Alloc, T, Args...>
|
Chris@16
|
572 ::value>::type
|
Chris@16
|
573 construct(Alloc& a, T* p, BOOST_FWD_REF(Args)... x)
|
Chris@16
|
574 {
|
Chris@16
|
575 a.construct(p, boost::forward<Args>(x)...);
|
Chris@16
|
576 }
|
Chris@16
|
577
|
Chris@16
|
578 template <typename T, typename... Args>
|
Chris@16
|
579 static typename boost::disable_if_c<
|
Chris@16
|
580 boost::unordered::detail::has_construct<Alloc, T, Args...>
|
Chris@16
|
581 ::value>::type
|
Chris@16
|
582 construct(Alloc&, T* p, BOOST_FWD_REF(Args)... x)
|
Chris@16
|
583 {
|
Chris@16
|
584 new ((void*) p) T(boost::forward<Args>(x)...);
|
Chris@16
|
585 }
|
Chris@16
|
586
|
Chris@16
|
587 template <typename T>
|
Chris@16
|
588 static typename boost::enable_if_c<
|
Chris@16
|
589 boost::unordered::detail::has_destroy<Alloc, T>::value>::type
|
Chris@16
|
590 destroy(Alloc& a, T* p)
|
Chris@16
|
591 {
|
Chris@16
|
592 a.destroy(p);
|
Chris@16
|
593 }
|
Chris@16
|
594
|
Chris@16
|
595 template <typename T>
|
Chris@16
|
596 static typename boost::disable_if_c<
|
Chris@16
|
597 boost::unordered::detail::has_destroy<Alloc, T>::value>::type
|
Chris@16
|
598 destroy(Alloc&, T* p)
|
Chris@16
|
599 {
|
Chris@16
|
600 boost::unordered::detail::func::destroy(p);
|
Chris@16
|
601 }
|
Chris@16
|
602
|
Chris@16
|
603 # elif !defined(BOOST_NO_SFINAE_EXPR)
|
Chris@16
|
604
|
Chris@16
|
605 template <typename T>
|
Chris@16
|
606 static typename boost::enable_if_c<
|
Chris@16
|
607 boost::unordered::detail::has_construct<Alloc, T>::value>::type
|
Chris@16
|
608 construct(Alloc& a, T* p, T const& x)
|
Chris@16
|
609 {
|
Chris@16
|
610 a.construct(p, x);
|
Chris@16
|
611 }
|
Chris@16
|
612
|
Chris@16
|
613 template <typename T>
|
Chris@16
|
614 static typename boost::disable_if_c<
|
Chris@16
|
615 boost::unordered::detail::has_construct<Alloc, T>::value>::type
|
Chris@16
|
616 construct(Alloc&, T* p, T const& x)
|
Chris@16
|
617 {
|
Chris@16
|
618 new ((void*) p) T(x);
|
Chris@16
|
619 }
|
Chris@16
|
620
|
Chris@16
|
621 template <typename T>
|
Chris@16
|
622 static typename boost::enable_if_c<
|
Chris@16
|
623 boost::unordered::detail::has_destroy<Alloc, T>::value>::type
|
Chris@16
|
624 destroy(Alloc& a, T* p)
|
Chris@16
|
625 {
|
Chris@16
|
626 a.destroy(p);
|
Chris@16
|
627 }
|
Chris@16
|
628
|
Chris@16
|
629 template <typename T>
|
Chris@16
|
630 static typename boost::disable_if_c<
|
Chris@16
|
631 boost::unordered::detail::has_destroy<Alloc, T>::value>::type
|
Chris@16
|
632 destroy(Alloc&, T* p)
|
Chris@16
|
633 {
|
Chris@16
|
634 boost::unordered::detail::func::destroy(p);
|
Chris@16
|
635 }
|
Chris@16
|
636
|
Chris@16
|
637 # else
|
Chris@16
|
638
|
Chris@16
|
639 // If we don't have SFINAE expressions, only call construct for the
|
Chris@16
|
640 // copy constructor for the allocator's value_type - as that's
|
Chris@16
|
641 // the only construct method that old fashioned allocators support.
|
Chris@16
|
642
|
Chris@16
|
643 template <typename T>
|
Chris@16
|
644 static void construct(Alloc& a, T* p, T const& x,
|
Chris@16
|
645 typename boost::enable_if_c<
|
Chris@16
|
646 boost::unordered::detail::has_construct<Alloc, T>::value &&
|
Chris@16
|
647 boost::is_same<T, value_type>::value,
|
Chris@16
|
648 void*>::type = 0)
|
Chris@16
|
649 {
|
Chris@16
|
650 a.construct(p, x);
|
Chris@16
|
651 }
|
Chris@16
|
652
|
Chris@16
|
653 template <typename T>
|
Chris@16
|
654 static void construct(Alloc&, T* p, T const& x,
|
Chris@16
|
655 typename boost::disable_if_c<
|
Chris@16
|
656 boost::unordered::detail::has_construct<Alloc, T>::value &&
|
Chris@16
|
657 boost::is_same<T, value_type>::value,
|
Chris@16
|
658 void*>::type = 0)
|
Chris@16
|
659 {
|
Chris@16
|
660 new ((void*) p) T(x);
|
Chris@16
|
661 }
|
Chris@16
|
662
|
Chris@16
|
663 template <typename T>
|
Chris@16
|
664 static void destroy(Alloc& a, T* p,
|
Chris@16
|
665 typename boost::enable_if_c<
|
Chris@16
|
666 boost::unordered::detail::has_destroy<Alloc, T>::value &&
|
Chris@16
|
667 boost::is_same<T, value_type>::value,
|
Chris@16
|
668 void*>::type = 0)
|
Chris@16
|
669 {
|
Chris@16
|
670 a.destroy(p);
|
Chris@16
|
671 }
|
Chris@16
|
672
|
Chris@16
|
673 template <typename T>
|
Chris@16
|
674 static void destroy(Alloc&, T* p,
|
Chris@16
|
675 typename boost::disable_if_c<
|
Chris@16
|
676 boost::unordered::detail::has_destroy<Alloc, T>::value &&
|
Chris@16
|
677 boost::is_same<T, value_type>::value,
|
Chris@16
|
678 void*>::type = 0)
|
Chris@16
|
679 {
|
Chris@16
|
680 boost::unordered::detail::func::destroy(p);
|
Chris@16
|
681 }
|
Chris@16
|
682
|
Chris@16
|
683 # endif
|
Chris@16
|
684
|
Chris@16
|
685 static size_type max_size(const Alloc& a)
|
Chris@16
|
686 {
|
Chris@16
|
687 return boost::unordered::detail::func::
|
Chris@16
|
688 call_max_size<size_type>(a);
|
Chris@16
|
689 }
|
Chris@16
|
690
|
Chris@16
|
691 // Allocator propagation on construction
|
Chris@16
|
692
|
Chris@16
|
693 static Alloc select_on_container_copy_construction(Alloc const& rhs)
|
Chris@16
|
694 {
|
Chris@16
|
695 return boost::unordered::detail::func::
|
Chris@16
|
696 call_select_on_container_copy_construction(rhs);
|
Chris@16
|
697 }
|
Chris@16
|
698
|
Chris@16
|
699 // Allocator propagation on assignment and swap.
|
Chris@16
|
700 // Return true if lhs is modified.
|
Chris@16
|
701 typedef BOOST_UNORDERED_DEFAULT_TYPE(
|
Chris@16
|
702 Alloc, propagate_on_container_copy_assignment, false_type)
|
Chris@16
|
703 propagate_on_container_copy_assignment;
|
Chris@16
|
704 typedef BOOST_UNORDERED_DEFAULT_TYPE(
|
Chris@16
|
705 Alloc,propagate_on_container_move_assignment, false_type)
|
Chris@16
|
706 propagate_on_container_move_assignment;
|
Chris@16
|
707 typedef BOOST_UNORDERED_DEFAULT_TYPE(
|
Chris@16
|
708 Alloc,propagate_on_container_swap,false_type)
|
Chris@16
|
709 propagate_on_container_swap;
|
Chris@16
|
710 };
|
Chris@16
|
711 }}}
|
Chris@16
|
712
|
Chris@16
|
713 # undef BOOST_UNORDERED_DEFAULT_TYPE_TMPLT
|
Chris@16
|
714 # undef BOOST_UNORDERED_DEFAULT_TYPE
|
Chris@16
|
715
|
Chris@16
|
716 ////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
717 //
|
Chris@16
|
718 // std::allocator_traits
|
Chris@16
|
719
|
Chris@16
|
720 #elif BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 1
|
Chris@16
|
721
|
Chris@16
|
722 # include <memory>
|
Chris@16
|
723
|
Chris@16
|
724 # define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 1
|
Chris@16
|
725
|
Chris@16
|
726 namespace boost { namespace unordered { namespace detail {
|
Chris@16
|
727
|
Chris@16
|
728 template <typename Alloc>
|
Chris@16
|
729 struct allocator_traits : std::allocator_traits<Alloc> {};
|
Chris@16
|
730
|
Chris@16
|
731 template <typename Alloc, typename T>
|
Chris@16
|
732 struct rebind_wrap
|
Chris@16
|
733 {
|
Chris@16
|
734 typedef typename std::allocator_traits<Alloc>::
|
Chris@16
|
735 template rebind_alloc<T> type;
|
Chris@16
|
736 };
|
Chris@16
|
737 }}}
|
Chris@16
|
738
|
Chris@16
|
739 ////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
740 //
|
Chris@16
|
741 // boost::container::allocator_traits
|
Chris@16
|
742
|
Chris@16
|
743 #elif BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 2
|
Chris@16
|
744
|
Chris@16
|
745 # include <boost/container/allocator_traits.hpp>
|
Chris@16
|
746
|
Chris@16
|
747 # define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 0
|
Chris@16
|
748
|
Chris@16
|
749 namespace boost { namespace unordered { namespace detail {
|
Chris@16
|
750
|
Chris@16
|
751 template <typename Alloc>
|
Chris@16
|
752 struct allocator_traits :
|
Chris@16
|
753 boost::container::allocator_traits<Alloc> {};
|
Chris@16
|
754
|
Chris@16
|
755 template <typename Alloc, typename T>
|
Chris@16
|
756 struct rebind_wrap :
|
Chris@16
|
757 boost::container::allocator_traits<Alloc>::
|
Chris@16
|
758 template portable_rebind_alloc<T>
|
Chris@16
|
759 {};
|
Chris@16
|
760
|
Chris@16
|
761 }}}
|
Chris@16
|
762
|
Chris@16
|
763 #else
|
Chris@16
|
764
|
Chris@16
|
765 #error "Invalid BOOST_UNORDERED_USE_ALLOCATOR_TRAITS value."
|
Chris@16
|
766
|
Chris@16
|
767 #endif
|
Chris@16
|
768
|
Chris@16
|
769
|
Chris@16
|
770 namespace boost { namespace unordered { namespace detail { namespace func {
|
Chris@16
|
771
|
Chris@16
|
772 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
773 // call_construct
|
Chris@16
|
774
|
Chris@16
|
775 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
776
|
Chris@16
|
777 # if BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT
|
Chris@16
|
778
|
Chris@16
|
779 template <typename Alloc, typename T, typename... Args>
|
Chris@16
|
780 inline void call_construct(Alloc& alloc, T* address,
|
Chris@16
|
781 BOOST_FWD_REF(Args)... args)
|
Chris@16
|
782 {
|
Chris@16
|
783 boost::unordered::detail::allocator_traits<Alloc>::construct(alloc,
|
Chris@16
|
784 address, boost::forward<Args>(args)...);
|
Chris@16
|
785 }
|
Chris@16
|
786
|
Chris@16
|
787 template <typename Alloc, typename T>
|
Chris@16
|
788 inline void destroy_value_impl(Alloc& alloc, T* x) {
|
Chris@16
|
789 boost::unordered::detail::allocator_traits<Alloc>::destroy(alloc, x);
|
Chris@16
|
790 }
|
Chris@16
|
791
|
Chris@16
|
792
|
Chris@16
|
793 # else
|
Chris@16
|
794
|
Chris@16
|
795 template <typename Alloc, typename T, typename... Args>
|
Chris@16
|
796 inline void call_construct(Alloc&, T* address,
|
Chris@16
|
797 BOOST_FWD_REF(Args)... args)
|
Chris@16
|
798 {
|
Chris@16
|
799 new((void*) address) T(boost::forward<Args>(args)...);
|
Chris@16
|
800 }
|
Chris@16
|
801
|
Chris@16
|
802 template <typename Alloc, typename T>
|
Chris@16
|
803 inline void destroy_value_impl(Alloc&, T* x) {
|
Chris@16
|
804 boost::unordered::detail::func::destroy(x);
|
Chris@16
|
805 }
|
Chris@16
|
806
|
Chris@16
|
807
|
Chris@16
|
808 # endif
|
Chris@16
|
809
|
Chris@16
|
810 #else
|
Chris@16
|
811
|
Chris@16
|
812 template <typename Alloc, typename T>
|
Chris@16
|
813 inline void destroy_value_impl(Alloc&, T* x) {
|
Chris@16
|
814 boost::unordered::detail::func::destroy(x);
|
Chris@16
|
815 }
|
Chris@16
|
816
|
Chris@16
|
817 #endif
|
Chris@16
|
818
|
Chris@16
|
819 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
820 // Construct from tuple
|
Chris@16
|
821 //
|
Chris@16
|
822 // Used for piecewise construction.
|
Chris@16
|
823
|
Chris@16
|
824 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
825
|
Chris@16
|
826 # define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \
|
Chris@16
|
827 template<typename Alloc, typename T> \
|
Chris@16
|
828 void construct_from_tuple(Alloc& alloc, T* ptr, namespace_ tuple<>) \
|
Chris@16
|
829 { \
|
Chris@16
|
830 boost::unordered::detail::func::call_construct(alloc, ptr); \
|
Chris@16
|
831 } \
|
Chris@16
|
832 \
|
Chris@16
|
833 BOOST_PP_REPEAT_FROM_TO(1, n, \
|
Chris@16
|
834 BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_)
|
Chris@16
|
835
|
Chris@16
|
836 # define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \
|
Chris@16
|
837 template<typename Alloc, typename T, \
|
Chris@16
|
838 BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
Chris@16
|
839 void construct_from_tuple(Alloc& alloc, T* ptr, \
|
Chris@16
|
840 namespace_ tuple<BOOST_PP_ENUM_PARAMS_Z(z, n, A)> const& x) \
|
Chris@16
|
841 { \
|
Chris@16
|
842 boost::unordered::detail::func::call_construct(alloc, ptr, \
|
Chris@16
|
843 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_) \
|
Chris@16
|
844 ); \
|
Chris@16
|
845 }
|
Chris@16
|
846
|
Chris@16
|
847 # define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) \
|
Chris@16
|
848 namespace_ get<n>(x)
|
Chris@16
|
849
|
Chris@16
|
850 #elif !defined(__SUNPRO_CC)
|
Chris@16
|
851
|
Chris@16
|
852 # define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \
|
Chris@16
|
853 template<typename Alloc, typename T> \
|
Chris@16
|
854 void construct_from_tuple(Alloc&, T* ptr, namespace_ tuple<>) \
|
Chris@16
|
855 { \
|
Chris@16
|
856 new ((void*) ptr) T(); \
|
Chris@16
|
857 } \
|
Chris@16
|
858 \
|
Chris@16
|
859 BOOST_PP_REPEAT_FROM_TO(1, n, \
|
Chris@16
|
860 BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_)
|
Chris@16
|
861
|
Chris@16
|
862 # define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \
|
Chris@16
|
863 template<typename Alloc, typename T, \
|
Chris@16
|
864 BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
Chris@16
|
865 void construct_from_tuple(Alloc&, T* ptr, \
|
Chris@16
|
866 namespace_ tuple<BOOST_PP_ENUM_PARAMS_Z(z, n, A)> const& x) \
|
Chris@16
|
867 { \
|
Chris@16
|
868 new ((void*) ptr) T( \
|
Chris@16
|
869 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_) \
|
Chris@16
|
870 ); \
|
Chris@16
|
871 }
|
Chris@16
|
872
|
Chris@16
|
873 # define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) \
|
Chris@16
|
874 namespace_ get<n>(x)
|
Chris@16
|
875
|
Chris@16
|
876 #else
|
Chris@16
|
877
|
Chris@16
|
878 template <int N> struct length {};
|
Chris@16
|
879
|
Chris@16
|
880 # define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \
|
Chris@16
|
881 template<typename Alloc, typename T> \
|
Chris@16
|
882 void construct_from_tuple_impl( \
|
Chris@101
|
883 boost::unordered::detail::func::length<0>, Alloc&, T* ptr, \
|
Chris@16
|
884 namespace_ tuple<>) \
|
Chris@16
|
885 { \
|
Chris@16
|
886 new ((void*) ptr) T(); \
|
Chris@16
|
887 } \
|
Chris@16
|
888 \
|
Chris@16
|
889 BOOST_PP_REPEAT_FROM_TO(1, n, \
|
Chris@16
|
890 BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_)
|
Chris@16
|
891
|
Chris@16
|
892 # define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \
|
Chris@16
|
893 template<typename Alloc, typename T, \
|
Chris@16
|
894 BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
|
Chris@16
|
895 void construct_from_tuple_impl( \
|
Chris@101
|
896 boost::unordered::detail::func::length<n>, Alloc&, T* ptr, \
|
Chris@16
|
897 namespace_ tuple<BOOST_PP_ENUM_PARAMS_Z(z, n, A)> const& x) \
|
Chris@16
|
898 { \
|
Chris@16
|
899 new ((void*) ptr) T( \
|
Chris@16
|
900 BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_) \
|
Chris@16
|
901 ); \
|
Chris@16
|
902 }
|
Chris@16
|
903
|
Chris@16
|
904 # define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) \
|
Chris@16
|
905 namespace_ get<n>(x)
|
Chris@16
|
906
|
Chris@16
|
907 #endif
|
Chris@16
|
908
|
Chris@16
|
909 BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
|
Chris@16
|
910
|
Chris@16
|
911 #if !defined(__SUNPRO_CC) && !defined(BOOST_NO_CXX11_HDR_TUPLE)
|
Chris@16
|
912 BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, std::)
|
Chris@16
|
913 #endif
|
Chris@16
|
914
|
Chris@16
|
915 #undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE
|
Chris@16
|
916 #undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL
|
Chris@16
|
917 #undef BOOST_UNORDERED_GET_TUPLE_ARG
|
Chris@16
|
918
|
Chris@16
|
919 #if defined(__SUNPRO_CC)
|
Chris@16
|
920
|
Chris@16
|
921 template <typename Alloc, typename T, typename Tuple>
|
Chris@16
|
922 void construct_from_tuple(Alloc& alloc, T* ptr, Tuple const& x)
|
Chris@16
|
923 {
|
Chris@16
|
924 construct_from_tuple_impl(
|
Chris@101
|
925 boost::unordered::detail::func::length<
|
Chris@16
|
926 boost::tuples::length<Tuple>::value>(),
|
Chris@16
|
927 alloc, ptr, x);
|
Chris@16
|
928 }
|
Chris@16
|
929
|
Chris@16
|
930 #endif
|
Chris@16
|
931
|
Chris@16
|
932 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
933 // Trait to check for piecewise construction.
|
Chris@16
|
934
|
Chris@16
|
935 template <typename A0>
|
Chris@16
|
936 struct use_piecewise {
|
Chris@16
|
937 static choice1::type test(choice1,
|
Chris@16
|
938 boost::unordered::piecewise_construct_t);
|
Chris@16
|
939
|
Chris@16
|
940 static choice2::type test(choice2, ...);
|
Chris@16
|
941
|
Chris@16
|
942 enum { value = sizeof(choice1::type) ==
|
Chris@16
|
943 sizeof(test(choose(), boost::unordered::detail::make<A0>())) };
|
Chris@16
|
944 };
|
Chris@16
|
945
|
Chris@16
|
946 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
947
|
Chris@16
|
948 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
949 // Construct from variadic parameters
|
Chris@16
|
950
|
Chris@16
|
951 // For the standard pair constructor.
|
Chris@16
|
952
|
Chris@16
|
953 template <typename Alloc, typename T, typename... Args>
|
Chris@16
|
954 inline void construct_value_impl(Alloc& alloc, T* address,
|
Chris@16
|
955 BOOST_FWD_REF(Args)... args)
|
Chris@16
|
956 {
|
Chris@16
|
957 boost::unordered::detail::func::call_construct(alloc,
|
Chris@16
|
958 address, boost::forward<Args>(args)...);
|
Chris@16
|
959 }
|
Chris@16
|
960
|
Chris@16
|
961 // Special case for piece_construct
|
Chris@16
|
962 //
|
Chris@16
|
963 // TODO: When possible, it might be better to use std::pair's
|
Chris@16
|
964 // constructor for std::piece_construct with std::tuple.
|
Chris@16
|
965
|
Chris@16
|
966 template <typename Alloc, typename A, typename B,
|
Chris@16
|
967 typename A0, typename A1, typename A2>
|
Chris@16
|
968 inline typename enable_if<use_piecewise<A0>, void>::type
|
Chris@16
|
969 construct_value_impl(Alloc& alloc, std::pair<A, B>* address,
|
Chris@16
|
970 BOOST_FWD_REF(A0), BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
|
Chris@16
|
971 {
|
Chris@16
|
972 boost::unordered::detail::func::construct_from_tuple(alloc,
|
Chris@16
|
973 boost::addressof(address->first), boost::forward<A1>(a1));
|
Chris@16
|
974 boost::unordered::detail::func::construct_from_tuple(alloc,
|
Chris@16
|
975 boost::addressof(address->second), boost::forward<A2>(a2));
|
Chris@16
|
976 }
|
Chris@16
|
977
|
Chris@16
|
978 #else // BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
Chris@16
|
979
|
Chris@16
|
980 ////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
981 // Construct from emplace_args
|
Chris@16
|
982
|
Chris@16
|
983 // Explicitly write out first three overloads for the sake of sane
|
Chris@16
|
984 // error messages.
|
Chris@16
|
985
|
Chris@16
|
986 template <typename Alloc, typename T, typename A0>
|
Chris@16
|
987 inline void construct_value_impl(Alloc&, T* address,
|
Chris@16
|
988 emplace_args1<A0> const& args)
|
Chris@16
|
989 {
|
Chris@16
|
990 new((void*) address) T(boost::forward<A0>(args.a0));
|
Chris@16
|
991 }
|
Chris@16
|
992
|
Chris@16
|
993 template <typename Alloc, typename T, typename A0, typename A1>
|
Chris@16
|
994 inline void construct_value_impl(Alloc&, T* address,
|
Chris@16
|
995 emplace_args2<A0, A1> const& args)
|
Chris@16
|
996 {
|
Chris@16
|
997 new((void*) address) T(
|
Chris@16
|
998 boost::forward<A0>(args.a0),
|
Chris@16
|
999 boost::forward<A1>(args.a1)
|
Chris@16
|
1000 );
|
Chris@16
|
1001 }
|
Chris@16
|
1002
|
Chris@16
|
1003 template <typename Alloc, typename T, typename A0, typename A1, typename A2>
|
Chris@16
|
1004 inline void construct_value_impl(Alloc&, T* address,
|
Chris@16
|
1005 emplace_args3<A0, A1, A2> const& args)
|
Chris@16
|
1006 {
|
Chris@16
|
1007 new((void*) address) T(
|
Chris@16
|
1008 boost::forward<A0>(args.a0),
|
Chris@16
|
1009 boost::forward<A1>(args.a1),
|
Chris@16
|
1010 boost::forward<A2>(args.a2)
|
Chris@16
|
1011 );
|
Chris@16
|
1012 }
|
Chris@16
|
1013
|
Chris@16
|
1014 // Use a macro for the rest.
|
Chris@16
|
1015
|
Chris@16
|
1016 #define BOOST_UNORDERED_CONSTRUCT_IMPL(z, num_params, _) \
|
Chris@16
|
1017 template < \
|
Chris@16
|
1018 typename Alloc, typename T, \
|
Chris@16
|
1019 BOOST_PP_ENUM_PARAMS_Z(z, num_params, typename A) \
|
Chris@16
|
1020 > \
|
Chris@16
|
1021 inline void construct_value_impl(Alloc&, T* address, \
|
Chris@16
|
1022 boost::unordered::detail::BOOST_PP_CAT(emplace_args,num_params) < \
|
Chris@16
|
1023 BOOST_PP_ENUM_PARAMS_Z(z, num_params, A) \
|
Chris@16
|
1024 > const& args) \
|
Chris@16
|
1025 { \
|
Chris@16
|
1026 new((void*) address) T( \
|
Chris@16
|
1027 BOOST_PP_ENUM_##z(num_params, BOOST_UNORDERED_CALL_FORWARD, \
|
Chris@16
|
1028 args.a)); \
|
Chris@16
|
1029 }
|
Chris@16
|
1030
|
Chris@16
|
1031 BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT,
|
Chris@16
|
1032 BOOST_UNORDERED_CONSTRUCT_IMPL, _)
|
Chris@16
|
1033
|
Chris@16
|
1034 #undef BOOST_UNORDERED_CONSTRUCT_IMPL
|
Chris@16
|
1035
|
Chris@16
|
1036 // Construct with piece_construct
|
Chris@16
|
1037
|
Chris@16
|
1038 template <typename Alloc, typename A, typename B,
|
Chris@16
|
1039 typename A0, typename A1, typename A2>
|
Chris@16
|
1040 inline void construct_value_impl(Alloc& alloc, std::pair<A, B>* address,
|
Chris@16
|
1041 boost::unordered::detail::emplace_args3<A0, A1, A2> const& args,
|
Chris@16
|
1042 typename enable_if<use_piecewise<A0>, void*>::type = 0)
|
Chris@16
|
1043 {
|
Chris@16
|
1044 boost::unordered::detail::func::construct_from_tuple(alloc,
|
Chris@16
|
1045 boost::addressof(address->first), args.a1);
|
Chris@16
|
1046 boost::unordered::detail::func::construct_from_tuple(alloc,
|
Chris@16
|
1047 boost::addressof(address->second), args.a2);
|
Chris@16
|
1048 }
|
Chris@16
|
1049
|
Chris@16
|
1050 #endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
Chris@16
|
1051
|
Chris@16
|
1052 }}}}
|
Chris@16
|
1053
|
Chris@16
|
1054 namespace boost { namespace unordered { namespace detail {
|
Chris@16
|
1055
|
Chris@16
|
1056 ////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
1057 //
|
Chris@16
|
1058 // array_constructor
|
Chris@16
|
1059 //
|
Chris@16
|
1060 // Allocate and construct an array in an exception safe manner, and
|
Chris@16
|
1061 // clean up if an exception is thrown before the container takes charge
|
Chris@16
|
1062 // of it.
|
Chris@16
|
1063
|
Chris@16
|
1064 template <typename Allocator>
|
Chris@16
|
1065 struct array_constructor
|
Chris@16
|
1066 {
|
Chris@16
|
1067 typedef boost::unordered::detail::allocator_traits<Allocator> traits;
|
Chris@16
|
1068 typedef typename traits::pointer pointer;
|
Chris@16
|
1069
|
Chris@16
|
1070 Allocator& alloc_;
|
Chris@16
|
1071 pointer ptr_;
|
Chris@16
|
1072 pointer constructed_;
|
Chris@16
|
1073 std::size_t length_;
|
Chris@16
|
1074
|
Chris@16
|
1075 array_constructor(Allocator& a)
|
Chris@16
|
1076 : alloc_(a), ptr_(), constructed_(), length_(0)
|
Chris@16
|
1077 {
|
Chris@16
|
1078 constructed_ = pointer();
|
Chris@16
|
1079 ptr_ = pointer();
|
Chris@16
|
1080 }
|
Chris@16
|
1081
|
Chris@16
|
1082 ~array_constructor() {
|
Chris@16
|
1083 if (ptr_) {
|
Chris@101
|
1084 for(pointer p = ptr_; p != constructed_; ++p) {
|
Chris@101
|
1085 boost::unordered::detail::func::destroy(
|
Chris@101
|
1086 boost::addressof(*p));
|
Chris@101
|
1087 }
|
Chris@16
|
1088
|
Chris@16
|
1089 traits::deallocate(alloc_, ptr_, length_);
|
Chris@16
|
1090 }
|
Chris@16
|
1091 }
|
Chris@16
|
1092
|
Chris@16
|
1093 template <typename V>
|
Chris@16
|
1094 void construct(V const& v, std::size_t l)
|
Chris@16
|
1095 {
|
Chris@16
|
1096 BOOST_ASSERT(!ptr_);
|
Chris@16
|
1097 length_ = l;
|
Chris@16
|
1098 ptr_ = traits::allocate(alloc_, length_);
|
Chris@16
|
1099 pointer end = ptr_ + static_cast<std::ptrdiff_t>(length_);
|
Chris@101
|
1100 for(constructed_ = ptr_; constructed_ != end; ++constructed_) {
|
Chris@101
|
1101 new ((void*) boost::addressof(*constructed_)) V(v);
|
Chris@101
|
1102 }
|
Chris@16
|
1103 }
|
Chris@16
|
1104
|
Chris@16
|
1105 pointer get() const
|
Chris@16
|
1106 {
|
Chris@16
|
1107 return ptr_;
|
Chris@16
|
1108 }
|
Chris@16
|
1109
|
Chris@16
|
1110 pointer release()
|
Chris@16
|
1111 {
|
Chris@16
|
1112 pointer p(ptr_);
|
Chris@16
|
1113 ptr_ = pointer();
|
Chris@16
|
1114 return p;
|
Chris@16
|
1115 }
|
Chris@16
|
1116
|
Chris@16
|
1117 private:
|
Chris@16
|
1118
|
Chris@16
|
1119 array_constructor(array_constructor const&);
|
Chris@16
|
1120 array_constructor& operator=(array_constructor const&);
|
Chris@16
|
1121 };
|
Chris@16
|
1122 }}}
|
Chris@16
|
1123
|
Chris@16
|
1124 #if defined(BOOST_MSVC)
|
Chris@16
|
1125 #pragma warning(pop)
|
Chris@16
|
1126 #endif
|
Chris@16
|
1127
|
Chris@16
|
1128 #endif
|