allocator_traits.hpp 23 KB

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