allocator_traits.hpp 30 KB

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