1 // Copyright (C) 2005 Arkadiy Vertleyb
2 // Copyright (C) 2005 Peder Holt
4 // Copyright (C) 2006 Tobias Schwinger
6 // Use, modification and distribution is subject to the Boost Software
7 // License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_TYPEOF_VECTOR_HPP_INCLUDED
11 #include <boost/mpl/int.hpp>
12 #include <boost/preprocessor/iteration/self.hpp>
14 #ifndef BOOST_TYPEOF_LIMIT_SIZE
15 # define BOOST_TYPEOF_LIMIT_SIZE 50
19 // To recreate the preprocessed versions of this file preprocess and run
21 // $(BOOST_ROOT)/libs/typeof/tools/preprocess.pl
24 #if defined(BOOST_TYPEOF_PP_INCLUDE_EXTERNAL)
26 # undef BOOST_TYPEOF_PP_INCLUDE_EXTERNAL
28 #elif !defined(BOOST_TYPEOF_PREPROCESSING_MODE) && !BOOST_PP_IS_SELFISH
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()
50 # error "BOOST_TYPEOF_LIMIT_SIZE too high"
53 #else// defined(BOOST_TYPEOF_PREPROCESSING_MODE) || BOOST_PP_IS_SELFISH
55 # ifndef BOOST_TYPEOF_PP_NEXT_SIZE
56 # define BOOST_TYPEOF_PP_NEXT_SIZE BOOST_TYPEOF_LIMIT_SIZE
58 # ifndef BOOST_TYPEOF_PP_START_SIZE
59 # define BOOST_TYPEOF_PP_START_SIZE 0
62 # if BOOST_TYPEOF_PP_START_SIZE <= BOOST_TYPEOF_LIMIT_SIZE
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>
77 # define BOOST_TYPEOF_spec_iter(n)\
79 struct v_iter<V, mpl::int_<n> >\
81 typedef typename V::item ## n type;\
82 typedef v_iter<V, mpl::int_<n + 1> > next;\
85 namespace boost { namespace type_of {
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()
96 # undef BOOST_TYPEOF_spec_iter
100 # define BOOST_TYPEOF_typedef_item(z, n, _)\
101 typedef P ## n item ## n;
103 # define BOOST_TYPEOF_typedef_fake_item(z, n, _)\
104 typedef mpl::int_<1> item ## n;
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)>\
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, ~)\
115 namespace boost { namespace type_of {
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()
124 # undef BOOST_TYPEOF_typedef_item
125 # undef BOOST_TYPEOF_typedef_fake_item
126 # undef BOOST_TYPEOF_define_vector
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>\
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\
139 namespace boost { namespace type_of {
141 # if BOOST_TYPEOF_LIMIT_SIZE < 50
142 template<class V, class T> struct push_back {
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()
156 # undef BOOST_TYPEOF_spec_push_back
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
162 #endif//BOOST_TYPEOF_PREPROCESSING_MODE || BOOST_PP_IS_SELFISH
164 #define BOOST_TYPEOF_VECTOR_HPP_INCLUDED
165 #endif//BOOST_TYPEOF_VECTOR_HPP_INCLUDED