container_rebind.hpp 6.2 KB

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