container_rebind.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2017-2017. 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. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_DETAIL_CONTAINER_REBIND_HPP
  11. #define BOOST_CONTAINER_DETAIL_CONTAINER_REBIND_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #include <boost/container/allocator_traits.hpp>
  19. #include <boost/container/container_fwd.hpp>
  20. namespace boost {
  21. namespace container {
  22. namespace dtl {
  23. template <class Cont, class U>
  24. struct container_rebind;
  25. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  26. template <template <class, class, class...> class Cont, typename V, typename A, class... An, class U>
  27. struct container_rebind<Cont<V, A, An...>, U>
  28. {
  29. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, An...> type;
  30. };
  31. //Needed for non-conforming compilers like GCC 4.3
  32. template <template <class, class> class Cont, typename V, typename A, class U>
  33. struct container_rebind<Cont<V, A>, U>
  34. {
  35. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type> type;
  36. };
  37. template <template <class> class Cont, typename V, class U>
  38. struct container_rebind<Cont<V>, U>
  39. {
  40. typedef Cont<U> type;
  41. };
  42. #else //C++03 compilers
  43. template <template <class> class Cont //0arg
  44. , typename V
  45. , class U>
  46. struct container_rebind<Cont<V>, U>
  47. {
  48. typedef Cont<U> type;
  49. };
  50. template <template <class, class> class Cont //0arg
  51. , typename V, typename A
  52. , class U>
  53. struct container_rebind<Cont<V, A>, U>
  54. {
  55. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type> type;
  56. };
  57. template <template <class, class, class> class Cont //1arg
  58. , typename V, typename A, class P0
  59. , class U>
  60. struct container_rebind<Cont<V, A, P0>, U>
  61. {
  62. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0> type;
  63. };
  64. template <template <class, class, class, class> class Cont //2arg
  65. , typename V, typename A, class P0, class P1
  66. , class U>
  67. struct container_rebind<Cont<V, A, P0, P1>, U>
  68. {
  69. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0, P1> type;
  70. };
  71. template <template <class, class, class, class, class> class Cont //3arg
  72. , typename V, typename A, class P0, class P1, class P2
  73. , class U>
  74. struct container_rebind<Cont<V, A, P0, P1, P2>, U>
  75. {
  76. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0, P1, P2> type;
  77. };
  78. template <template <class, class, class, class, class, class> class Cont //4arg
  79. , typename V, typename A, class P0, class P1, class P2, class P3
  80. , class U>
  81. struct container_rebind<Cont<V, A, P0, P1, P2, P3>, U>
  82. {
  83. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0, P1, P2, P3> type;
  84. };
  85. template <template <class, class, class, class, class, class, class> class Cont //5arg
  86. , typename V, typename A, class P0, class P1, class P2, class P3, class P4
  87. , class U>
  88. struct container_rebind<Cont<V, A, P0, P1, P2, P3, P4>, U>
  89. {
  90. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0, P1, P2, P3, P4> type;
  91. };
  92. template <template <class, class, class, class, class, class, class, class> class Cont //6arg
  93. , typename V, typename A, class P0, class P1, class P2, class P3, class P4, class P5
  94. , class U>
  95. struct container_rebind<Cont<V, A, P0, P1, P2, P3, P4, P5>, U>
  96. {
  97. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0, P1, P2, P3, P4, P5> type;
  98. };
  99. template <template <class, class, class, class, class, class, class, class, class> class Cont //7arg
  100. , typename V, typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6
  101. , class U>
  102. struct container_rebind<Cont<V, A, P0, P1, P2, P3, P4, P5, P6>, U>
  103. {
  104. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0, P1, P2, P3, P4, P5, P6> type;
  105. };
  106. template <template <class, class, class, class, class, class, class, class, class, class> class Cont //8arg
  107. , typename V, typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7
  108. , class U>
  109. struct container_rebind<Cont<V, A, P0, P1, P2, P3, P4, P5, P6, P7>, U>
  110. {
  111. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0, P1, P2, P3, P4, P5, P6, P7> type;
  112. };
  113. template <template <class, class, class, class, class, class, class, class, class, class, class> class Cont //9arg
  114. , typename V, typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8
  115. , class U>
  116. struct container_rebind<Cont<V, A, P0, P1, P2, P3, P4, P5, P6, P7, P8>, U>
  117. {
  118. typedef Cont<U, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type, P0, P1, P2, P3, P4, P5, P6, P7, P8> type;
  119. };
  120. #endif //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  121. //for small_vector,static_vector
  122. template <typename V, std::size_t N, typename A, class U>
  123. struct container_rebind<small_vector<V, N, A>, U>
  124. {
  125. typedef small_vector<U, N, typename allocator_traits<typename real_allocator<V, A>::type>::template portable_rebind_alloc<U>::type> type;
  126. };
  127. template <typename V, std::size_t N, typename O, class U>
  128. struct container_rebind<static_vector<V, N, O>, U>
  129. {
  130. typedef static_vector<U, N, O> type;
  131. };
  132. } //namespace dtl {
  133. } //namespace container {
  134. } //namespace boost {
  135. #endif //#ifndef BOOST_CONTAINER_DETAIL_CONTAINER_REBIND_HPP