blob: f5730805869b8257b67e26700791b32ee7a4ca65 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
Jeff Thompson3d613fd2013-10-15 15:39:04 -07002#if !defined(NDNBOOST_PP_IS_ITERATING)
Jeff Thompsona28eed82013-08-22 16:21:10 -07003
4///// header body
5
Jeff Thompson3d613fd2013-10-15 15:39:04 -07006#ifndef NDNBOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
7#define NDNBOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -07008
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 Thompson3d613fd2013-10-15 15:39:04 -070024#if !defined(NDNBOOST_MPL_PREPROCESSING_MODE)
Jeff Thompsona28eed82013-08-22 16:21:10 -070025# include <ndnboost/mpl/aux_/template_arity_fwd.hpp>
26# include <ndnboost/mpl/int.hpp>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070027# if !defined(NDNBOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT)
28# if defined(NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
Jeff Thompsona28eed82013-08-22 16:21:10 -070029# 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 Thompson3d613fd2013-10-15 15:39:04 -070039#if !defined(NDNBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
40 && !defined(NDNBOOST_MPL_PREPROCESSING_MODE)
Jeff Thompsona28eed82013-08-22 16:21:10 -070041
Jeff Thompson3d613fd2013-10-15 15:39:04 -070042# define NDNBOOST_MPL_PREPROCESSED_HEADER template_arity.hpp
Jeff Thompsona28eed82013-08-22 16:21:10 -070043# include <ndnboost/mpl/aux_/include_preprocessed.hpp>
44
45#else
46
Jeff Thompson3d613fd2013-10-15 15:39:04 -070047# if !defined(NDNBOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT)
48# if defined(NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
Jeff Thompsona28eed82013-08-22 16:21:10 -070049
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 Thompson3d613fd2013-10-15 15:39:04 -070062# define AUX778076_ARITY NDNBOOST_PP_INC(NDNBOOST_MPL_LIMIT_METAFUNCTION_ARITY)
Jeff Thompsona28eed82013-08-22 16:21:10 -070063
64namespace ndnboost { namespace mpl { namespace aux {
65
Jeff Thompson3d613fd2013-10-15 15:39:04 -070066template< NDNBOOST_MPL_AUX_NTTP_DECL(int, N) > struct arity_tag
Jeff Thompsona28eed82013-08-22 16:21:10 -070067{
68 typedef char (&type)[N + 1];
69};
70
71# define AUX778076_MAX_ARITY_OP(unused, state, i_) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070072 ( NDNBOOST_PP_CAT(C,i_) > 0 ? NDNBOOST_PP_CAT(C,i_) : state ) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070073/**/
74
75template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070076 NDNBOOST_MPL_PP_PARAMS(AUX778076_ARITY, NDNBOOST_MPL_AUX_NTTP_DECL(int, C))
Jeff Thompsona28eed82013-08-22 16:21:10 -070077 >
78struct max_arity
79{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080 NDNBOOST_STATIC_CONSTANT(int, value =
81 NDNBOOST_PP_SEQ_FOLD_LEFT(
Jeff Thompsona28eed82013-08-22 16:21:10 -070082 AUX778076_MAX_ARITY_OP
83 , -1
Jeff Thompson3d613fd2013-10-15 15:39:04 -070084 , NDNBOOST_MPL_PP_RANGE(1, AUX778076_ARITY)
Jeff Thompsona28eed82013-08-22 16:21:10 -070085 )
86 );
87};
88
89# undef AUX778076_MAX_ARITY_OP
90
91arity_tag<0>::type arity_helper(...);
92
Jeff Thompson3d613fd2013-10-15 15:39:04 -070093# 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 Thompsona28eed82013-08-22 16:21:10 -070096
Jeff Thompson3d613fd2013-10-15 15:39:04 -070097template< typename F, NDNBOOST_MPL_AUX_NTTP_DECL(int, N) >
Jeff Thompsona28eed82013-08-22 16:21:10 -070098struct template_arity_impl
99{
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700100 NDNBOOST_STATIC_CONSTANT(int, value =
Jeff Thompsona28eed82013-08-22 16:21:10 -0700101 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 Thompson3d613fd2013-10-15 15:39:04 -0700106 NDNBOOST_PP_COMMA_IF(i_) template_arity_impl<F,NDNBOOST_PP_INC(i_)>::value \
Jeff Thompsona28eed82013-08-22 16:21:10 -0700107/**/
108
109template< typename F >
110struct template_arity
111{
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700112 NDNBOOST_STATIC_CONSTANT(int, value = (
113 max_arity< NDNBOOST_MPL_PP_REPEAT(
Jeff Thompsona28eed82013-08-22 16:21:10 -0700114 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 Thompson3d613fd2013-10-15 15:39:04 -0700129# endif // NDNBOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING
130# else // NDNBOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT
Jeff Thompsona28eed82013-08-22 16:21:10 -0700131
132# include <ndnboost/mpl/aux_/config/eti.hpp>
133
134namespace ndnboost { namespace mpl { namespace aux {
135
136template< bool >
137struct template_arity_impl
138{
139 template< typename F > struct result_
140 : mpl::int_<-1>
141 {
142 };
143};
144
145template<>
146struct template_arity_impl<true>
147{
148 template< typename F > struct result_
149 : F::arity
150 {
151 };
152};
153
154template< typename F >
155struct template_arity
156 : template_arity_impl< ::ndnboost::mpl::aux::has_rebind<F>::value >
157 ::template result_<F>
158{
159};
160
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700161#if defined(NDNBOOST_MPL_CFG_MSVC_ETI_BUG)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700162template<>
163struct template_arity<int>
164 : mpl::int_<-1>
165{
166};
167#endif
168
169}}}
170
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700171# endif // NDNBOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT
Jeff Thompsona28eed82013-08-22 16:21:10 -0700172
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700173#endif // NDNBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
174#endif // NDNBOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -0700175
176///// iteration
177
178#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700179#define i_ NDNBOOST_PP_FRAME_ITERATION(1)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700180
181template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700182 template< NDNBOOST_MPL_PP_PARAMS(i_, typename P) > class F
183 , NDNBOOST_MPL_PP_PARAMS(i_, typename T)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700184 >
185typename arity_tag<i_>::type
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700186arity_helper(type_wrapper< F<NDNBOOST_MPL_PP_PARAMS(i_, T)> >, arity_tag<i_>);
Jeff Thompsona28eed82013-08-22 16:21:10 -0700187
188#undef i_
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700189#endif // NDNBOOST_PP_IS_ITERATING