Chris@16
|
1 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Pablo Halpern 2009. Distributed under the Boost
|
Chris@16
|
4 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 //
|
Chris@16
|
7 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
8 //
|
Chris@16
|
9 // (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost
|
Chris@16
|
10 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
11 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
12 //
|
Chris@16
|
13 // See http://www.boost.org/libs/container for documentation.
|
Chris@16
|
14 //
|
Chris@16
|
15 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
16
|
Chris@16
|
17 #ifndef BOOST_CONTAINER_ALLOCATOR_ALLOCATOR_TRAITS_HPP
|
Chris@16
|
18 #define BOOST_CONTAINER_ALLOCATOR_ALLOCATOR_TRAITS_HPP
|
Chris@16
|
19
|
Chris@16
|
20 #if defined(_MSC_VER)
|
Chris@16
|
21 # pragma once
|
Chris@16
|
22 #endif
|
Chris@16
|
23
|
Chris@16
|
24 #include <boost/container/detail/config_begin.hpp>
|
Chris@16
|
25 #include <boost/container/detail/workaround.hpp>
|
Chris@16
|
26 #include <boost/container/container_fwd.hpp>
|
Chris@16
|
27 #include <boost/intrusive/pointer_traits.hpp>
|
Chris@16
|
28 #include <boost/intrusive/detail/memory_util.hpp>
|
Chris@16
|
29 #include <boost/container/detail/memory_util.hpp>
|
Chris@16
|
30 #include <boost/type_traits/integral_constant.hpp>
|
Chris@16
|
31 #include <boost/container/detail/mpl.hpp>
|
Chris@16
|
32 #include <boost/move/utility.hpp>
|
Chris@16
|
33 #include <limits> //numeric_limits<>::max()
|
Chris@16
|
34 #include <new> //placement new
|
Chris@16
|
35 #include <memory> //std::allocator
|
Chris@16
|
36
|
Chris@16
|
37 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
38 #include <boost/container/detail/preprocessor.hpp>
|
Chris@16
|
39 #endif
|
Chris@16
|
40
|
Chris@16
|
41 ///@cond
|
Chris@16
|
42
|
Chris@16
|
43 namespace boost {
|
Chris@16
|
44 namespace container {
|
Chris@16
|
45 namespace container_detail {
|
Chris@16
|
46
|
Chris@16
|
47 //workaround needed for C++03 compilers with no construct()
|
Chris@16
|
48 //supporting rvalue references
|
Chris@16
|
49 template<class A>
|
Chris@16
|
50 struct is_std_allocator
|
Chris@16
|
51 { static const bool value = false; };
|
Chris@16
|
52
|
Chris@16
|
53 template<class T>
|
Chris@16
|
54 struct is_std_allocator< std::allocator<T> >
|
Chris@16
|
55 { static const bool value = true; };
|
Chris@16
|
56
|
Chris@16
|
57 } //namespace container_detail {
|
Chris@16
|
58
|
Chris@16
|
59 ///@endcond
|
Chris@16
|
60
|
Chris@16
|
61 //! The class template allocator_traits supplies a uniform interface to all allocator types.
|
Chris@16
|
62 //! This class is a C++03-compatible implementation of std::allocator_traits
|
Chris@16
|
63 template <typename Alloc>
|
Chris@16
|
64 struct allocator_traits
|
Chris@16
|
65 {
|
Chris@16
|
66 //allocator_type
|
Chris@16
|
67 typedef Alloc allocator_type;
|
Chris@16
|
68 //value_type
|
Chris@16
|
69 typedef typename Alloc::value_type value_type;
|
Chris@16
|
70
|
Chris@16
|
71 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
Chris@16
|
72 //! Alloc::pointer if such a type exists; otherwise, value_type*
|
Chris@16
|
73 //!
|
Chris@16
|
74 typedef unspecified pointer;
|
Chris@16
|
75 //! Alloc::const_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const
|
Chris@16
|
76 //!
|
Chris@16
|
77 typedef see_documentation const_pointer;
|
Chris@16
|
78 //! Non-standard extension
|
Chris@16
|
79 //! Alloc::reference if such a type exists; otherwise, value_type&
|
Chris@16
|
80 typedef see_documentation reference;
|
Chris@16
|
81 //! Non-standard extension
|
Chris@16
|
82 //! Alloc::const_reference if such a type exists ; otherwise, const value_type&
|
Chris@16
|
83 typedef see_documentation const_reference;
|
Chris@16
|
84 //! Alloc::void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<void>.
|
Chris@16
|
85 //!
|
Chris@16
|
86 typedef see_documentation void_pointer;
|
Chris@16
|
87 //! Alloc::const_void_pointer if such a type exists ; otherwis e, pointer_traits<pointer>::rebind<const
|
Chris@16
|
88 //!
|
Chris@16
|
89 typedef see_documentation const_void_pointer;
|
Chris@16
|
90 //! Alloc::difference_type if such a type exists ; otherwise, pointer_traits<pointer>::difference_type.
|
Chris@16
|
91 //!
|
Chris@16
|
92 typedef see_documentation difference_type;
|
Chris@16
|
93 //! Alloc::size_type if such a type exists ; otherwise, make_unsigned<difference_type>::type
|
Chris@16
|
94 //!
|
Chris@16
|
95 typedef see_documentation size_type;
|
Chris@16
|
96 //! Alloc::propagate_on_container_copy_assignment if such a type exists, otherwise an integral_constant
|
Chris@16
|
97 //! type with internal constant static member `value` == false.
|
Chris@16
|
98 typedef see_documentation propagate_on_container_copy_assignment;
|
Chris@16
|
99 //! Alloc::propagate_on_container_move_assignment if such a type exists, otherwise an integral_constant
|
Chris@16
|
100 //! type with internal constant static member `value` == false.
|
Chris@16
|
101 typedef see_documentation propagate_on_container_move_assignment;
|
Chris@16
|
102 //! Alloc::propagate_on_container_swap if such a type exists, otherwise an integral_constant
|
Chris@16
|
103 //! type with internal constant static member `value` == false.
|
Chris@16
|
104 typedef see_documentation propagate_on_container_swap;
|
Chris@16
|
105 //! Defines an allocator: Alloc::rebind<T>::other if such a type exists; otherwise, Alloc<T, Args>
|
Chris@16
|
106 //! if Alloc is a class template instantiation of the form Alloc<U, Args>, where Args is zero or
|
Chris@16
|
107 //! more type arguments ; otherwise, the instantiation of rebind_alloc is ill-formed.
|
Chris@16
|
108 //!
|
Chris@16
|
109 //! In C++03 compilers `rebind_alloc` is a struct derived from an allocator
|
Chris@16
|
110 //! deduced by previously detailed rules.
|
Chris@16
|
111 template <class T> using rebind_alloc = see_documentation;
|
Chris@16
|
112
|
Chris@16
|
113 //! In C++03 compilers `rebind_traits` is a struct derived from
|
Chris@16
|
114 //! `allocator_traits<OtherAlloc>`, where `OtherAlloc` is
|
Chris@16
|
115 //! the allocator deduced by rules explained in `rebind_alloc`.
|
Chris@16
|
116 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T> >;
|
Chris@16
|
117
|
Chris@16
|
118 //! Non-standard extension: Portable allocator rebind for C++03 and C++11 compilers.
|
Chris@16
|
119 //! `type` is an allocator related to Alloc deduced deduced by rules explained in `rebind_alloc`.
|
Chris@16
|
120 template <class T>
|
Chris@16
|
121 struct portable_rebind_alloc
|
Chris@16
|
122 { typedef see_documentation type; };
|
Chris@16
|
123 #else
|
Chris@16
|
124 //pointer
|
Chris@16
|
125 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
126 pointer, value_type*)
|
Chris@16
|
127 pointer;
|
Chris@16
|
128 //const_pointer
|
Chris@16
|
129 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
130 const_pointer, typename boost::intrusive::pointer_traits<pointer>::template
|
Chris@16
|
131 rebind_pointer<const value_type>)
|
Chris@16
|
132 const_pointer;
|
Chris@16
|
133 //reference
|
Chris@16
|
134 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
135 reference, typename container_detail::unvoid<value_type>::type&)
|
Chris@16
|
136 reference;
|
Chris@16
|
137 //const_reference
|
Chris@16
|
138 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
139 const_reference, const typename container_detail::unvoid<value_type>::type&)
|
Chris@16
|
140 const_reference;
|
Chris@16
|
141 //void_pointer
|
Chris@16
|
142 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
143 void_pointer, typename boost::intrusive::pointer_traits<pointer>::template
|
Chris@16
|
144 rebind_pointer<void>)
|
Chris@16
|
145 void_pointer;
|
Chris@16
|
146 //const_void_pointer
|
Chris@16
|
147 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
148 const_void_pointer, typename boost::intrusive::pointer_traits<pointer>::template
|
Chris@16
|
149 rebind_pointer<const void>)
|
Chris@16
|
150 const_void_pointer;
|
Chris@16
|
151 //difference_type
|
Chris@16
|
152 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
153 difference_type, std::ptrdiff_t)
|
Chris@16
|
154 difference_type;
|
Chris@16
|
155 //size_type
|
Chris@16
|
156 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
157 size_type, std::size_t)
|
Chris@16
|
158 size_type;
|
Chris@16
|
159 //propagate_on_container_copy_assignment
|
Chris@16
|
160 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
161 propagate_on_container_copy_assignment, boost::false_type)
|
Chris@16
|
162 propagate_on_container_copy_assignment;
|
Chris@16
|
163 //propagate_on_container_move_assignment
|
Chris@16
|
164 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
165 propagate_on_container_move_assignment, boost::false_type)
|
Chris@16
|
166 propagate_on_container_move_assignment;
|
Chris@16
|
167 //propagate_on_container_swap
|
Chris@16
|
168 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::container_detail::, Alloc,
|
Chris@16
|
169 propagate_on_container_swap, boost::false_type)
|
Chris@16
|
170 propagate_on_container_swap;
|
Chris@16
|
171
|
Chris@16
|
172 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
Chris@16
|
173 //C++11
|
Chris@16
|
174 template <typename T> using rebind_alloc = typename boost::intrusive::detail::type_rebinder<Alloc, T>::type;
|
Chris@16
|
175 template <typename T> using rebind_traits = allocator_traits< rebind_alloc<T> >;
|
Chris@16
|
176 #else // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
Chris@16
|
177 //Some workaround for C++03 or C++11 compilers with no template aliases
|
Chris@16
|
178 template <typename T>
|
Chris@16
|
179 struct rebind_alloc : boost::intrusive::detail::type_rebinder<Alloc,T>::type
|
Chris@16
|
180 {
|
Chris@16
|
181 typedef typename boost::intrusive::detail::type_rebinder<Alloc,T>::type Base;
|
Chris@16
|
182 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
183 template <typename... Args>
|
Chris@16
|
184 rebind_alloc(BOOST_FWD_REF(Args)... args)
|
Chris@16
|
185 : Base(boost::forward<Args>(args)...)
|
Chris@16
|
186 {}
|
Chris@16
|
187 #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
188 #define BOOST_PP_LOCAL_MACRO(n) \
|
Chris@16
|
189 BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
|
Chris@16
|
190 rebind_alloc(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
|
Chris@16
|
191 : Base(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)) \
|
Chris@16
|
192 {} \
|
Chris@16
|
193 //
|
Chris@16
|
194 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
|
Chris@16
|
195 #include BOOST_PP_LOCAL_ITERATE()
|
Chris@16
|
196 #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
197 };
|
Chris@16
|
198
|
Chris@16
|
199 template <typename T>
|
Chris@16
|
200 struct rebind_traits
|
Chris@16
|
201 : allocator_traits<typename boost::intrusive::detail::type_rebinder<Alloc, T>::type>
|
Chris@16
|
202 {};
|
Chris@16
|
203 #endif // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
Chris@16
|
204 template <class T>
|
Chris@16
|
205 struct portable_rebind_alloc
|
Chris@16
|
206 { typedef typename boost::intrusive::detail::type_rebinder<Alloc, T>::type type; };
|
Chris@16
|
207 #endif //BOOST_CONTAINER_DOXYGEN_INVOKED
|
Chris@16
|
208
|
Chris@16
|
209 //! <b>Returns</b>: `a.allocate(n)`
|
Chris@16
|
210 //!
|
Chris@16
|
211 static pointer allocate(Alloc &a, size_type n)
|
Chris@16
|
212 { return a.allocate(n); }
|
Chris@16
|
213
|
Chris@16
|
214 //! <b>Returns</b>: `a.deallocate(p, n)`
|
Chris@16
|
215 //!
|
Chris@16
|
216 //! <b>Throws</b>: Nothing
|
Chris@16
|
217 static void deallocate(Alloc &a, pointer p, size_type n)
|
Chris@16
|
218 { a.deallocate(p, n); }
|
Chris@16
|
219
|
Chris@16
|
220 //! <b>Effects</b>: calls `a.allocate(n, p)` if that call is well-formed;
|
Chris@16
|
221 //! otherwise, invokes `a.allocate(n)`
|
Chris@16
|
222 static pointer allocate(Alloc &a, size_type n, const_void_pointer p)
|
Chris@16
|
223 {
|
Chris@16
|
224 const bool value = boost::container::container_detail::
|
Chris@16
|
225 has_member_function_callable_with_allocate
|
Chris@16
|
226 <Alloc, const size_type, const const_void_pointer>::value;
|
Chris@16
|
227 ::boost::integral_constant<bool, value> flag;
|
Chris@16
|
228 return allocator_traits::priv_allocate(flag, a, n, p);
|
Chris@16
|
229 }
|
Chris@16
|
230
|
Chris@16
|
231 //! <b>Effects</b>: calls `a.destroy(p)` if that call is well-formed;
|
Chris@16
|
232 //! otherwise, invokes `p->~T()`.
|
Chris@16
|
233 template<class T>
|
Chris@16
|
234 static void destroy(Alloc &a, T*p)
|
Chris@16
|
235 {
|
Chris@16
|
236 typedef T* destroy_pointer;
|
Chris@16
|
237 const bool value = boost::container::container_detail::
|
Chris@16
|
238 has_member_function_callable_with_destroy
|
Chris@16
|
239 <Alloc, const destroy_pointer>::value;
|
Chris@16
|
240 ::boost::integral_constant<bool, value> flag;
|
Chris@16
|
241 allocator_traits::priv_destroy(flag, a, p);
|
Chris@16
|
242 }
|
Chris@16
|
243
|
Chris@16
|
244 //! <b>Returns</b>: `a.max_size()` if that expression is well-formed; otherwise,
|
Chris@16
|
245 //! `numeric_limits<size_type>::max()`.
|
Chris@16
|
246 static size_type max_size(const Alloc &a)
|
Chris@16
|
247 {
|
Chris@16
|
248 const bool value = boost::container::container_detail::
|
Chris@16
|
249 has_member_function_callable_with_max_size
|
Chris@16
|
250 <const Alloc>::value;
|
Chris@16
|
251 ::boost::integral_constant<bool, value> flag;
|
Chris@16
|
252 return allocator_traits::priv_max_size(flag, a);
|
Chris@16
|
253 }
|
Chris@16
|
254
|
Chris@16
|
255 //! <b>Returns</b>: `a.select_on_container_copy_construction()` if that expression is well-formed;
|
Chris@16
|
256 //! otherwise, a.
|
Chris@16
|
257 static
|
Chris@16
|
258 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
Chris@16
|
259 typename container_detail::if_c
|
Chris@16
|
260 < boost::container::container_detail::
|
Chris@16
|
261 has_member_function_callable_with_select_on_container_copy_construction
|
Chris@16
|
262 <const Alloc>::value
|
Chris@16
|
263 , Alloc
|
Chris@16
|
264 , const Alloc &
|
Chris@16
|
265 >::type
|
Chris@16
|
266 #else
|
Chris@16
|
267 Alloc
|
Chris@16
|
268 #endif
|
Chris@16
|
269 select_on_container_copy_construction(const Alloc &a)
|
Chris@16
|
270 {
|
Chris@16
|
271 const bool value = boost::container::container_detail::
|
Chris@16
|
272 has_member_function_callable_with_select_on_container_copy_construction
|
Chris@16
|
273 <const Alloc>::value;
|
Chris@16
|
274 ::boost::integral_constant<bool, value> flag;
|
Chris@16
|
275 return allocator_traits::priv_select_on_container_copy_construction(flag, a);
|
Chris@16
|
276 }
|
Chris@16
|
277
|
Chris@16
|
278 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
Chris@16
|
279 //! <b>Effects</b>: calls `a.construct(p, std::forward<Args>(args)...)` if that call is well-formed;
|
Chris@16
|
280 //! otherwise, invokes `::new (static_cast<void*>(p)) T(std::forward<Args>(args)...)`
|
Chris@16
|
281 template <class T, class ...Args>
|
Chris@16
|
282 static void construct(Alloc & a, T* p, BOOST_FWD_REF(Args)... args)
|
Chris@16
|
283 {
|
Chris@16
|
284 ::boost::integral_constant<bool, container_detail::is_std_allocator<Alloc>::value> flag;
|
Chris@16
|
285 allocator_traits::priv_construct(flag, a, p, ::boost::forward<Args>(args)...);
|
Chris@16
|
286 }
|
Chris@16
|
287 #endif
|
Chris@16
|
288 ///@cond
|
Chris@16
|
289 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
Chris@16
|
290 private:
|
Chris@16
|
291 static pointer priv_allocate(boost::true_type, Alloc &a, size_type n, const_void_pointer p)
|
Chris@16
|
292 { return a.allocate(n, p); }
|
Chris@16
|
293
|
Chris@16
|
294 static pointer priv_allocate(boost::false_type, Alloc &a, size_type n, const_void_pointer)
|
Chris@16
|
295 { return allocator_traits::allocate(a, n); }
|
Chris@16
|
296
|
Chris@16
|
297 template<class T>
|
Chris@16
|
298 static void priv_destroy(boost::true_type, Alloc &a, T* p)
|
Chris@16
|
299 { a.destroy(p); }
|
Chris@16
|
300
|
Chris@16
|
301 template<class T>
|
Chris@16
|
302 static void priv_destroy(boost::false_type, Alloc &, T* p)
|
Chris@16
|
303 { p->~T(); (void)p; }
|
Chris@16
|
304
|
Chris@16
|
305 static size_type priv_max_size(boost::true_type, const Alloc &a)
|
Chris@16
|
306 { return a.max_size(); }
|
Chris@16
|
307
|
Chris@16
|
308 static size_type priv_max_size(boost::false_type, const Alloc &)
|
Chris@16
|
309 { return (std::numeric_limits<size_type>::max)(); }
|
Chris@16
|
310
|
Chris@16
|
311 static Alloc priv_select_on_container_copy_construction(boost::true_type, const Alloc &a)
|
Chris@16
|
312 { return a.select_on_container_copy_construction(); }
|
Chris@16
|
313
|
Chris@16
|
314 static const Alloc &priv_select_on_container_copy_construction(boost::false_type, const Alloc &a)
|
Chris@16
|
315 { return a; }
|
Chris@16
|
316
|
Chris@16
|
317 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
318 template<class T, class ...Args>
|
Chris@16
|
319 static void priv_construct(boost::false_type, Alloc &a, T *p, BOOST_FWD_REF(Args) ...args)
|
Chris@16
|
320 {
|
Chris@16
|
321 const bool value = boost::container::container_detail::
|
Chris@16
|
322 has_member_function_callable_with_construct
|
Chris@16
|
323 < Alloc, T*, Args... >::value;
|
Chris@16
|
324 ::boost::integral_constant<bool, value> flag;
|
Chris@16
|
325 priv_construct_dispatch2(flag, a, p, ::boost::forward<Args>(args)...);
|
Chris@16
|
326 }
|
Chris@16
|
327
|
Chris@16
|
328 template<class T, class ...Args>
|
Chris@16
|
329 static void priv_construct(boost::true_type, Alloc &a, T *p, BOOST_FWD_REF(Args) ...args)
|
Chris@16
|
330 {
|
Chris@16
|
331 priv_construct_dispatch2(boost::false_type(), a, p, ::boost::forward<Args>(args)...);
|
Chris@16
|
332 }
|
Chris@16
|
333
|
Chris@16
|
334 template<class T, class ...Args>
|
Chris@16
|
335 static void priv_construct_dispatch2(boost::true_type, Alloc &a, T *p, BOOST_FWD_REF(Args) ...args)
|
Chris@16
|
336 { a.construct( p, ::boost::forward<Args>(args)...); }
|
Chris@16
|
337
|
Chris@16
|
338 template<class T, class ...Args>
|
Chris@16
|
339 static void priv_construct_dispatch2(boost::false_type, Alloc &, T *p, BOOST_FWD_REF(Args) ...args)
|
Chris@16
|
340 { ::new((void*)p) T(::boost::forward<Args>(args)...); }
|
Chris@16
|
341 #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
342 public:
|
Chris@16
|
343 #define BOOST_PP_LOCAL_MACRO(n) \
|
Chris@16
|
344 template<class T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P) > \
|
Chris@16
|
345 static void construct(Alloc &a, T *p \
|
Chris@16
|
346 BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
|
Chris@16
|
347 { \
|
Chris@16
|
348 ::boost::integral_constant<bool, container_detail::is_std_allocator<Alloc>::value> flag; \
|
Chris@16
|
349 allocator_traits::priv_construct(flag, a, p \
|
Chris@16
|
350 BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
|
Chris@16
|
351 } \
|
Chris@16
|
352 //
|
Chris@16
|
353 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
|
Chris@16
|
354 #include BOOST_PP_LOCAL_ITERATE()
|
Chris@16
|
355
|
Chris@16
|
356 private:
|
Chris@16
|
357 #define BOOST_PP_LOCAL_MACRO(n) \
|
Chris@16
|
358 template<class T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P) > \
|
Chris@16
|
359 static void priv_construct(boost::false_type, Alloc &a, T *p \
|
Chris@16
|
360 BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST,_)) \
|
Chris@16
|
361 { \
|
Chris@16
|
362 const bool value = \
|
Chris@16
|
363 boost::container::container_detail::has_member_function_callable_with_construct \
|
Chris@16
|
364 < Alloc, T* BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_FWD_TYPE, _) >::value; \
|
Chris@16
|
365 ::boost::integral_constant<bool, value> flag; \
|
Chris@16
|
366 priv_construct_dispatch2(flag, a, p \
|
Chris@16
|
367 BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _) ); \
|
Chris@16
|
368 } \
|
Chris@16
|
369 \
|
Chris@16
|
370 template<class T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P) > \
|
Chris@16
|
371 static void priv_construct(boost::true_type, Alloc &a, T *p \
|
Chris@16
|
372 BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST,_)) \
|
Chris@16
|
373 { \
|
Chris@16
|
374 priv_construct_dispatch2(boost::false_type(), a, p \
|
Chris@16
|
375 BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _) ); \
|
Chris@16
|
376 } \
|
Chris@16
|
377 \
|
Chris@16
|
378 template<class T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P) > \
|
Chris@16
|
379 static void priv_construct_dispatch2(boost::true_type, Alloc &a, T *p \
|
Chris@16
|
380 BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST,_)) \
|
Chris@16
|
381 { a.construct( p BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _) ); } \
|
Chris@16
|
382 \
|
Chris@16
|
383 template<class T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P) > \
|
Chris@16
|
384 static void priv_construct_dispatch2(boost::false_type, Alloc &, T *p \
|
Chris@16
|
385 BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _) ) \
|
Chris@16
|
386 { ::new((void*)p) T(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); } \
|
Chris@16
|
387 //
|
Chris@16
|
388 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
|
Chris@16
|
389 #include BOOST_PP_LOCAL_ITERATE()
|
Chris@16
|
390 #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
391
|
Chris@16
|
392 template<class T>
|
Chris@16
|
393 static void priv_construct_dispatch2(boost::false_type, Alloc &, T *p, ::boost::container::default_init_t)
|
Chris@16
|
394 { ::new((void*)p) T; }
|
Chris@16
|
395 #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
Chris@16
|
396
|
Chris@16
|
397 ///@endcond
|
Chris@16
|
398 };
|
Chris@16
|
399
|
Chris@16
|
400 } //namespace container {
|
Chris@16
|
401 } //namespace boost {
|
Chris@16
|
402
|
Chris@16
|
403 #include <boost/container/detail/config_end.hpp>
|
Chris@16
|
404
|
Chris@16
|
405 #endif // ! defined(BOOST_CONTAINER_ALLOCATOR_ALLOCATOR_TRAITS_HPP)
|