vector.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Copyright (C) 2005 Arkadiy Vertleyb
  2. // Copyright (C) 2005 Peder Holt
  3. //
  4. // Copyright (C) 2006 Tobias Schwinger
  5. //
  6. // Use, modification and distribution is subject to the Boost Software
  7. // License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_TYPEOF_VECTOR_HPP_INCLUDED
  9. #include <boost/typeof/constant.hpp>
  10. #include <boost/preprocessor/iteration/self.hpp>
  11. #ifndef BOOST_TYPEOF_LIMIT_SIZE
  12. # define BOOST_TYPEOF_LIMIT_SIZE 50
  13. #endif
  14. //
  15. // To recreate the preprocessed versions of this file preprocess and run
  16. //
  17. // $(BOOST_ROOT)/libs/typeof/tools/preprocess.pl
  18. //
  19. #if defined(BOOST_TYPEOF_PP_INCLUDE_EXTERNAL)
  20. # undef BOOST_TYPEOF_PP_INCLUDE_EXTERNAL
  21. #elif !defined(BOOST_TYPEOF_PREPROCESSING_MODE) && !BOOST_PP_IS_SELFISH
  22. # define BOOST_PP_INDIRECT_SELF <boost/typeof/vector.hpp>
  23. # if BOOST_TYPEOF_LIMIT_SIZE < 50
  24. # include BOOST_PP_INCLUDE_SELF()
  25. # elif BOOST_TYPEOF_LIMIT_SIZE < 100
  26. # include <boost/typeof/vector50.hpp>
  27. # define BOOST_TYPEOF_PP_START_SIZE 51
  28. # include BOOST_PP_INCLUDE_SELF()
  29. # elif BOOST_TYPEOF_LIMIT_SIZE < 150
  30. # include <boost/typeof/vector100.hpp>
  31. # define BOOST_TYPEOF_PP_START_SIZE 101
  32. # include BOOST_PP_INCLUDE_SELF()
  33. # elif BOOST_TYPEOF_LIMIT_SIZE < 200
  34. # include <boost/typeof/vector150.hpp>
  35. # define BOOST_TYPEOF_PP_START_SIZE 151
  36. # include BOOST_PP_INCLUDE_SELF()
  37. # elif BOOST_TYPEOF_LIMIT_SIZE <= 250
  38. # include <boost/typeof/vector200.hpp>
  39. # define BOOST_TYPEOF_PP_START_SIZE 201
  40. # include BOOST_PP_INCLUDE_SELF()
  41. # else
  42. # error "BOOST_TYPEOF_LIMIT_SIZE too high"
  43. # endif
  44. #else// defined(BOOST_TYPEOF_PREPROCESSING_MODE) || BOOST_PP_IS_SELFISH
  45. # ifndef BOOST_TYPEOF_PP_NEXT_SIZE
  46. # define BOOST_TYPEOF_PP_NEXT_SIZE BOOST_TYPEOF_LIMIT_SIZE
  47. # endif
  48. # ifndef BOOST_TYPEOF_PP_START_SIZE
  49. # define BOOST_TYPEOF_PP_START_SIZE 0
  50. # endif
  51. # if BOOST_TYPEOF_PP_START_SIZE <= BOOST_TYPEOF_LIMIT_SIZE
  52. # include <boost/preprocessor/enum_params.hpp>
  53. # include <boost/preprocessor/repeat.hpp>
  54. # include <boost/preprocessor/repeat_from_to.hpp>
  55. # include <boost/preprocessor/cat.hpp>
  56. # include <boost/preprocessor/inc.hpp>
  57. # include <boost/preprocessor/dec.hpp>
  58. # include <boost/preprocessor/comma_if.hpp>
  59. # include <boost/preprocessor/iteration/local.hpp>
  60. # include <boost/preprocessor/control/expr_iif.hpp>
  61. # include <boost/preprocessor/logical/not.hpp>
  62. // iterator
  63. # define BOOST_TYPEOF_spec_iter(n)\
  64. template<class V>\
  65. struct v_iter<V, constant<int,n> >\
  66. {\
  67. typedef typename V::item ## n type;\
  68. typedef v_iter<V, constant<int,n + 1> > next;\
  69. };
  70. namespace boost { namespace type_of {
  71. template<class V, class Increase_BOOST_TYPEOF_LIMIT_SIZE> struct v_iter; // not defined
  72. # define BOOST_PP_LOCAL_MACRO BOOST_TYPEOF_spec_iter
  73. # define BOOST_PP_LOCAL_LIMITS \
  74. (BOOST_PP_DEC(BOOST_TYPEOF_PP_START_SIZE), \
  75. BOOST_PP_DEC(BOOST_TYPEOF_LIMIT_SIZE))
  76. # include BOOST_PP_LOCAL_ITERATE()
  77. }}
  78. # undef BOOST_TYPEOF_spec_iter
  79. // vector
  80. # define BOOST_TYPEOF_typedef_item(z, n, _)\
  81. typedef P ## n item ## n;
  82. # define BOOST_TYPEOF_typedef_fake_item(z, n, _)\
  83. typedef constant<int,1> item ## n;
  84. # define BOOST_TYPEOF_define_vector(n)\
  85. template<BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IIF(BOOST_PP_NOT(n), class T = void)>\
  86. struct vector ## n\
  87. {\
  88. typedef v_iter<vector ## n<BOOST_PP_ENUM_PARAMS(n,P)>, boost::type_of::constant<int,0> > begin;\
  89. BOOST_PP_REPEAT(n, BOOST_TYPEOF_typedef_item, ~)\
  90. BOOST_PP_REPEAT_FROM_TO(n, BOOST_TYPEOF_PP_NEXT_SIZE, BOOST_TYPEOF_typedef_fake_item, ~)\
  91. };
  92. namespace boost { namespace type_of {
  93. # define BOOST_PP_LOCAL_MACRO BOOST_TYPEOF_define_vector
  94. # define BOOST_PP_LOCAL_LIMITS \
  95. (BOOST_TYPEOF_PP_START_SIZE,BOOST_TYPEOF_LIMIT_SIZE)
  96. # include BOOST_PP_LOCAL_ITERATE()
  97. }}
  98. # undef BOOST_TYPEOF_typedef_item
  99. # undef BOOST_TYPEOF_typedef_fake_item
  100. # undef BOOST_TYPEOF_define_vector
  101. // push_back
  102. # define BOOST_TYPEOF_spec_push_back(n)\
  103. template<BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_COMMA_IF(n) class T>\
  104. struct push_back<BOOST_PP_CAT(boost::type_of::vector, n)<BOOST_PP_ENUM_PARAMS(n, P)>, T>\
  105. {\
  106. typedef BOOST_PP_CAT(boost::type_of::vector, BOOST_PP_INC(n))<\
  107. BOOST_PP_ENUM_PARAMS(n, P) BOOST_PP_COMMA_IF(n) T\
  108. > type;\
  109. };
  110. namespace boost { namespace type_of {
  111. # if BOOST_TYPEOF_LIMIT_SIZE < 50
  112. template<class V, class T> struct push_back {
  113. typedef V type;
  114. };
  115. # endif
  116. //default behaviour is to let push_back ignore T, and return the input vector.
  117. //This is to let BOOST_TYPEOF_NESTED_TYPEDEF work properly with the default vector.
  118. # define BOOST_PP_LOCAL_MACRO BOOST_TYPEOF_spec_push_back
  119. # define BOOST_PP_LOCAL_LIMITS \
  120. (BOOST_PP_DEC(BOOST_TYPEOF_PP_START_SIZE), \
  121. BOOST_PP_DEC(BOOST_TYPEOF_LIMIT_SIZE))
  122. # include BOOST_PP_LOCAL_ITERATE()
  123. }}
  124. # undef BOOST_TYPEOF_spec_push_back
  125. # endif//BOOST_TYPEOF_PP_START_SIZE<=BOOST_TYPEOF_LIMIT_SIZE
  126. # undef BOOST_TYPEOF_PP_START_SIZE
  127. # undef BOOST_TYPEOF_PP_NEXT_SIZE
  128. #endif//BOOST_TYPEOF_PREPROCESSING_MODE || BOOST_PP_IS_SELFISH
  129. #define BOOST_TYPEOF_VECTOR_HPP_INCLUDED
  130. #endif//BOOST_TYPEOF_VECTOR_HPP_INCLUDED