allocator_traits.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. Copyright 2021 Glen Joseph Fernandes
  3. ([email protected])
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BOOST_CORE_ALLOCATOR_TRAITS_HPP
  8. #define BOOST_CORE_ALLOCATOR_TRAITS_HPP
  9. #include <boost/core/allocator_access.hpp>
  10. namespace boost {
  11. template<class A>
  12. struct allocator_traits {
  13. typedef A allocator_type;
  14. typedef typename allocator_value_type<A>::type value_type;
  15. typedef typename allocator_pointer<A>::type pointer;
  16. typedef typename allocator_const_pointer<A>::type const_pointer;
  17. typedef typename allocator_void_pointer<A>::type void_pointer;
  18. typedef typename allocator_const_void_pointer<A>::type const_void_pointer;
  19. typedef typename allocator_difference_type<A>::type difference_type;
  20. typedef typename allocator_size_type<A>::type size_type;
  21. typedef typename allocator_propagate_on_container_copy_assignment<A>::type
  22. propagate_on_container_copy_assignment;
  23. typedef typename allocator_propagate_on_container_move_assignment<A>::type
  24. propagate_on_container_move_assignment;
  25. typedef typename allocator_propagate_on_container_swap<A>::type
  26. propagate_on_container_swap;
  27. typedef typename allocator_is_always_equal<A>::type is_always_equal;
  28. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  29. template<class T>
  30. using rebind_traits = allocator_traits<typename
  31. allocator_rebind<A, T>::type>;
  32. #else
  33. template<class T>
  34. struct rebind_traits
  35. : allocator_traits<typename allocator_rebind<A, T>::type> { };
  36. #endif
  37. static pointer allocate(A& a, size_type n) {
  38. return boost::allocator_allocate(a, n);
  39. }
  40. static pointer allocate(A& a, size_type n, const_void_pointer h) {
  41. return boost::allocator_allocate(a, n, h);
  42. }
  43. static void deallocate(A& a, pointer p, size_type n) {
  44. return boost::allocator_deallocate(a, p, n);
  45. }
  46. template<class T>
  47. static void construct(A& a, T* p) {
  48. boost::allocator_construct(a, p);
  49. }
  50. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  51. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  52. template<class T, class V, class... Args>
  53. static void construct(A& a, T* p, V&& v, Args&&... args) {
  54. boost::allocator_construct(a, p, std::forward<V>(v),
  55. std::forward<Args>(args)...);
  56. }
  57. #else
  58. template<class T, class V>
  59. static void construct(A& a, T* p, V&& v) {
  60. boost::allocator_construct(a, p, std::forward<V>(v));
  61. }
  62. #endif
  63. #else
  64. template<class T, class V>
  65. static void construct(A& a, T* p, const V& v) {
  66. boost::allocator_construct(a, p, v);
  67. }
  68. template<class T, class V>
  69. static void construct(A& a, T* p, V& v) {
  70. boost::allocator_construct(a, p, v);
  71. }
  72. #endif
  73. template<class T>
  74. static void destroy(A& a, T* p) {
  75. boost::allocator_destroy(a, p);
  76. }
  77. static size_type max_size(const A& a) BOOST_NOEXCEPT {
  78. return boost::allocator_max_size(a);
  79. }
  80. static A select_on_container_copy_construction(const A& a) {
  81. return boost::allocator_select_on_container_copy_construction(a);
  82. }
  83. };
  84. } /* boost */
  85. #endif