1 ////////////////////////////////////////////////////////////////////////////// 2 // 3 // (C) Copyright Pablo Halpern 2009. Distributed under the Boost 4 // Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 ////////////////////////////////////////////////////////////////////////////// 8 // 9 // (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost 10 // Software License, Version 1.0. (See accompanying file 11 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 12 // 13 // See http://www.boost.org/libs/container for documentation. 14 // 15 ////////////////////////////////////////////////////////////////////////////// 16 #ifndef BOOST_CONTAINER_ALLOCATOR_ALLOCATOR_TRAITS_HPP 17 #define BOOST_CONTAINER_ALLOCATOR_ALLOCATOR_TRAITS_HPP 18 19 #ifndef BOOST_CONFIG_HPP 20 # include <boost/config.hpp> 21 #endif 22 23 #if defined(BOOST_HAS_PRAGMA_ONCE) 24 # pragma once 25 #endif 26 27 #include <boost/container/detail/config_begin.hpp> 28 #include <boost/container/detail/workaround.hpp> 29 30 // container 31 #include <boost/container/container_fwd.hpp> 32 #include <boost/container/detail/mpl.hpp> 33 #include <boost/container/detail/type_traits.hpp> //is_empty 34 #include <boost/container/detail/placement_new.hpp> 35 #ifndef BOOST_CONTAINER_DETAIL_STD_FWD_HPP 36 #include <boost/container/detail/std_fwd.hpp> 37 #endif 38 // intrusive 39 #include <boost/intrusive/pointer_traits.hpp> 40 #include <boost/intrusive/detail/mpl.hpp> 41 // move 42 #include <boost/move/utility_core.hpp> 43 // move/detail 44 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 45 #include <boost/move/detail/fwd_macros.hpp> 46 #endif 47 // other boost 48 #include <boost/static_assert.hpp> 49 50 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED 51 52 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600) 53 #pragma GCC diagnostic push 54 #pragma GCC diagnostic ignored "-Wunused-result" 55 #endif 56 57 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME allocate 58 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl { 59 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} 60 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 2 61 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 2 62 #include <boost/intrusive/detail/has_member_function_callable_with.hpp> 63 64 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME destroy 65 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl { 66 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} 67 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1 68 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1 69 #include <boost/intrusive/detail/has_member_function_callable_with.hpp> 70 71 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME construct 72 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl { 73 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} 74 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1 75 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 9 76 #include <boost/intrusive/detail/has_member_function_callable_with.hpp> 77 78 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600) 79 #pragma GCC diagnostic pop 80 #endif 81 82 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED 83 84 namespace boost { 85 namespace container { 86 87 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED 88 89 template<class T, class VoidAllocator, class Options> 90 class small_vector_allocator; 91 92 namespace allocator_traits_detail { 93 94 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_max_size, max_size) 95 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_select_on_container_copy_construction, select_on_container_copy_construction) 96 97 } //namespace allocator_traits_detail { 98 99 namespace dtl { 100 101 //workaround needed for C++03 compilers with no construct() 102 //supporting rvalue references 103 template<class Allocator> 104 struct is_std_allocator 105 { static const bool value = false; }; 106 107 template<class T> 108 struct is_std_allocator< std::allocator<T> > 109 { static const bool value = true; }; 110 111 template<class T, class Options> 112 struct is_std_allocator< small_vector_allocator<T, std::allocator<T>, Options > > 113 { static const bool value = true; }; 114 115 template<class Allocator> 116 struct is_not_std_allocator 117 { static const bool value = !is_std_allocator<Allocator>::value; }; 118 119 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(pointer) 120 BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(const_pointer) 121 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference) 122 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reference) 123 BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(void_pointer) 124 BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(const_void_pointer) 125 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(size_type) 126 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_copy_assignment) 127 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_move_assignment) 128 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_swap) 129 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(is_always_equal) 130 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type) 131 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(is_partially_propagable) 132 133 } //namespace dtl { 134 135 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED 136 137 //! The class template allocator_traits supplies a uniform interface to all allocator types. 138 //! This class is a C++03-compatible implementation of std::allocator_traits 139 template <typename Allocator> 140 struct allocator_traits 141 { 142 //allocator_type 143 typedef Allocator allocator_type; 144 //value_type 145 typedef typename allocator_type::value_type value_type; 146 147 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) 148 //! Allocator::pointer if such a type exists; otherwise, value_type* 149 //! 150 typedef unspecified pointer; 151 //! Allocator::const_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const 152 //! 153 typedef see_documentation const_pointer; 154 //! Non-standard extension 155 //! Allocator::reference if such a type exists; otherwise, value_type& 156 typedef see_documentation reference; 157 //! Non-standard extension 158 //! Allocator::const_reference if such a type exists ; otherwise, const value_type& 159 typedef see_documentation const_reference; 160 //! Allocator::void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<void>. 161 //! 162 typedef see_documentation void_pointer; 163 //! Allocator::const_void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const 164 //! 165 typedef see_documentation const_void_pointer; 166 //! Allocator::difference_type if such a type exists ; otherwise, pointer_traits<pointer>::difference_type. 167 //! 168 typedef see_documentation difference_type; 169 //! Allocator::size_type if such a type exists ; otherwise, make_unsigned<difference_type>::type 170 //! 171 typedef see_documentation size_type; 172 //! Allocator::propagate_on_container_copy_assignment if such a type exists, otherwise a type 173 //! with an internal constant static boolean member <code>value</code> == false. 174 typedef see_documentation propagate_on_container_copy_assignment; 175 //! Allocator::propagate_on_container_move_assignment if such a type exists, otherwise a type 176 //! with an internal constant static boolean member <code>value</code> == false. 177 typedef see_documentation propagate_on_container_move_assignment; 178 //! Allocator::propagate_on_container_swap if such a type exists, otherwise a type 179 //! with an internal constant static boolean member <code>value</code> == false. 180 typedef see_documentation propagate_on_container_swap; 181 //! Allocator::is_always_equal if such a type exists, otherwise a type 182 //! with an internal constant static boolean member <code>value</code> == is_empty<Allocator>::value 183 typedef see_documentation is_always_equal; 184 //! Allocator::is_partially_propagable if such a type exists, otherwise a type 185 //! with an internal constant static boolean member <code>value</code> == false 186 //! <b>Note</b>: Non-standard extension used to implement `small_vector_allocator`. 187 typedef see_documentation is_partially_propagable; 188 //! Defines an allocator: Allocator::rebind<T>::other if such a type exists; otherwise, Allocator<T, Args> 189 //! if Allocator is a class template instantiation of the form Allocator<U, Args>, where Args is zero or 190 //! more type arguments ; otherwise, the instantiation of rebind_alloc is ill-formed. 191 //! 192 //! In C++03 compilers <code>rebind_alloc</code> is a struct derived from an allocator 193 //! deduced by previously detailed rules. 194 template <class T> using rebind_alloc = see_documentation; 195 196 //! In C++03 compilers <code>rebind_traits</code> is a struct derived from 197 //! <code>allocator_traits<OtherAlloc></code>, where <code>OtherAlloc</code> is 198 //! the allocator deduced by rules explained in <code>rebind_alloc</code>. 199 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T> >; 200 201 //! Non-standard extension: Portable allocator rebind for C++03 and C++11 compilers. 202 //! <code>type</code> is an allocator related to Allocator deduced deduced by rules explained in <code>rebind_alloc</code>. 203 template <class T> 204 struct portable_rebind_alloc 205 { typedef see_documentation type; }; 206 #else 207 //pointer 208 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 209 pointer, value_type*) 210 pointer; 211 //const_pointer 212 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator, 213 const_pointer, typename boost::intrusive::pointer_traits<pointer>::template 214 rebind_pointer<const value_type>) 215 const_pointer; 216 //reference 217 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 218 reference, typename dtl::unvoid_ref<value_type>::type) 219 reference; 220 //const_reference 221 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 222 const_reference, typename dtl::unvoid_ref<const value_type>::type) 223 const_reference; 224 //void_pointer 225 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator, 226 void_pointer, typename boost::intrusive::pointer_traits<pointer>::template 227 rebind_pointer<void>) 228 void_pointer; 229 //const_void_pointer 230 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator, 231 const_void_pointer, typename boost::intrusive::pointer_traits<pointer>::template 232 rebind_pointer<const void>) 233 const_void_pointer; 234 //difference_type 235 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 236 difference_type, std::ptrdiff_t) 237 difference_type; 238 //size_type 239 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 240 size_type, std::size_t) 241 size_type; 242 //propagate_on_container_copy_assignment 243 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 244 propagate_on_container_copy_assignment, dtl::false_type) 245 propagate_on_container_copy_assignment; 246 //propagate_on_container_move_assignment 247 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 248 propagate_on_container_move_assignment, dtl::false_type) 249 propagate_on_container_move_assignment; 250 //propagate_on_container_swap 251 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 252 propagate_on_container_swap, dtl::false_type) 253 propagate_on_container_swap; 254 //is_always_equal 255 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 256 is_always_equal, dtl::is_empty<Allocator>) 257 is_always_equal; 258 //is_partially_propagable 259 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator, 260 is_partially_propagable, dtl::false_type) 261 is_partially_propagable; 262 263 //rebind_alloc & rebind_traits 264 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) 265 //C++11 266 template <typename T> using rebind_alloc = typename boost::intrusive::pointer_rebind<Allocator, T>::type; 267 template <typename T> using rebind_traits = allocator_traits< rebind_alloc<T> >; 268 #else // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) 269 //Some workaround for C++03 or C++11 compilers with no template aliases 270 template <typename T> 271 struct rebind_alloc : boost::intrusive::pointer_rebind<Allocator,T>::type 272 { 273 typedef typename boost::intrusive::pointer_rebind<Allocator,T>::type Base; 274 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 275 template <typename... Args> rebind_allocboost::container::allocator_traits::rebind_alloc276 rebind_alloc(BOOST_FWD_REF(Args)... args) : Base(boost::forward<Args>(args)...) {} 277 #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 278 #define BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC(N) \ 279 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N\ 280 explicit rebind_alloc(BOOST_MOVE_UREF##N) : Base(BOOST_MOVE_FWD##N){}\ 281 // 282 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC) 283 #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC 284 #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 285 }; 286 287 template <typename T> 288 struct rebind_traits 289 : allocator_traits<typename boost::intrusive::pointer_rebind<Allocator, T>::type> 290 {}; 291 #endif // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) 292 293 //portable_rebind_alloc 294 template <class T> 295 struct portable_rebind_alloc 296 { typedef typename boost::intrusive::pointer_rebind<Allocator, T>::type type; }; 297 #endif //BOOST_CONTAINER_DOXYGEN_INVOKED 298 299 //! <b>Returns</b>: <code>a.allocate(n)</code> 300 //! allocateboost::container::allocator_traits301 BOOST_CONTAINER_FORCEINLINE static pointer allocate(Allocator &a, size_type n) 302 { return a.allocate(n); } 303 304 //! <b>Returns</b>: <code>a.deallocate(p, n)</code> 305 //! 306 //! <b>Throws</b>: Nothing deallocateboost::container::allocator_traits307 BOOST_CONTAINER_FORCEINLINE static void deallocate(Allocator &a, pointer p, size_type n) 308 { a.deallocate(p, n); } 309 310 //! <b>Effects</b>: calls <code>a.allocate(n, p)</code> if that call is well-formed; 311 //! otherwise, invokes <code>a.allocate(n)</code> allocateboost::container::allocator_traits312 BOOST_CONTAINER_FORCEINLINE static pointer allocate(Allocator &a, size_type n, const_void_pointer p) 313 { 314 const bool value = boost::container::dtl:: 315 has_member_function_callable_with_allocate 316 <Allocator, const size_type, const const_void_pointer>::value; 317 dtl::bool_<value> flag; 318 return allocator_traits::priv_allocate(flag, a, n, p); 319 } 320 321 //! <b>Effects</b>: calls <code>a.destroy(p)</code> if that call is well-formed; 322 //! otherwise, invokes <code>p->~T()</code>. 323 template<class T> destroyboost::container::allocator_traits324 BOOST_CONTAINER_FORCEINLINE static void destroy(Allocator &a, T*p) BOOST_NOEXCEPT_OR_NOTHROW 325 { 326 typedef T* destroy_pointer; 327 const bool value = boost::container::dtl:: 328 has_member_function_callable_with_destroy 329 <Allocator, const destroy_pointer>::value; 330 dtl::bool_<value> flag; 331 allocator_traits::priv_destroy(flag, a, p); 332 } 333 334 //! <b>Returns</b>: <code>a.max_size()</code> if that expression is well-formed; otherwise, 335 //! <code>numeric_limits<size_type>::max()</code>. max_sizeboost::container::allocator_traits336 BOOST_CONTAINER_FORCEINLINE static size_type max_size(const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW 337 { 338 const bool value = allocator_traits_detail::has_max_size<Allocator, size_type (Allocator::*)() const>::value; 339 dtl::bool_<value> flag; 340 return allocator_traits::priv_max_size(flag, a); 341 } 342 343 //! <b>Returns</b>: <code>a.select_on_container_copy_construction()</code> if that expression is well-formed; 344 //! otherwise, a. BOOST_CONTAINER_DOC1STboost::container::allocator_traits345 BOOST_CONTAINER_FORCEINLINE static BOOST_CONTAINER_DOC1ST(Allocator, 346 typename dtl::if_c 347 < allocator_traits_detail::has_select_on_container_copy_construction<Allocator BOOST_MOVE_I Allocator (Allocator::*)() const>::value 348 BOOST_MOVE_I Allocator BOOST_MOVE_I const Allocator & >::type) 349 select_on_container_copy_construction(const Allocator &a) 350 { 351 const bool value = allocator_traits_detail::has_select_on_container_copy_construction 352 <Allocator, Allocator (Allocator::*)() const>::value; 353 dtl::bool_<value> flag; 354 return allocator_traits::priv_select_on_container_copy_construction(flag, a); 355 } 356 357 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) 358 //! <b>Effects</b>: calls <code>a.construct(p, std::forward<Args>(args)...)</code> if that call is well-formed; 359 //! otherwise, invokes <code>`placement new` (static_cast<void*>(p)) T(std::forward<Args>(args)...)</code> 360 template <class T, class ...Args> constructboost::container::allocator_traits361 BOOST_CONTAINER_FORCEINLINE static void construct(Allocator & a, T* p, BOOST_FWD_REF(Args)... args) 362 { 363 static const bool value = ::boost::move_detail::and_ 364 < dtl::is_not_std_allocator<Allocator> 365 , boost::container::dtl::has_member_function_callable_with_construct 366 < Allocator, T*, Args... > 367 >::value; 368 dtl::bool_<value> flag; 369 allocator_traits::priv_construct(flag, a, p, ::boost::forward<Args>(args)...); 370 } 371 #endif 372 373 //! <b>Returns</b>: <code>a.storage_is_unpropagable(p)</code> if is_partially_propagable::value is true; otherwise, 374 //! <code>false</code>. storage_is_unpropagableboost::container::allocator_traits375 BOOST_CONTAINER_FORCEINLINE static bool storage_is_unpropagable(const Allocator &a, pointer p) BOOST_NOEXCEPT_OR_NOTHROW 376 { 377 dtl::bool_<is_partially_propagable::value> flag; 378 return allocator_traits::priv_storage_is_unpropagable(flag, a, p); 379 } 380 381 //! <b>Returns</b>: <code>true</code> if <code>is_always_equal::value == true</code>, otherwise, 382 //! <code>a == b</code>. equalboost::container::allocator_traits383 BOOST_CONTAINER_FORCEINLINE static bool equal(const Allocator &a, const Allocator &b) BOOST_NOEXCEPT_OR_NOTHROW 384 { 385 dtl::bool_<is_always_equal::value> flag; 386 return allocator_traits::priv_equal(flag, a, b); 387 } 388 389 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) 390 private: priv_allocateboost::container::allocator_traits391 BOOST_CONTAINER_FORCEINLINE static pointer priv_allocate(dtl::true_type, Allocator &a, size_type n, const_void_pointer p) 392 { return a.allocate(n, p); } 393 priv_allocateboost::container::allocator_traits394 BOOST_CONTAINER_FORCEINLINE static pointer priv_allocate(dtl::false_type, Allocator &a, size_type n, const_void_pointer) 395 { return a.allocate(n); } 396 397 template<class T> priv_destroyboost::container::allocator_traits398 BOOST_CONTAINER_FORCEINLINE static void priv_destroy(dtl::true_type, Allocator &a, T* p) BOOST_NOEXCEPT_OR_NOTHROW 399 { a.destroy(p); } 400 401 template<class T> priv_destroyboost::container::allocator_traits402 BOOST_CONTAINER_FORCEINLINE static void priv_destroy(dtl::false_type, Allocator &, T* p) BOOST_NOEXCEPT_OR_NOTHROW 403 { p->~T(); (void)p; } 404 priv_max_sizeboost::container::allocator_traits405 BOOST_CONTAINER_FORCEINLINE static size_type priv_max_size(dtl::true_type, const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW 406 { return a.max_size(); } 407 priv_max_sizeboost::container::allocator_traits408 BOOST_CONTAINER_FORCEINLINE static size_type priv_max_size(dtl::false_type, const Allocator &) BOOST_NOEXCEPT_OR_NOTHROW 409 { return size_type(-1)/sizeof(value_type); } 410 priv_select_on_container_copy_constructionboost::container::allocator_traits411 BOOST_CONTAINER_FORCEINLINE static Allocator priv_select_on_container_copy_construction(dtl::true_type, const Allocator &a) 412 { return a.select_on_container_copy_construction(); } 413 priv_select_on_container_copy_constructionboost::container::allocator_traits414 BOOST_CONTAINER_FORCEINLINE static const Allocator &priv_select_on_container_copy_construction(dtl::false_type, const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW 415 { return a; } 416 417 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 418 template<class T, class ...Args> priv_constructboost::container::allocator_traits419 BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::true_type, Allocator &a, T *p, BOOST_FWD_REF(Args) ...args) 420 { a.construct( p, ::boost::forward<Args>(args)...); } 421 422 template<class T, class ...Args> priv_constructboost::container::allocator_traits423 BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::false_type, Allocator &, T *p, BOOST_FWD_REF(Args) ...args) 424 { ::new((void*)p, boost_container_new_t()) T(::boost::forward<Args>(args)...); } 425 #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 426 public: 427 428 #define BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL(N) \ 429 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\ 430 BOOST_CONTAINER_FORCEINLINE static void construct(Allocator &a, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ 431 {\ 432 static const bool value = ::boost::move_detail::and_ \ 433 < dtl::is_not_std_allocator<Allocator> \ 434 , boost::container::dtl::has_member_function_callable_with_construct \ 435 < Allocator, T* BOOST_MOVE_I##N BOOST_MOVE_FWD_T##N > \ 436 >::value; \ 437 dtl::bool_<value> flag;\ 438 (priv_construct)(flag, a, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ 439 }\ 440 // 441 BOOST_MOVE_ITERATE_0TO8(BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL) 442 #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL 443 444 private: 445 ///////////////////////////////// 446 // priv_construct 447 ///////////////////////////////// 448 #define BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL(N) \ 449 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\ 450 BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::true_type, Allocator &a, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ 451 { a.construct( p BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); }\ 452 \ 453 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\ 454 BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::false_type, Allocator &, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ 455 { ::new((void*)p, boost_container_new_t()) T(BOOST_MOVE_FWD##N); }\ 456 // BOOST_MOVE_ITERATE_0TO8boost::container::allocator_traits457 BOOST_MOVE_ITERATE_0TO8(BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL) 458 #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL 459 460 #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 461 462 template<class T> 463 BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::false_type, Allocator &, T *p, const ::boost::container::default_init_t&) 464 { ::new((void*)p, boost_container_new_t()) T; } 465 priv_storage_is_unpropagableboost::container::allocator_traits466 BOOST_CONTAINER_FORCEINLINE static bool priv_storage_is_unpropagable(dtl::true_type, const Allocator &a, pointer p) 467 { return a.storage_is_unpropagable(p); } 468 priv_storage_is_unpropagableboost::container::allocator_traits469 BOOST_CONTAINER_FORCEINLINE static bool priv_storage_is_unpropagable(dtl::false_type, const Allocator &, pointer) 470 { return false; } 471 priv_equalboost::container::allocator_traits472 BOOST_CONTAINER_FORCEINLINE static bool priv_equal(dtl::true_type, const Allocator &, const Allocator &) 473 { return true; } 474 priv_equalboost::container::allocator_traits475 BOOST_CONTAINER_FORCEINLINE static bool priv_equal(dtl::false_type, const Allocator &a, const Allocator &b) 476 { return a == b; } 477 478 #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) 479 }; 480 481 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) 482 483 template<class T, class AllocatorOrVoid> 484 struct real_allocator 485 { 486 typedef AllocatorOrVoid type; 487 }; 488 489 template<class T> 490 struct real_allocator<T, void> 491 { 492 typedef new_allocator<T> type; 493 }; 494 495 #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) 496 497 } //namespace container { 498 } //namespace boost { 499 500 #include <boost/container/detail/config_end.hpp> 501 502 #endif // ! defined(BOOST_CONTAINER_ALLOCATOR_ALLOCATOR_TRAITS_HPP) 503