allocator_traits.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. #ifndef BOOST_CONFIG_HPP
  19. # include <boost/config.hpp>
  20. #endif
  21. #if defined(BOOST_HAS_PRAGMA_ONCE)
  22. # pragma once
  23. #endif
  24. #include <boost/container/detail/config_begin.hpp>
  25. #include <boost/container/detail/workaround.hpp>
  26. // container
  27. #include <boost/container/container_fwd.hpp>
  28. #include <boost/container/detail/mpl.hpp>
  29. #include <boost/container/detail/type_traits.hpp> //is_empty
  30. #include <boost/container/detail/placement_new.hpp>
  31. #ifndef BOOST_CONTAINER_DETAIL_STD_FWD_HPP
  32. #include <boost/container/detail/std_fwd.hpp>
  33. #endif
  34. // intrusive
  35. #include <boost/intrusive/pointer_traits.hpp>
  36. #include <boost/intrusive/detail/mpl.hpp>
  37. // move
  38. #include <boost/move/utility_core.hpp>
  39. // move/detail
  40. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  41. #include <boost/move/detail/fwd_macros.hpp>
  42. #endif
  43. // other boost
  44. #include <boost/static_assert.hpp>
  45. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  46. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME allocate
  47. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
  48. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
  49. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 2
  50. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 2
  51. #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
  52. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME destroy
  53. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
  54. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
  55. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1
  56. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1
  57. #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
  58. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME construct
  59. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
  60. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
  61. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1
  62. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 9
  63. #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
  64. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  65. namespace boost {
  66. namespace container {
  67. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  68. template<class T, class VoidAllocator, class Options>
  69. class small_vector_allocator;
  70. namespace allocator_traits_detail {
  71. BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_max_size, max_size)
  72. BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_select_on_container_copy_construction, select_on_container_copy_construction)
  73. } //namespace allocator_traits_detail {
  74. namespace dtl {
  75. //workaround needed for C++03 compilers with no construct()
  76. //supporting rvalue references
  77. template<class Allocator>
  78. struct is_std_allocator
  79. { static const bool value = false; };
  80. template<class T>
  81. struct is_std_allocator< std::allocator<T> >
  82. { static const bool value = true; };
  83. template<class T, class Options>
  84. struct is_std_allocator< small_vector_allocator<T, std::allocator<T>, Options > >
  85. { static const bool value = true; };
  86. template<class Allocator>
  87. struct is_not_std_allocator
  88. { static const bool value = !is_std_allocator<Allocator>::value; };
  89. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(pointer)
  90. BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(const_pointer)
  91. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference)
  92. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reference)
  93. BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(void_pointer)
  94. BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(const_void_pointer)
  95. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(size_type)
  96. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_copy_assignment)
  97. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_move_assignment)
  98. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_swap)
  99. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(is_always_equal)
  100. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type)
  101. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(is_partially_propagable)
  102. } //namespace dtl {
  103. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  104. //! The class template allocator_traits supplies a uniform interface to all allocator types.
  105. //! This class is a C++03-compatible implementation of std::allocator_traits
  106. template <typename Allocator>
  107. struct allocator_traits
  108. {
  109. //allocator_type
  110. typedef Allocator allocator_type;
  111. //value_type
  112. typedef typename allocator_type::value_type value_type;
  113. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  114. //! Allocator::pointer if such a type exists; otherwise, value_type*
  115. //!
  116. typedef unspecified pointer;
  117. //! Allocator::const_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const
  118. //!
  119. typedef see_documentation const_pointer;
  120. //! Non-standard extension
  121. //! Allocator::reference if such a type exists; otherwise, value_type&
  122. typedef see_documentation reference;
  123. //! Non-standard extension
  124. //! Allocator::const_reference if such a type exists ; otherwise, const value_type&
  125. typedef see_documentation const_reference;
  126. //! Allocator::void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<void>.
  127. //!
  128. typedef see_documentation void_pointer;
  129. //! Allocator::const_void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const
  130. //!
  131. typedef see_documentation const_void_pointer;
  132. //! Allocator::difference_type if such a type exists ; otherwise, pointer_traits<pointer>::difference_type.
  133. //!
  134. typedef see_documentation difference_type;
  135. //! Allocator::size_type if such a type exists ; otherwise, make_unsigned<difference_type>::type
  136. //!
  137. typedef see_documentation size_type;
  138. //! Allocator::propagate_on_container_copy_assignment if such a type exists, otherwise a type
  139. //! with an internal constant static boolean member <code>value</code> == false.
  140. typedef see_documentation propagate_on_container_copy_assignment;
  141. //! Allocator::propagate_on_container_move_assignment if such a type exists, otherwise a type
  142. //! with an internal constant static boolean member <code>value</code> == false.
  143. typedef see_documentation propagate_on_container_move_assignment;
  144. //! Allocator::propagate_on_container_swap if such a type exists, otherwise a type
  145. //! with an internal constant static boolean member <code>value</code> == false.
  146. typedef see_documentation propagate_on_container_swap;
  147. //! Allocator::is_always_equal if such a type exists, otherwise a type
  148. //! with an internal constant static boolean member <code>value</code> == is_empty<Allocator>::value
  149. typedef see_documentation is_always_equal;
  150. //! Allocator::is_partially_propagable if such a type exists, otherwise a type
  151. //! with an internal constant static boolean member <code>value</code> == false
  152. //! <b>Note</b>: Non-standard extension used to implement `small_vector_allocator`.
  153. typedef see_documentation is_partially_propagable;
  154. //! Defines an allocator: Allocator::rebind<T>::other if such a type exists; otherwise, Allocator<T, Args>
  155. //! if Allocator is a class template instantiation of the form Allocator<U, Args>, where Args is zero or
  156. //! more type arguments ; otherwise, the instantiation of rebind_alloc is ill-formed.
  157. //!
  158. //! In C++03 compilers <code>rebind_alloc</code> is a struct derived from an allocator
  159. //! deduced by previously detailed rules.
  160. template <class T> using rebind_alloc = see_documentation;
  161. //! In C++03 compilers <code>rebind_traits</code> is a struct derived from
  162. //! <code>allocator_traits<OtherAlloc></code>, where <code>OtherAlloc</code> is
  163. //! the allocator deduced by rules explained in <code>rebind_alloc</code>.
  164. template <class T> using rebind_traits = allocator_traits<rebind_alloc<T> >;
  165. //! Non-standard extension: Portable allocator rebind for C++03 and C++11 compilers.
  166. //! <code>type</code> is an allocator related to Allocator deduced deduced by rules explained in <code>rebind_alloc</code>.
  167. template <class T>
  168. struct portable_rebind_alloc
  169. { typedef see_documentation type; };
  170. #else
  171. //pointer
  172. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  173. pointer, value_type*)
  174. pointer;
  175. //const_pointer
  176. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator,
  177. const_pointer, typename boost::intrusive::pointer_traits<pointer>::template
  178. rebind_pointer<const value_type>)
  179. const_pointer;
  180. //reference
  181. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  182. reference, typename dtl::unvoid_ref<value_type>::type)
  183. reference;
  184. //const_reference
  185. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  186. const_reference, typename dtl::unvoid_ref<const value_type>::type)
  187. const_reference;
  188. //void_pointer
  189. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator,
  190. void_pointer, typename boost::intrusive::pointer_traits<pointer>::template
  191. rebind_pointer<void>)
  192. void_pointer;
  193. //const_void_pointer
  194. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator,
  195. const_void_pointer, typename boost::intrusive::pointer_traits<pointer>::template
  196. rebind_pointer<const void>)
  197. const_void_pointer;
  198. //difference_type
  199. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  200. difference_type, std::ptrdiff_t)
  201. difference_type;
  202. //size_type
  203. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  204. size_type, std::size_t)
  205. size_type;
  206. //propagate_on_container_copy_assignment
  207. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  208. propagate_on_container_copy_assignment, dtl::false_type)
  209. propagate_on_container_copy_assignment;
  210. //propagate_on_container_move_assignment
  211. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  212. propagate_on_container_move_assignment, dtl::false_type)
  213. propagate_on_container_move_assignment;
  214. //propagate_on_container_swap
  215. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  216. propagate_on_container_swap, dtl::false_type)
  217. propagate_on_container_swap;
  218. //is_always_equal
  219. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  220. is_always_equal, dtl::is_empty<Allocator>)
  221. is_always_equal;
  222. //is_partially_propagable
  223. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  224. is_partially_propagable, dtl::false_type)
  225. is_partially_propagable;
  226. //rebind_alloc & rebind_traits
  227. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  228. //C++11
  229. template <typename T> using rebind_alloc = typename boost::intrusive::pointer_rebind<Allocator, T>::type;
  230. template <typename T> using rebind_traits = allocator_traits< rebind_alloc<T> >;
  231. #else // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  232. //Some workaround for C++03 or C++11 compilers with no template aliases
  233. template <typename T>
  234. struct rebind_alloc : boost::intrusive::pointer_rebind<Allocator,T>::type
  235. {
  236. typedef typename boost::intrusive::pointer_rebind<Allocator,T>::type Base;
  237. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  238. template <typename... Args>
  239. rebind_alloc(BOOST_FWD_REF(Args)... args) : Base(boost::forward<Args>(args)...) {}
  240. #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  241. #define BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC(N) \
  242. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N\
  243. explicit rebind_alloc(BOOST_MOVE_UREF##N) : Base(BOOST_MOVE_FWD##N){}\
  244. //
  245. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC)
  246. #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC
  247. #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  248. };
  249. template <typename T>
  250. struct rebind_traits
  251. : allocator_traits<typename boost::intrusive::pointer_rebind<Allocator, T>::type>
  252. {};
  253. #endif // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  254. //portable_rebind_alloc
  255. template <class T>
  256. struct portable_rebind_alloc
  257. { typedef typename boost::intrusive::pointer_rebind<Allocator, T>::type type; };
  258. #endif //BOOST_CONTAINER_DOXYGEN_INVOKED
  259. //! <b>Returns</b>: <code>a.allocate(n)</code>
  260. //!
  261. BOOST_CONTAINER_FORCEINLINE static pointer allocate(Allocator &a, size_type n)
  262. { return a.allocate(n); }
  263. //! <b>Returns</b>: <code>a.deallocate(p, n)</code>
  264. //!
  265. //! <b>Throws</b>: Nothing
  266. BOOST_CONTAINER_FORCEINLINE static void deallocate(Allocator &a, pointer p, size_type n)
  267. { a.deallocate(p, n); }
  268. //! <b>Effects</b>: calls <code>a.allocate(n, p)</code> if that call is well-formed;
  269. //! otherwise, invokes <code>a.allocate(n)</code>
  270. BOOST_CONTAINER_FORCEINLINE static pointer allocate(Allocator &a, size_type n, const_void_pointer p)
  271. {
  272. const bool value = boost::container::dtl::
  273. has_member_function_callable_with_allocate
  274. <Allocator, const size_type, const const_void_pointer>::value;
  275. dtl::bool_<value> flag;
  276. return allocator_traits::priv_allocate(flag, a, n, p);
  277. }
  278. //! <b>Effects</b>: calls <code>a.destroy(p)</code> if that call is well-formed;
  279. //! otherwise, invokes <code>p->~T()</code>.
  280. template<class T>
  281. BOOST_CONTAINER_FORCEINLINE static void destroy(Allocator &a, T*p) BOOST_NOEXCEPT_OR_NOTHROW
  282. {
  283. typedef T* destroy_pointer;
  284. const bool value = boost::container::dtl::
  285. has_member_function_callable_with_destroy
  286. <Allocator, const destroy_pointer>::value;
  287. dtl::bool_<value> flag;
  288. allocator_traits::priv_destroy(flag, a, p);
  289. }
  290. //! <b>Returns</b>: <code>a.max_size()</code> if that expression is well-formed; otherwise,
  291. //! <code>numeric_limits<size_type>::max()</code>.
  292. BOOST_CONTAINER_FORCEINLINE static size_type max_size(const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW
  293. {
  294. const bool value = allocator_traits_detail::has_max_size<Allocator, size_type (Allocator::*)() const>::value;
  295. dtl::bool_<value> flag;
  296. return allocator_traits::priv_max_size(flag, a);
  297. }
  298. //! <b>Returns</b>: <code>a.select_on_container_copy_construction()</code> if that expression is well-formed;
  299. //! otherwise, a.
  300. BOOST_CONTAINER_FORCEINLINE static BOOST_CONTAINER_DOC1ST(Allocator,
  301. typename dtl::if_c
  302. < allocator_traits_detail::has_select_on_container_copy_construction<Allocator BOOST_MOVE_I Allocator (Allocator::*)() const>::value
  303. BOOST_MOVE_I Allocator BOOST_MOVE_I const Allocator & >::type)
  304. select_on_container_copy_construction(const Allocator &a)
  305. {
  306. const bool value = allocator_traits_detail::has_select_on_container_copy_construction
  307. <Allocator, Allocator (Allocator::*)() const>::value;
  308. dtl::bool_<value> flag;
  309. return allocator_traits::priv_select_on_container_copy_construction(flag, a);
  310. }
  311. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  312. //! <b>Effects</b>: calls <code>a.construct(p, std::forward<Args>(args)...)</code> if that call is well-formed;
  313. //! otherwise, invokes <code>`placement new` (static_cast<void*>(p)) T(std::forward<Args>(args)...)</code>
  314. template <class T, class ...Args>
  315. BOOST_CONTAINER_FORCEINLINE static void construct(Allocator & a, T* p, BOOST_FWD_REF(Args)... args)
  316. {
  317. static const bool value = ::boost::move_detail::and_
  318. < dtl::is_not_std_allocator<Allocator>
  319. , boost::container::dtl::has_member_function_callable_with_construct
  320. < Allocator, T*, Args... >
  321. >::value;
  322. dtl::bool_<value> flag;
  323. allocator_traits::priv_construct(flag, a, p, ::boost::forward<Args>(args)...);
  324. }
  325. #endif
  326. //! <b>Returns</b>: <code>a.storage_is_unpropagable(p)</code> if is_partially_propagable::value is true; otherwise,
  327. //! <code>false</code>.
  328. BOOST_CONTAINER_FORCEINLINE static bool storage_is_unpropagable(const Allocator &a, pointer p) BOOST_NOEXCEPT_OR_NOTHROW
  329. {
  330. dtl::bool_<is_partially_propagable::value> flag;
  331. return allocator_traits::priv_storage_is_unpropagable(flag, a, p);
  332. }
  333. //! <b>Returns</b>: <code>true</code> if <code>is_always_equal::value == true</code>, otherwise,
  334. //! <code>a == b</code>.
  335. BOOST_CONTAINER_FORCEINLINE static bool equal(const Allocator &a, const Allocator &b) BOOST_NOEXCEPT_OR_NOTHROW
  336. {
  337. dtl::bool_<is_always_equal::value> flag;
  338. return allocator_traits::priv_equal(flag, a, b);
  339. }
  340. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  341. private:
  342. BOOST_CONTAINER_FORCEINLINE static pointer priv_allocate(dtl::true_type, Allocator &a, size_type n, const_void_pointer p)
  343. { return a.allocate(n, p); }
  344. BOOST_CONTAINER_FORCEINLINE static pointer priv_allocate(dtl::false_type, Allocator &a, size_type n, const_void_pointer)
  345. { return a.allocate(n); }
  346. template<class T>
  347. BOOST_CONTAINER_FORCEINLINE static void priv_destroy(dtl::true_type, Allocator &a, T* p) BOOST_NOEXCEPT_OR_NOTHROW
  348. { a.destroy(p); }
  349. template<class T>
  350. BOOST_CONTAINER_FORCEINLINE static void priv_destroy(dtl::false_type, Allocator &, T* p) BOOST_NOEXCEPT_OR_NOTHROW
  351. { p->~T(); (void)p; }
  352. BOOST_CONTAINER_FORCEINLINE static size_type priv_max_size(dtl::true_type, const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW
  353. { return a.max_size(); }
  354. BOOST_CONTAINER_FORCEINLINE static size_type priv_max_size(dtl::false_type, const Allocator &) BOOST_NOEXCEPT_OR_NOTHROW
  355. { return size_type(-1)/sizeof(value_type); }
  356. BOOST_CONTAINER_FORCEINLINE static Allocator priv_select_on_container_copy_construction(dtl::true_type, const Allocator &a)
  357. { return a.select_on_container_copy_construction(); }
  358. BOOST_CONTAINER_FORCEINLINE static const Allocator &priv_select_on_container_copy_construction(dtl::false_type, const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW
  359. { return a; }
  360. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  361. template<class T, class ...Args>
  362. BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::true_type, Allocator &a, T *p, BOOST_FWD_REF(Args) ...args)
  363. { a.construct( p, ::boost::forward<Args>(args)...); }
  364. template<class T, class ...Args>
  365. BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::false_type, Allocator &, T *p, BOOST_FWD_REF(Args) ...args)
  366. { ::new((void*)p, boost_container_new_t()) T(::boost::forward<Args>(args)...); }
  367. #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  368. public:
  369. #define BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL(N) \
  370. template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  371. BOOST_CONTAINER_FORCEINLINE static void construct(Allocator &a, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  372. {\
  373. static const bool value = ::boost::move_detail::and_ \
  374. < dtl::is_not_std_allocator<Allocator> \
  375. , boost::container::dtl::has_member_function_callable_with_construct \
  376. < Allocator, T* BOOST_MOVE_I##N BOOST_MOVE_FWD_T##N > \
  377. >::value; \
  378. dtl::bool_<value> flag;\
  379. (priv_construct)(flag, a, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  380. }\
  381. //
  382. BOOST_MOVE_ITERATE_0TO8(BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL)
  383. #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL
  384. private:
  385. /////////////////////////////////
  386. // priv_construct
  387. /////////////////////////////////
  388. #define BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL(N) \
  389. template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  390. BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::true_type, Allocator &a, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  391. { a.construct( p BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); }\
  392. \
  393. template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  394. BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::false_type, Allocator &, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  395. { ::new((void*)p, boost_container_new_t()) T(BOOST_MOVE_FWD##N); }\
  396. //
  397. BOOST_MOVE_ITERATE_0TO8(BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL)
  398. #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL
  399. #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  400. template<class T>
  401. BOOST_CONTAINER_FORCEINLINE static void priv_construct(dtl::false_type, Allocator &, T *p, const ::boost::container::default_init_t&)
  402. { ::new((void*)p, boost_container_new_t()) T; }
  403. BOOST_CONTAINER_FORCEINLINE static bool priv_storage_is_unpropagable(dtl::true_type, const Allocator &a, pointer p)
  404. { return a.storage_is_unpropagable(p); }
  405. BOOST_CONTAINER_FORCEINLINE static bool priv_storage_is_unpropagable(dtl::false_type, const Allocator &, pointer)
  406. { return false; }
  407. BOOST_CONTAINER_FORCEINLINE static bool priv_equal(dtl::true_type, const Allocator &, const Allocator &)
  408. { return true; }
  409. BOOST_CONTAINER_FORCEINLINE static bool priv_equal(dtl::false_type, const Allocator &a, const Allocator &b)
  410. { return a == b; }
  411. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  412. };
  413. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  414. template<class T, class AllocatorOrVoid>
  415. struct real_allocator
  416. {
  417. typedef AllocatorOrVoid type;
  418. };
  419. template<class T>
  420. struct real_allocator<T, void>
  421. {
  422. typedef new_allocator<T> type;
  423. };
  424. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  425. } //namespace container {
  426. } //namespace boost {
  427. #include <boost/container/detail/config_end.hpp>
  428. #endif // ! defined(BOOST_CONTAINER_ALLOCATOR_ALLOCATOR_TRAITS_HPP)