numbered.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // NO INCLUDE GUARDS, THE HEADER IS INTENDED FOR MULTIPLE INCLUSION
  2. #if defined(BOOST_PP_IS_ITERATING)
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/preprocessor/enum_params.hpp>
  14. #include <boost/preprocessor/enum_shifted_params.hpp>
  15. #include <boost/preprocessor/comma_if.hpp>
  16. #include <boost/preprocessor/repeat.hpp>
  17. #include <boost/preprocessor/dec.hpp>
  18. #include <boost/preprocessor/cat.hpp>
  19. #define i_ BOOST_PP_FRAME_ITERATION(1)
  20. #if defined(BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES)
  21. # define AUX778076_VECTOR_TAIL(vector, i_, T) \
  22. BOOST_PP_CAT(vector,i_)< \
  23. BOOST_PP_ENUM_PARAMS(i_, T) \
  24. > \
  25. /**/
  26. #if i_ > 0
  27. template<
  28. BOOST_PP_ENUM_PARAMS(i_, typename T)
  29. >
  30. struct BOOST_PP_CAT(vector,i_)
  31. : v_item<
  32. BOOST_PP_CAT(T,BOOST_PP_DEC(i_))
  33. , AUX778076_VECTOR_TAIL(vector,BOOST_PP_DEC(i_),T)
  34. >
  35. {
  36. typedef BOOST_PP_CAT(vector,i_) type;
  37. };
  38. #endif
  39. # undef AUX778076_VECTOR_TAIL
  40. #else // "brute force" implementation
  41. # if i_ > 0
  42. template<
  43. BOOST_PP_ENUM_PARAMS(i_, typename T)
  44. >
  45. struct BOOST_PP_CAT(vector,i_)
  46. {
  47. typedef aux::vector_tag<i_> tag;
  48. typedef BOOST_PP_CAT(vector,i_) type;
  49. # define AUX778076_VECTOR_ITEM(unused, i_, unused2) \
  50. typedef BOOST_PP_CAT(T,i_) BOOST_PP_CAT(item,i_); \
  51. /**/
  52. BOOST_PP_REPEAT(i_, AUX778076_VECTOR_ITEM, unused)
  53. # undef AUX778076_VECTOR_ITEM
  54. typedef void_ BOOST_PP_CAT(item,i_);
  55. typedef BOOST_PP_CAT(T,BOOST_PP_DEC(i_)) back;
  56. // Borland forces us to use 'type' here (instead of the class name)
  57. typedef v_iter<type,0> begin;
  58. typedef v_iter<type,i_> end;
  59. };
  60. template<>
  61. struct push_front_impl< aux::vector_tag<BOOST_PP_DEC(i_)> >
  62. {
  63. template< typename Vector, typename T > struct apply
  64. {
  65. typedef BOOST_PP_CAT(vector,i_)<
  66. T
  67. BOOST_PP_COMMA_IF(BOOST_PP_DEC(i_))
  68. BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(i_), typename Vector::item)
  69. > type;
  70. };
  71. };
  72. template<>
  73. struct pop_front_impl< aux::vector_tag<i_> >
  74. {
  75. template< typename Vector > struct apply
  76. {
  77. typedef BOOST_PP_CAT(vector,BOOST_PP_DEC(i_))<
  78. BOOST_PP_ENUM_SHIFTED_PARAMS(i_, typename Vector::item)
  79. > type;
  80. };
  81. };
  82. template<>
  83. struct push_back_impl< aux::vector_tag<BOOST_PP_DEC(i_)> >
  84. {
  85. template< typename Vector, typename T > struct apply
  86. {
  87. typedef BOOST_PP_CAT(vector,i_)<
  88. BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(i_), typename Vector::item)
  89. BOOST_PP_COMMA_IF(BOOST_PP_DEC(i_))
  90. T
  91. > type;
  92. };
  93. };
  94. template<>
  95. struct pop_back_impl< aux::vector_tag<i_> >
  96. {
  97. template< typename Vector > struct apply
  98. {
  99. typedef BOOST_PP_CAT(vector,BOOST_PP_DEC(i_))<
  100. BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(i_), typename Vector::item)
  101. > type;
  102. };
  103. };
  104. # endif // i_ > 0
  105. # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
  106. && !defined(BOOST_MPL_CFG_NO_NONTYPE_TEMPLATE_PARTIAL_SPEC)
  107. template< typename V >
  108. struct v_at<V,i_>
  109. {
  110. typedef typename V::BOOST_PP_CAT(item,i_) type;
  111. };
  112. # else
  113. namespace aux {
  114. template<> struct v_at_impl<i_>
  115. {
  116. template< typename V_ > struct result_
  117. {
  118. typedef typename V_::BOOST_PP_CAT(item,i_) type;
  119. };
  120. };
  121. }
  122. template<>
  123. struct at_impl< aux::vector_tag<i_> >
  124. {
  125. template< typename V_, typename N > struct apply
  126. {
  127. typedef typename aux::v_at_impl<BOOST_MPL_AUX_VALUE_WKND(N)::value>
  128. ::template result_<V_>::type type;
  129. };
  130. };
  131. #if i_ > 0
  132. template<>
  133. struct front_impl< aux::vector_tag<i_> >
  134. {
  135. template< typename Vector > struct apply
  136. {
  137. typedef typename Vector::item0 type;
  138. };
  139. };
  140. template<>
  141. struct back_impl< aux::vector_tag<i_> >
  142. {
  143. template< typename Vector > struct apply
  144. {
  145. typedef typename Vector::back type;
  146. };
  147. };
  148. template<>
  149. struct empty_impl< aux::vector_tag<i_> >
  150. {
  151. template< typename Vector > struct apply
  152. : false_
  153. {
  154. };
  155. };
  156. #endif
  157. template<>
  158. struct size_impl< aux::vector_tag<i_> >
  159. {
  160. template< typename Vector > struct apply
  161. : long_<i_>
  162. {
  163. };
  164. };
  165. template<>
  166. struct O1_size_impl< aux::vector_tag<i_> >
  167. : size_impl< aux::vector_tag<i_> >
  168. {
  169. };
  170. template<>
  171. struct clear_impl< aux::vector_tag<i_> >
  172. {
  173. template< typename Vector > struct apply
  174. {
  175. typedef vector0<> type;
  176. };
  177. };
  178. # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  179. #endif // BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES
  180. #undef i_
  181. #endif // BOOST_PP_IS_ITERATING