Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 1 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 2 | #if !defined(NDNBOOST_PP_IS_ITERATING) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 3 | |
| 4 | ///// header body |
| 5 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 6 | #ifndef NDNBOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED |
| 7 | #define NDNBOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 8 | |
| 9 | // Copyright Aleksey Gurtovoy 2001-2004 |
| 10 | // |
| 11 | // Distributed under the Boost Software License, Version 1.0. |
| 12 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 13 | // http://www.boost.org/LICENSE_1_0.txt) |
| 14 | // |
| 15 | // See http://www.boost.org/libs/mpl for documentation. |
| 16 | |
| 17 | // $Id: template_arity.hpp 61584 2010-04-26 18:48:26Z agurtovoy $ |
| 18 | // $Date: 2010-04-26 11:48:26 -0700 (Mon, 26 Apr 2010) $ |
| 19 | // $Revision: 61584 $ |
| 20 | |
| 21 | #include <ndnboost/mpl/aux_/config/ttp.hpp> |
| 22 | #include <ndnboost/mpl/aux_/config/lambda.hpp> |
| 23 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 24 | #if !defined(NDNBOOST_MPL_PREPROCESSING_MODE) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 25 | # include <ndnboost/mpl/aux_/template_arity_fwd.hpp> |
| 26 | # include <ndnboost/mpl/int.hpp> |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 27 | # if !defined(NDNBOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT) |
| 28 | # if defined(NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 29 | # include <ndnboost/mpl/aux_/type_wrapper.hpp> |
| 30 | # endif |
| 31 | # else |
| 32 | # include <ndnboost/mpl/aux_/has_rebind.hpp> |
| 33 | # endif |
| 34 | #endif |
| 35 | |
| 36 | #include <ndnboost/mpl/aux_/config/static_constant.hpp> |
| 37 | #include <ndnboost/mpl/aux_/config/use_preprocessed.hpp> |
| 38 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 39 | #if !defined(NDNBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \ |
| 40 | && !defined(NDNBOOST_MPL_PREPROCESSING_MODE) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 41 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 42 | # define NDNBOOST_MPL_PREPROCESSED_HEADER template_arity.hpp |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 43 | # include <ndnboost/mpl/aux_/include_preprocessed.hpp> |
| 44 | |
| 45 | #else |
| 46 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 47 | # if !defined(NDNBOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT) |
| 48 | # if defined(NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 49 | |
| 50 | # include <ndnboost/mpl/limits/arity.hpp> |
| 51 | # include <ndnboost/mpl/aux_/preprocessor/range.hpp> |
| 52 | # include <ndnboost/mpl/aux_/preprocessor/repeat.hpp> |
| 53 | # include <ndnboost/mpl/aux_/preprocessor/params.hpp> |
| 54 | # include <ndnboost/mpl/aux_/nttp_decl.hpp> |
| 55 | |
| 56 | # include <ndnboost/preprocessor/seq/fold_left.hpp> |
| 57 | # include <ndnboost/preprocessor/comma_if.hpp> |
| 58 | # include <ndnboost/preprocessor/iterate.hpp> |
| 59 | # include <ndnboost/preprocessor/inc.hpp> |
| 60 | # include <ndnboost/preprocessor/cat.hpp> |
| 61 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 62 | # define AUX778076_ARITY NDNBOOST_PP_INC(NDNBOOST_MPL_LIMIT_METAFUNCTION_ARITY) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 63 | |
| 64 | namespace ndnboost { namespace mpl { namespace aux { |
| 65 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 66 | template< NDNBOOST_MPL_AUX_NTTP_DECL(int, N) > struct arity_tag |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 67 | { |
| 68 | typedef char (&type)[N + 1]; |
| 69 | }; |
| 70 | |
| 71 | # define AUX778076_MAX_ARITY_OP(unused, state, i_) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 72 | ( NDNBOOST_PP_CAT(C,i_) > 0 ? NDNBOOST_PP_CAT(C,i_) : state ) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 73 | /**/ |
| 74 | |
| 75 | template< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 76 | NDNBOOST_MPL_PP_PARAMS(AUX778076_ARITY, NDNBOOST_MPL_AUX_NTTP_DECL(int, C)) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 77 | > |
| 78 | struct max_arity |
| 79 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 80 | NDNBOOST_STATIC_CONSTANT(int, value = |
| 81 | NDNBOOST_PP_SEQ_FOLD_LEFT( |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 82 | AUX778076_MAX_ARITY_OP |
| 83 | , -1 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 84 | , NDNBOOST_MPL_PP_RANGE(1, AUX778076_ARITY) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 85 | ) |
| 86 | ); |
| 87 | }; |
| 88 | |
| 89 | # undef AUX778076_MAX_ARITY_OP |
| 90 | |
| 91 | arity_tag<0>::type arity_helper(...); |
| 92 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 93 | # define NDNBOOST_PP_ITERATION_LIMITS (1, AUX778076_ARITY) |
| 94 | # define NDNBOOST_PP_FILENAME_1 <ndnboost/mpl/aux_/template_arity.hpp> |
| 95 | # include NDNBOOST_PP_ITERATE() |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 96 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 97 | template< typename F, NDNBOOST_MPL_AUX_NTTP_DECL(int, N) > |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 98 | struct template_arity_impl |
| 99 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 100 | NDNBOOST_STATIC_CONSTANT(int, value = |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 101 | sizeof(::ndnboost::mpl::aux::arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1 |
| 102 | ); |
| 103 | }; |
| 104 | |
| 105 | # define AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION(unused, i_, F) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 106 | NDNBOOST_PP_COMMA_IF(i_) template_arity_impl<F,NDNBOOST_PP_INC(i_)>::value \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 107 | /**/ |
| 108 | |
| 109 | template< typename F > |
| 110 | struct template_arity |
| 111 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 112 | NDNBOOST_STATIC_CONSTANT(int, value = ( |
| 113 | max_arity< NDNBOOST_MPL_PP_REPEAT( |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 114 | AUX778076_ARITY |
| 115 | , AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION |
| 116 | , F |
| 117 | ) >::value |
| 118 | )); |
| 119 | |
| 120 | typedef mpl::int_<value> type; |
| 121 | }; |
| 122 | |
| 123 | # undef AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION |
| 124 | |
| 125 | # undef AUX778076_ARITY |
| 126 | |
| 127 | }}} |
| 128 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 129 | # endif // NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING |
| 130 | # else // NDNBOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 131 | |
| 132 | # include <ndnboost/mpl/aux_/config/eti.hpp> |
| 133 | |
| 134 | namespace ndnboost { namespace mpl { namespace aux { |
| 135 | |
| 136 | template< bool > |
| 137 | struct template_arity_impl |
| 138 | { |
| 139 | template< typename F > struct result_ |
| 140 | : mpl::int_<-1> |
| 141 | { |
| 142 | }; |
| 143 | }; |
| 144 | |
| 145 | template<> |
| 146 | struct template_arity_impl<true> |
| 147 | { |
| 148 | template< typename F > struct result_ |
| 149 | : F::arity |
| 150 | { |
| 151 | }; |
| 152 | }; |
| 153 | |
| 154 | template< typename F > |
| 155 | struct template_arity |
| 156 | : template_arity_impl< ::ndnboost::mpl::aux::has_rebind<F>::value > |
| 157 | ::template result_<F> |
| 158 | { |
| 159 | }; |
| 160 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 161 | #if defined(NDNBOOST_MPL_CFG_MSVC_ETI_BUG) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 162 | template<> |
| 163 | struct template_arity<int> |
| 164 | : mpl::int_<-1> |
| 165 | { |
| 166 | }; |
| 167 | #endif |
| 168 | |
| 169 | }}} |
| 170 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 171 | # endif // NDNBOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 172 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 173 | #endif // NDNBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS |
| 174 | #endif // NDNBOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 175 | |
| 176 | ///// iteration |
| 177 | |
| 178 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 179 | #define i_ NDNBOOST_PP_FRAME_ITERATION(1) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 180 | |
| 181 | template< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 182 | template< NDNBOOST_MPL_PP_PARAMS(i_, typename P) > class F |
| 183 | , NDNBOOST_MPL_PP_PARAMS(i_, typename T) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 184 | > |
| 185 | typename arity_tag<i_>::type |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 186 | arity_helper(type_wrapper< F<NDNBOOST_MPL_PP_PARAMS(i_, T)> >, arity_tag<i_>); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 187 | |
| 188 | #undef i_ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 189 | #endif // NDNBOOST_PP_IS_ITERATING |