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 9 #ifndef BOOST_TYPEOF_VECTOR_HPP_INCLUDED 10 11 #include <boost/mpl/int.hpp> 12 #include <boost/preprocessor/iteration/self.hpp> 13 14 #ifndef BOOST_TYPEOF_LIMIT_SIZE 15 # define BOOST_TYPEOF_LIMIT_SIZE 50 16 #endif 17 18 // 19 // To recreate the preprocessed versions of this file preprocess and run 20 // 21 // $(BOOST_ROOT)/libs/typeof/tools/preprocess.pl 22 // 23 24 #if defined(BOOST_TYPEOF_PP_INCLUDE_EXTERNAL) 25 26 # undef BOOST_TYPEOF_PP_INCLUDE_EXTERNAL 27 28 #elif !defined(BOOST_TYPEOF_PREPROCESSING_MODE) && !BOOST_PP_IS_SELFISH 29 30 # define BOOST_PP_INDIRECT_SELF <boost/typeof/vector.hpp> 31 # if BOOST_TYPEOF_LIMIT_SIZE < 50 32 # include BOOST_PP_INCLUDE_SELF() 33 # elif BOOST_TYPEOF_LIMIT_SIZE < 100 34 # include <boost/typeof/vector50.hpp> 35 # define BOOST_TYPEOF_PP_START_SIZE 51 36 # include BOOST_PP_INCLUDE_SELF() 37 # elif BOOST_TYPEOF_LIMIT_SIZE < 150 38 # include <boost/typeof/vector100.hpp> 39 # define BOOST_TYPEOF_PP_START_SIZE 101 40 # include BOOST_PP_INCLUDE_SELF() 41 # elif BOOST_TYPEOF_LIMIT_SIZE < 200 42 # include <boost/typeof/vector150.hpp> 43 # define BOOST_TYPEOF_PP_START_SIZE 151 44 # include BOOST_PP_INCLUDE_SELF() 45 # elif BOOST_TYPEOF_LIMIT_SIZE <= 250 46 # include <boost/typeof/vector200.hpp> 47 # define BOOST_TYPEOF_PP_START_SIZE 201 48 # include BOOST_PP_INCLUDE_SELF() 49 # else 50 # error "BOOST_TYPEOF_LIMIT_SIZE too high" 51 # endif 52 53 #else// defined(BOOST_TYPEOF_PREPROCESSING_MODE) || BOOST_PP_IS_SELFISH 54 55 # ifndef BOOST_TYPEOF_PP_NEXT_SIZE 56 # define BOOST_TYPEOF_PP_NEXT_SIZE BOOST_TYPEOF_LIMIT_SIZE 57 # endif 58 # ifndef BOOST_TYPEOF_PP_START_SIZE 59 # define BOOST_TYPEOF_PP_START_SIZE 0 60 # endif 61 62 # if BOOST_TYPEOF_PP_START_SIZE <= BOOST_TYPEOF_LIMIT_SIZE 63 64 # include <boost/preprocessor/enum_params.hpp> 65 # include <boost/preprocessor/repeat.hpp> 66 # include <boost/preprocessor/repeat_from_to.hpp> 67 # include <boost/preprocessor/cat.hpp> 68 # include <boost/preprocessor/inc.hpp> 69 # include <boost/preprocessor/dec.hpp> 70 # include <boost/preprocessor/comma_if.hpp> 71 # include <boost/preprocessor/iteration/local.hpp> 72 # include <boost/preprocessor/control/expr_iif.hpp> 73 # include <boost/preprocessor/logical/not.hpp> 74 75 // iterator 76 77 # define BOOST_TYPEOF_spec_iter(n)\ 78 template<class V>\ 79 struct v_iter<V, mpl::int_<n> >\ 80 {\ 81 typedef typename V::item ## n type;\ 82 typedef v_iter<V, mpl::int_<n + 1> > next;\ 83 }; 84 85 namespace boost { namespace type_of { 86 87 template<class V, class Increase_BOOST_TYPEOF_LIMIT_SIZE> struct v_iter; // not defined 88 # define BOOST_PP_LOCAL_MACRO BOOST_TYPEOF_spec_iter 89 # define BOOST_PP_LOCAL_LIMITS \ 90 (BOOST_PP_DEC(BOOST_TYPEOF_PP_START_SIZE), \ 91 BOOST_PP_DEC(BOOST_TYPEOF_LIMIT_SIZE)) 92 # include BOOST_PP_LOCAL_ITERATE() 93 94 }} 95 96 # undef BOOST_TYPEOF_spec_iter 97 98 // vector 99 100 # define BOOST_TYPEOF_typedef_item(z, n, _)\ 101 typedef P ## n item ## n; 102 103 # define BOOST_TYPEOF_typedef_fake_item(z, n, _)\ 104 typedef mpl::int_<1> item ## n; 105 106 # define BOOST_TYPEOF_define_vector(n)\ 107 template<BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IIF(BOOST_PP_NOT(n), class T = void)>\ 108 struct vector ## n\ 109 {\ 110 typedef v_iter<vector ## n<BOOST_PP_ENUM_PARAMS(n,P)>, boost::mpl::int_<0> > begin;\ 111 BOOST_PP_REPEAT(n, BOOST_TYPEOF_typedef_item, ~)\ 112 BOOST_PP_REPEAT_FROM_TO(n, BOOST_TYPEOF_PP_NEXT_SIZE, BOOST_TYPEOF_typedef_fake_item, ~)\ 113 }; 114 115 namespace boost { namespace type_of { 116 117 # define BOOST_PP_LOCAL_MACRO BOOST_TYPEOF_define_vector 118 # define BOOST_PP_LOCAL_LIMITS \ 119 (BOOST_TYPEOF_PP_START_SIZE,BOOST_TYPEOF_LIMIT_SIZE) 120 # include BOOST_PP_LOCAL_ITERATE() 121 122 }} 123 124 # undef BOOST_TYPEOF_typedef_item 125 # undef BOOST_TYPEOF_typedef_fake_item 126 # undef BOOST_TYPEOF_define_vector 127 128 // push_back 129 130 # define BOOST_TYPEOF_spec_push_back(n)\ 131 template<BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_COMMA_IF(n) class T>\ 132 struct push_back<BOOST_PP_CAT(boost::type_of::vector, n)<BOOST_PP_ENUM_PARAMS(n, P)>, T>\ 133 {\ 134 typedef BOOST_PP_CAT(boost::type_of::vector, BOOST_PP_INC(n))<\ 135 BOOST_PP_ENUM_PARAMS(n, P) BOOST_PP_COMMA_IF(n) T\ 136 > type;\ 137 }; 138 139 namespace boost { namespace type_of { 140 141 # if BOOST_TYPEOF_LIMIT_SIZE < 50 142 template<class V, class T> struct push_back { 143 typedef V type; 144 }; 145 # endif 146 //default behaviour is to let push_back ignore T, and return the input vector. 147 //This is to let BOOST_TYPEOF_NESTED_TYPEDEF work properly with the default vector. 148 # define BOOST_PP_LOCAL_MACRO BOOST_TYPEOF_spec_push_back 149 # define BOOST_PP_LOCAL_LIMITS \ 150 (BOOST_PP_DEC(BOOST_TYPEOF_PP_START_SIZE), \ 151 BOOST_PP_DEC(BOOST_TYPEOF_LIMIT_SIZE)) 152 # include BOOST_PP_LOCAL_ITERATE() 153 154 }} 155 156 # undef BOOST_TYPEOF_spec_push_back 157 158 # endif//BOOST_TYPEOF_PP_START_SIZE<=BOOST_TYPEOF_LIMIT_SIZE 159 # undef BOOST_TYPEOF_PP_START_SIZE 160 # undef BOOST_TYPEOF_PP_NEXT_SIZE 161 162 #endif//BOOST_TYPEOF_PREPROCESSING_MODE || BOOST_PP_IS_SELFISH 163 164 #define BOOST_TYPEOF_VECTOR_HPP_INCLUDED 165 #endif//BOOST_TYPEOF_VECTOR_HPP_INCLUDED 166 167