allocator_traits.hpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. #include <boost/container/detail/is_pair.hpp>
  32. #include <boost/container/detail/addressof.hpp>
  33. #ifndef BOOST_CONTAINER_DETAIL_STD_FWD_HPP
  34. #include <boost/container/detail/std_fwd.hpp>
  35. #endif
  36. // intrusive
  37. #include <boost/intrusive/pointer_traits.hpp>
  38. #include <boost/intrusive/detail/mpl.hpp>
  39. // move
  40. #include <boost/move/utility_core.hpp>
  41. // move/detail
  42. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  43. #include <boost/move/detail/fwd_macros.hpp>
  44. #endif
  45. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  46. #if defined(BOOST_CONTAINER_GCC_COMPATIBLE_HAS_DIAGNOSTIC_IGNORED)
  47. #pragma GCC diagnostic push
  48. #pragma GCC diagnostic ignored "-Wunused-result"
  49. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  50. #endif
  51. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME allocate
  52. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
  53. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
  54. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 2
  55. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 2
  56. #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
  57. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME destroy
  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 1
  61. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1
  62. #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
  63. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME construct
  64. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace dtl {
  65. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
  66. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1
  67. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 9
  68. #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
  69. #if defined(BOOST_CONTAINER_GCC_COMPATIBLE_HAS_DIAGNOSTIC_IGNORED)
  70. #pragma GCC diagnostic pop
  71. #endif
  72. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  73. namespace boost {
  74. namespace container {
  75. namespace dtl {
  76. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  77. template<class T, class ...Args>
  78. BOOST_CONTAINER_FORCEINLINE void construct_type(T *p, BOOST_FWD_REF(Args) ...args)
  79. {
  80. ::new((void*)p, boost_container_new_t()) T(::boost::forward<Args>(args)...);
  81. }
  82. template < class Pair, class KeyType, class ... Args>
  83. typename dtl::enable_if< dtl::is_pair<Pair>, void >::type
  84. construct_type
  85. (Pair* p, try_emplace_t, BOOST_FWD_REF(KeyType) k, BOOST_FWD_REF(Args) ...args)
  86. {
  87. construct_type(dtl::addressof(p->first), ::boost::forward<KeyType>(k));
  88. BOOST_CONTAINER_TRY{
  89. construct_type(dtl::addressof(p->second), ::boost::forward<Args>(args)...);
  90. }
  91. BOOST_CONTAINER_CATCH(...) {
  92. typedef typename Pair::first_type first_type;
  93. dtl::addressof(p->first)->~first_type();
  94. BOOST_CONTAINER_RETHROW
  95. }
  96. BOOST_CONTAINER_CATCH_END
  97. }
  98. #else
  99. #define BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_TYPEJ(N) \
  100. template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N>\
  101. BOOST_CONTAINER_FORCEINLINE \
  102. typename dtl::disable_if_c<dtl::is_pair<T>::value, void >::type \
  103. construct_type(T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  104. {\
  105. ::new((void*)p, boost_container_new_t()) T( BOOST_MOVE_FWD##N );\
  106. }\
  107. //
  108. BOOST_MOVE_ITERATE_0TO8(BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_TYPEJ)
  109. #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_TYPEJ
  110. #define BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_TYPE(N) \
  111. template < class Pair, class KeyType BOOST_MOVE_I##N BOOST_MOVE_CLASS##N>\
  112. typename dtl::enable_if< dtl::is_pair<Pair>, void >::type construct_type\
  113. (Pair* p, try_emplace_t, BOOST_FWD_REF(KeyType) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  114. {\
  115. construct_type(dtl::addressof(p->first), ::boost::forward<KeyType>(k));\
  116. BOOST_CONTAINER_TRY{\
  117. construct_type(dtl::addressof(p->second) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  118. }\
  119. BOOST_CONTAINER_CATCH(...) {\
  120. typedef typename Pair::first_type first_type;\
  121. dtl::addressof(p->first)->~first_type();\
  122. BOOST_CONTAINER_RETHROW\
  123. }\
  124. BOOST_CONTAINER_CATCH_END\
  125. }\
  126. //
  127. BOOST_MOVE_ITERATE_0TO8(BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_TYPE)
  128. #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_TYPE
  129. #endif
  130. template<class T>
  131. inline
  132. typename dtl::enable_if<dtl::is_pair<T>, void >::type
  133. construct_type(T* p)
  134. {
  135. dtl::construct_type(dtl::addressof(p->first));
  136. BOOST_CONTAINER_TRY{
  137. dtl::construct_type(dtl::addressof(p->second));
  138. }
  139. BOOST_CONTAINER_CATCH(...) {
  140. typedef typename T::first_type first_type;
  141. dtl::addressof(p->first)->~first_type();
  142. BOOST_CONTAINER_RETHROW
  143. }
  144. BOOST_CONTAINER_CATCH_END
  145. }
  146. template<class T, class U>
  147. inline
  148. typename dtl::enable_if_c
  149. < dtl::is_pair<T>::value
  150. , void >::type
  151. construct_type(T* p, U &u)
  152. {
  153. dtl::construct_type(dtl::addressof(p->first), u.first);
  154. BOOST_CONTAINER_TRY{
  155. dtl::construct_type(dtl::addressof(p->second), u.second);
  156. }
  157. BOOST_CONTAINER_CATCH(...) {
  158. typedef typename T::first_type first_type;
  159. dtl::addressof(p->first)->~first_type();
  160. BOOST_CONTAINER_RETHROW
  161. }
  162. BOOST_CONTAINER_CATCH_END
  163. }
  164. template<class T, class U>
  165. inline
  166. typename dtl::enable_if_c
  167. < dtl::is_pair<typename dtl::remove_reference<T>::type>::value &&
  168. !boost::move_detail::is_reference<U>::value //This is needed for MSVC10 and ambiguous overloads
  169. , void >::type
  170. construct_type(T* p, BOOST_RV_REF(U) u)
  171. {
  172. dtl::construct_type(dtl::addressof(p->first), ::boost::move(u.first));
  173. BOOST_CONTAINER_TRY{
  174. dtl::construct_type(dtl::addressof(p->second), ::boost::move(u.second));
  175. }
  176. BOOST_CONTAINER_CATCH(...) {
  177. typedef typename T::first_type first_type;
  178. dtl::addressof(p->first)->~first_type();
  179. BOOST_CONTAINER_RETHROW
  180. }
  181. BOOST_CONTAINER_CATCH_END
  182. }
  183. template<class T, class U, class V>
  184. inline
  185. typename dtl::enable_if<dtl::is_pair<T>, void >::type
  186. construct_type(T* p, BOOST_FWD_REF(U) x, BOOST_FWD_REF(V) y)
  187. {
  188. dtl::construct_type(dtl::addressof(p->first), ::boost::forward<U>(x));
  189. BOOST_CONTAINER_TRY{
  190. dtl::construct_type(dtl::addressof(p->second), ::boost::forward<V>(y));
  191. }
  192. BOOST_CONTAINER_CATCH(...) {
  193. typedef typename T::first_type first_type;
  194. dtl::addressof(p->first)->~first_type();
  195. BOOST_CONTAINER_RETHROW
  196. }
  197. BOOST_CONTAINER_CATCH_END
  198. }
  199. } //namespace dtl
  200. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  201. template<class T, class VoidAllocator, class Options>
  202. class small_vector_allocator;
  203. namespace allocator_traits_detail {
  204. BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_max_size, max_size)
  205. BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_select_on_container_copy_construction, select_on_container_copy_construction)
  206. } //namespace allocator_traits_detail {
  207. namespace dtl {
  208. //workaround needed for C++03 compilers with no construct()
  209. //supporting rvalue references
  210. template<class Allocator>
  211. struct is_std_allocator
  212. { BOOST_STATIC_CONSTEXPR bool value = false; };
  213. template<class T>
  214. struct is_std_allocator< std::allocator<T> >
  215. { BOOST_STATIC_CONSTEXPR bool value = true; };
  216. template<class T, class Options>
  217. struct is_std_allocator< small_vector_allocator<T, std::allocator<T>, Options > >
  218. { BOOST_STATIC_CONSTEXPR bool value = true; };
  219. template<class Allocator>
  220. struct is_not_std_allocator
  221. { BOOST_STATIC_CONSTEXPR bool value = !is_std_allocator<Allocator>::value; };
  222. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(pointer)
  223. BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(const_pointer)
  224. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference)
  225. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reference)
  226. BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(void_pointer)
  227. BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(const_void_pointer)
  228. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(size_type)
  229. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_copy_assignment)
  230. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_move_assignment)
  231. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_swap)
  232. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(is_always_equal)
  233. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type)
  234. BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(is_partially_propagable)
  235. } //namespace dtl {
  236. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  237. //! The class template allocator_traits supplies a uniform interface to all allocator types.
  238. //! This class is a C++03-compatible implementation of std::allocator_traits
  239. template <typename Allocator>
  240. struct allocator_traits
  241. {
  242. //allocator_type
  243. typedef Allocator allocator_type;
  244. //value_type
  245. typedef typename allocator_type::value_type value_type;
  246. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  247. //! Allocator::pointer if such a type exists; otherwise, value_type*
  248. //!
  249. typedef unspecified pointer;
  250. //! Allocator::const_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const
  251. //!
  252. typedef see_documentation const_pointer;
  253. //! Non-standard extension
  254. //! Allocator::reference if such a type exists; otherwise, value_type&
  255. typedef see_documentation reference;
  256. //! Non-standard extension
  257. //! Allocator::const_reference if such a type exists ; otherwise, const value_type&
  258. typedef see_documentation const_reference;
  259. //! Allocator::void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<void>.
  260. //!
  261. typedef see_documentation void_pointer;
  262. //! Allocator::const_void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const
  263. //!
  264. typedef see_documentation const_void_pointer;
  265. //! Allocator::difference_type if such a type exists ; otherwise, pointer_traits<pointer>::difference_type.
  266. //!
  267. typedef see_documentation difference_type;
  268. //! Allocator::size_type if such a type exists ; otherwise, make_unsigned<difference_type>::type
  269. //!
  270. typedef see_documentation size_type;
  271. //! Allocator::propagate_on_container_copy_assignment if such a type exists, otherwise a type
  272. //! with an internal constant static boolean member <code>value</code> == false.
  273. typedef see_documentation propagate_on_container_copy_assignment;
  274. //! Allocator::propagate_on_container_move_assignment if such a type exists, otherwise a type
  275. //! with an internal constant static boolean member <code>value</code> == false.
  276. typedef see_documentation propagate_on_container_move_assignment;
  277. //! Allocator::propagate_on_container_swap if such a type exists, otherwise a type
  278. //! with an internal constant static boolean member <code>value</code> == false.
  279. typedef see_documentation propagate_on_container_swap;
  280. //! Allocator::is_always_equal if such a type exists, otherwise a type
  281. //! with an internal constant static boolean member <code>value</code> == is_empty<Allocator>::value
  282. typedef see_documentation is_always_equal;
  283. //! Allocator::is_partially_propagable if such a type exists, otherwise a type
  284. //! with an internal constant static boolean member <code>value</code> == false
  285. //! <b>Note</b>: Non-standard extension used to implement `small_vector_allocator`.
  286. typedef see_documentation is_partially_propagable;
  287. //! Defines an allocator: Allocator::rebind<T>::other if such a type exists; otherwise, Allocator<T, Args>
  288. //! if Allocator is a class template instantiation of the form Allocator<U, Args>, where Args is zero or
  289. //! more type arguments ; otherwise, the instantiation of rebind_alloc is ill-formed.
  290. //!
  291. //! In C++03 compilers <code>rebind_alloc</code> is a struct derived from an allocator
  292. //! deduced by previously detailed rules.
  293. template <class T> using rebind_alloc = see_documentation;
  294. //! In C++03 compilers <code>rebind_traits</code> is a struct derived from
  295. //! <code>allocator_traits<OtherAlloc></code>, where <code>OtherAlloc</code> is
  296. //! the allocator deduced by rules explained in <code>rebind_alloc</code>.
  297. template <class T> using rebind_traits = allocator_traits<rebind_alloc<T> >;
  298. //! Non-standard extension: Portable allocator rebind for C++03 and C++11 compilers.
  299. //! <code>type</code> is an allocator related to Allocator deduced deduced by rules explained in <code>rebind_alloc</code>.
  300. template <class T>
  301. struct portable_rebind_alloc
  302. { typedef see_documentation type; };
  303. #else
  304. //pointer
  305. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  306. pointer, value_type*)
  307. pointer;
  308. //const_pointer
  309. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator,
  310. const_pointer, typename boost::intrusive::pointer_traits<pointer>::template
  311. rebind_pointer<const value_type>)
  312. const_pointer;
  313. //reference
  314. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  315. reference, typename dtl::unvoid_ref<value_type>::type)
  316. reference;
  317. //const_reference
  318. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  319. const_reference, typename dtl::unvoid_ref<const value_type>::type)
  320. const_reference;
  321. //void_pointer
  322. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator,
  323. void_pointer, typename boost::intrusive::pointer_traits<pointer>::template
  324. rebind_pointer<void>)
  325. void_pointer;
  326. //const_void_pointer
  327. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(boost::container::dtl::, Allocator,
  328. const_void_pointer, typename boost::intrusive::pointer_traits<pointer>::template
  329. rebind_pointer<const void>)
  330. const_void_pointer;
  331. //difference_type
  332. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  333. difference_type, std::ptrdiff_t)
  334. difference_type;
  335. //size_type
  336. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  337. size_type, std::size_t)
  338. size_type;
  339. //propagate_on_container_copy_assignment
  340. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  341. propagate_on_container_copy_assignment, dtl::false_type)
  342. propagate_on_container_copy_assignment;
  343. //propagate_on_container_move_assignment
  344. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  345. propagate_on_container_move_assignment, dtl::false_type)
  346. propagate_on_container_move_assignment;
  347. //propagate_on_container_swap
  348. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  349. propagate_on_container_swap, dtl::false_type)
  350. propagate_on_container_swap;
  351. //is_always_equal
  352. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  353. is_always_equal, dtl::is_empty<Allocator>)
  354. is_always_equal;
  355. //is_partially_propagable
  356. typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(boost::container::dtl::, Allocator,
  357. is_partially_propagable, dtl::false_type)
  358. is_partially_propagable;
  359. //rebind_alloc & rebind_traits
  360. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  361. //C++11
  362. template <typename T> using rebind_alloc = typename boost::intrusive::pointer_rebind<Allocator, T>::type;
  363. template <typename T> using rebind_traits = allocator_traits< rebind_alloc<T> >;
  364. #else // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  365. //Some workaround for C++03 or C++11 compilers with no template aliases
  366. template <typename T>
  367. struct rebind_alloc : boost::intrusive::pointer_rebind<Allocator,T>::type
  368. {
  369. typedef typename boost::intrusive::pointer_rebind<Allocator,T>::type Base;
  370. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  371. template <typename... Args>
  372. rebind_alloc(BOOST_FWD_REF(Args)... args) : Base(boost::forward<Args>(args)...) {}
  373. #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  374. #define BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC(N) \
  375. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N\
  376. explicit rebind_alloc(BOOST_MOVE_UREF##N) : Base(BOOST_MOVE_FWD##N){}\
  377. //
  378. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC)
  379. #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_REBIND_ALLOC
  380. #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  381. };
  382. template <typename T>
  383. struct rebind_traits
  384. : allocator_traits<typename boost::intrusive::pointer_rebind<Allocator, T>::type>
  385. {};
  386. #endif // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  387. //portable_rebind_alloc
  388. template <class T>
  389. struct portable_rebind_alloc
  390. { typedef typename boost::intrusive::pointer_rebind<Allocator, T>::type type; };
  391. #endif //BOOST_CONTAINER_DOXYGEN_INVOKED
  392. //! <b>Returns</b>: <code>a.allocate(n)</code>
  393. //!
  394. inline static pointer allocate(Allocator &a, size_type n)
  395. { return a.allocate(n); }
  396. //! <b>Returns</b>: <code>a.deallocate(p, n)</code>
  397. //!
  398. //! <b>Throws</b>: Nothing
  399. inline static void deallocate(Allocator &a, pointer p, size_type n)
  400. { a.deallocate(p, n); }
  401. //! <b>Effects</b>: calls <code>a.allocate(n, p)</code> if that call is well-formed;
  402. //! otherwise, invokes <code>a.allocate(n)</code>
  403. inline static pointer allocate(Allocator &a, size_type n, const_void_pointer p)
  404. {
  405. const bool value = boost::container::dtl::
  406. has_member_function_callable_with_allocate
  407. <Allocator, const size_type, const const_void_pointer>::value;
  408. dtl::bool_<value> flag;
  409. return allocator_traits::priv_allocate(flag, a, n, p);
  410. }
  411. //! <b>Effects</b>: calls <code>a.destroy(p)</code> if that call is well-formed;
  412. //! otherwise, invokes <code>p->~T()</code>.
  413. template<class T>
  414. inline static void destroy(Allocator &a, T*p) BOOST_NOEXCEPT_OR_NOTHROW
  415. {
  416. typedef T* destroy_pointer;
  417. const bool value = boost::container::dtl::
  418. has_member_function_callable_with_destroy
  419. <Allocator, const destroy_pointer>::value;
  420. dtl::bool_<value> flag;
  421. allocator_traits::priv_destroy(flag, a, p);
  422. }
  423. //! <b>Returns</b>: <code>a.max_size()</code> if that expression is well-formed; otherwise,
  424. //! <code>numeric_limits<size_type>::max()</code>.
  425. inline static size_type max_size(const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW
  426. {
  427. const bool value = allocator_traits_detail::has_max_size<Allocator, size_type (Allocator::*)() const>::value;
  428. dtl::bool_<value> flag;
  429. return allocator_traits::priv_max_size(flag, a);
  430. }
  431. //! <b>Returns</b>: <code>a.select_on_container_copy_construction()</code> if that expression is well-formed;
  432. //! otherwise, a.
  433. inline static BOOST_CONTAINER_DOC1ST(Allocator,
  434. typename dtl::if_c
  435. < allocator_traits_detail::has_select_on_container_copy_construction<Allocator BOOST_MOVE_I Allocator (Allocator::*)() const>::value
  436. BOOST_MOVE_I Allocator BOOST_MOVE_I const Allocator & >::type)
  437. select_on_container_copy_construction(const Allocator &a)
  438. {
  439. const bool value = allocator_traits_detail::has_select_on_container_copy_construction
  440. <Allocator, Allocator (Allocator::*)() const>::value;
  441. dtl::bool_<value> flag;
  442. return allocator_traits::priv_select_on_container_copy_construction(flag, a);
  443. }
  444. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  445. //! <b>Effects</b>: calls <code>a.construct(p, std::forward<Args>(args)...)</code> if that call is well-formed;
  446. //! otherwise, invokes <code>`placement new` (static_cast<void*>(p)) T(std::forward<Args>(args)...)</code>
  447. template <class T, class ...Args>
  448. inline static void construct(Allocator & a, T* p, BOOST_FWD_REF(Args)... args)
  449. {
  450. BOOST_STATIC_CONSTEXPR bool value = ::boost::move_detail::and_
  451. < dtl::is_not_std_allocator<Allocator>
  452. , boost::container::dtl::has_member_function_callable_with_construct
  453. < Allocator, T*, Args... >
  454. >::value;
  455. dtl::bool_<value> flag;
  456. allocator_traits::priv_construct(flag, a, p, ::boost::forward<Args>(args)...);
  457. }
  458. #endif
  459. //! <b>Returns</b>: <code>a.storage_is_unpropagable(p)</code> if is_partially_propagable::value is true; otherwise,
  460. //! <code>false</code>.
  461. inline static bool storage_is_unpropagable(const Allocator &a, pointer p) BOOST_NOEXCEPT_OR_NOTHROW
  462. {
  463. dtl::bool_<is_partially_propagable::value> flag;
  464. return allocator_traits::priv_storage_is_unpropagable(flag, a, p);
  465. }
  466. //! <b>Returns</b>: <code>true</code> if <code>is_always_equal::value == true</code>, otherwise,
  467. //! <code>a == b</code>.
  468. inline static bool equal(const Allocator &a, const Allocator &b) BOOST_NOEXCEPT_OR_NOTHROW
  469. {
  470. dtl::bool_<is_always_equal::value> flag;
  471. return allocator_traits::priv_equal(flag, a, b);
  472. }
  473. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  474. private:
  475. inline static pointer priv_allocate(dtl::true_type, Allocator &a, size_type n, const_void_pointer p)
  476. { return a.allocate(n, p); }
  477. inline static pointer priv_allocate(dtl::false_type, Allocator &a, size_type n, const_void_pointer)
  478. { return a.allocate(n); }
  479. template<class T>
  480. inline static void priv_destroy(dtl::true_type, Allocator &a, T* p) BOOST_NOEXCEPT_OR_NOTHROW
  481. { a.destroy(p); }
  482. template<class T>
  483. inline static void priv_destroy(dtl::false_type, Allocator &, T* p) BOOST_NOEXCEPT_OR_NOTHROW
  484. { p->~T(); (void)p; }
  485. inline static size_type priv_max_size(dtl::true_type, const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW
  486. { return a.max_size(); }
  487. inline static size_type priv_max_size(dtl::false_type, const Allocator &) BOOST_NOEXCEPT_OR_NOTHROW
  488. { return size_type(-1)/sizeof(value_type); }
  489. inline static Allocator priv_select_on_container_copy_construction(dtl::true_type, const Allocator &a)
  490. { return a.select_on_container_copy_construction(); }
  491. inline static const Allocator &priv_select_on_container_copy_construction(dtl::false_type, const Allocator &a) BOOST_NOEXCEPT_OR_NOTHROW
  492. { return a; }
  493. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  494. template<class T, class ...Args>
  495. inline static void priv_construct(dtl::true_type, Allocator &a, T *p, BOOST_FWD_REF(Args) ...args)
  496. { a.construct( p, ::boost::forward<Args>(args)...); }
  497. template<class T, class ...Args>
  498. inline static void priv_construct(dtl::false_type, Allocator &, T *p, BOOST_FWD_REF(Args) ...args)
  499. { dtl::construct_type(p, ::boost::forward<Args>(args)...); }
  500. #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  501. public:
  502. #define BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL(N) \
  503. template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  504. inline static void construct(Allocator &a, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  505. {\
  506. BOOST_STATIC_CONSTEXPR bool value = ::boost::move_detail::and_ \
  507. < dtl::is_not_std_allocator<Allocator> \
  508. , boost::container::dtl::has_member_function_callable_with_construct \
  509. < Allocator, T* BOOST_MOVE_I##N BOOST_MOVE_FWD_T##N > \
  510. >::value; \
  511. dtl::bool_<value> flag;\
  512. (priv_construct)(flag, a, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  513. }\
  514. //
  515. BOOST_MOVE_ITERATE_0TO8(BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL)
  516. #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_CONSTRUCT_IMPL
  517. private:
  518. /////////////////////////////////
  519. // priv_construct
  520. /////////////////////////////////
  521. #define BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL(N) \
  522. template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  523. inline static void priv_construct(dtl::true_type, Allocator &a, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  524. { a.construct( p BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); }\
  525. \
  526. template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  527. inline static void priv_construct(dtl::false_type, Allocator &, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  528. { dtl::construct_type(p BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
  529. //
  530. BOOST_MOVE_ITERATE_0TO8(BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL)
  531. #undef BOOST_CONTAINER_ALLOCATOR_TRAITS_PRIV_CONSTRUCT_IMPL
  532. #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  533. template<class T>
  534. inline static void priv_construct(dtl::false_type, Allocator &, T *p, const ::boost::container::default_init_t&)
  535. { ::new((void*)p, boost_container_new_t()) T; }
  536. inline static bool priv_storage_is_unpropagable(dtl::true_type, const Allocator &a, pointer p)
  537. { return a.storage_is_unpropagable(p); }
  538. inline static bool priv_storage_is_unpropagable(dtl::false_type, const Allocator &, pointer)
  539. { return false; }
  540. inline static bool priv_equal(dtl::true_type, const Allocator &, const Allocator &)
  541. { return true; }
  542. inline static bool priv_equal(dtl::false_type, const Allocator &a, const Allocator &b)
  543. { return a == b; }
  544. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  545. };
  546. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  547. template<class T, class AllocatorOrVoid>
  548. struct real_allocator
  549. {
  550. typedef AllocatorOrVoid type;
  551. };
  552. template<class T>
  553. struct real_allocator<T, void>
  554. {
  555. typedef new_allocator<T> type;
  556. };
  557. #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  558. } //namespace container {
  559. } //namespace boost {
  560. #include <boost/container/detail/config_end.hpp>
  561. #endif // ! defined(BOOST_CONTAINER_ALLOCATOR_ALLOCATOR_TRAITS_HPP)