~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/mpl/aux_/template_arity.hpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
// boost mpl/aux_/template_arity.hpp header file
 
3
// See http://www.boost.org for updates, documentation, and revision history.
 
4
//-----------------------------------------------------------------------------
 
5
//
 
6
// Copyright (c) 2001-02
 
7
// Aleksey Gurtovoy
 
8
//
 
9
// Permission to use, copy, modify, distribute and sell this software
 
10
// and its documentation for any purpose is hereby granted without fee, 
 
11
// provided that the above copyright notice appears in all copies and 
 
12
// that both the copyright notice and this permission notice appear in 
 
13
// supporting documentation. No representations are made about the 
 
14
// suitability of this software for any purpose. It is provided "as is" 
 
15
// without express or implied warranty.
 
16
 
 
17
#if !defined(BOOST_PP_IS_ITERATING)
 
18
 
 
19
///// header body
 
20
 
 
21
#ifndef BOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
 
22
#define BOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
 
23
 
 
24
#include "boost/mpl/aux_/config/ttp.hpp"
 
25
#include "boost/mpl/aux_/config/lambda.hpp"
 
26
 
 
27
#if !defined(BOOST_MPL_PREPROCESSING_MODE)
 
28
#   include "boost/mpl/aux_/template_arity_fwd.hpp"
 
29
#   if !defined(BOOST_MPL_NO_FULL_LAMBDA_SUPPORT)
 
30
#   if defined(BOOST_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
 
31
#       include "boost/mpl/aux_/type_wrapper.hpp"
 
32
#   endif
 
33
#   else
 
34
#       include "boost/mpl/aux_/has_rebind.hpp"
 
35
#   endif
 
36
#endif
 
37
 
 
38
#include "boost/mpl/aux_/config/use_preprocessed.hpp"
 
39
 
 
40
#if !defined(BOOST_MPL_NO_PREPROCESSED_HEADERS) \
 
41
 && !defined(BOOST_MPL_PREPROCESSING_MODE)
 
42
 
 
43
#   define BOOST_MPL_PREPROCESSED_HEADER template_arity.hpp
 
44
#   include "boost/mpl/aux_/include_preprocessed.hpp"
 
45
 
 
46
#else
 
47
 
 
48
#   if !defined(BOOST_MPL_NO_FULL_LAMBDA_SUPPORT)
 
49
#   if defined(BOOST_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
 
50
 
 
51
#   include "boost/mpl/limits/arity.hpp"
 
52
#   include "boost/mpl/aux_/config/nttp.hpp"
 
53
#   include "boost/mpl/aux_/preprocessor/range.hpp"
 
54
#   include "boost/mpl/aux_/preprocessor/repeat.hpp"
 
55
#   include "boost/mpl/aux_/preprocessor/params.hpp"
 
56
 
 
57
#   include "boost/preprocessor/seq/fold_left.hpp"
 
58
#   include "boost/preprocessor/comma_if.hpp"
 
59
#   include "boost/preprocessor/iterate.hpp"
 
60
#   include "boost/preprocessor/inc.hpp"
 
61
#   include "boost/preprocessor/cat.hpp"
 
62
 
 
63
namespace boost { namespace mpl { namespace aux {
 
64
 
 
65
template< BOOST_MPL_AUX_NTTP_DECL(int, N) > struct arity_tag
 
66
{
 
67
    typedef char (&type)[N + 1];
 
68
};
 
69
 
 
70
#define AUX_MAX_ARITY_OP(unused, state, i) \
 
71
    ( BOOST_PP_CAT(C,i) > 0 ? BOOST_PP_CAT(C,i) : state ) \
 
72
/**/
 
73
 
 
74
template<
 
75
      BOOST_MPL_PP_PARAMS(
 
76
          BOOST_MPL_METAFUNCTION_MAX_ARITY
 
77
        , BOOST_MPL_AUX_NTTP_DECL(int, C)
 
78
        )
 
79
    >
 
80
struct max_arity
 
81
{
 
82
    BOOST_STATIC_CONSTANT(int, value = 
 
83
          BOOST_PP_SEQ_FOLD_LEFT(
 
84
              AUX_MAX_ARITY_OP
 
85
            , -1
 
86
            , BOOST_MPL_PP_RANGE(1, BOOST_MPL_METAFUNCTION_MAX_ARITY)
 
87
            )
 
88
        );
 
89
};
 
90
 
 
91
#undef AUX_MAX_ARITY_OP
 
92
 
 
93
arity_tag<0> arity_helper(...);
 
94
 
 
95
#define BOOST_PP_ITERATION_LIMITS (1, BOOST_MPL_METAFUNCTION_MAX_ARITY)
 
96
#define BOOST_PP_FILENAME_1 "boost/mpl/aux_/template_arity.hpp"
 
97
#include BOOST_PP_ITERATE()
 
98
 
 
99
template< typename F, BOOST_MPL_AUX_NTTP_DECL(int, N) >
 
100
struct template_arity_impl
 
101
{
 
102
    BOOST_STATIC_CONSTANT(int, value = 
 
103
          sizeof(arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1
 
104
        );
 
105
};
 
106
 
 
107
#define AUX_TEMPLATE_ARITY_IMPL_INVOCATION(unused, i, F) \
 
108
    BOOST_PP_COMMA_IF(i) template_arity_impl<F,BOOST_PP_INC(i)>::value \
 
109
/**/
 
110
 
 
111
template< typename F >
 
112
struct template_arity
 
113
{
 
114
    BOOST_STATIC_CONSTANT(int, value = (
 
115
          max_arity< BOOST_MPL_PP_REPEAT(
 
116
              BOOST_MPL_METAFUNCTION_MAX_ARITY
 
117
            , AUX_TEMPLATE_ARITY_IMPL_INVOCATION
 
118
            , F
 
119
            ) >::value
 
120
        ));
 
121
};
 
122
 
 
123
#undef AUX_TEMPLATE_ARITY_IMPL_INVOCATION
 
124
 
 
125
}}} // namespace boost::mpl::aux
 
126
 
 
127
#   endif // BOOST_EXTENDED_TEMPLATE_PARAMETERS_MATCHING
 
128
#   else // BOOST_MPL_NO_FULL_LAMBDA_SUPPORT
 
129
 
 
130
#   include "boost/mpl/aux_/config/eti.hpp"
 
131
#   include "boost/mpl/aux_/config/static_constant.hpp"
 
132
#   include "boost/mpl/aux_/config/workaround.hpp"
 
133
 
 
134
namespace boost { namespace mpl { namespace aux {
 
135
 
 
136
template< bool >
 
137
struct template_arity_impl
 
138
{
 
139
    template< typename F > struct result_
 
140
    {
 
141
        BOOST_STATIC_CONSTANT(int, value = -1);
 
142
    };
 
143
};
 
144
 
 
145
template<>
 
146
struct template_arity_impl<true>
 
147
{
 
148
    template< typename F > struct result_
 
149
    {
 
150
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x561 && !defined(BOOST_STRICT_CONFIG))
 
151
        enum { value = F::arity };
 
152
#else
 
153
        BOOST_STATIC_CONSTANT(int, value = F::arity);
 
154
#endif
 
155
    };
 
156
};
 
157
 
 
158
template< typename F >
 
159
struct template_arity
 
160
    : template_arity_impl< ::boost::mpl::aux::has_rebind<F>::value >
 
161
        ::template result_<F>
 
162
{
 
163
};
 
164
 
 
165
#if defined(BOOST_MPL_MSVC_ETI_BUG)
 
166
template<>
 
167
struct template_arity<int>
 
168
{
 
169
    BOOST_STATIC_CONSTANT(int, value = -1);
 
170
};
 
171
#endif
 
172
 
 
173
}}} // namespace boost::mpl::aux
 
174
 
 
175
#   endif // BOOST_MPL_NO_FULL_LAMBDA_SUPPORT
 
176
 
 
177
#endif // BOOST_MPL_USE_PREPROCESSED_HEADERS
 
178
#endif // BOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
 
179
 
 
180
///// iteration
 
181
 
 
182
#else
 
183
#define i BOOST_PP_FRAME_ITERATION(1)
 
184
 
 
185
template<
 
186
      template< BOOST_MPL_PP_PARAMS(i, typename P) > class F
 
187
    , BOOST_MPL_PP_PARAMS(i, typename T)
 
188
    >
 
189
typename arity_tag<i>::type
 
190
arity_helper(type_wrapper< F<BOOST_MPL_PP_PARAMS(i, T)> >, arity_tag<i>);
 
191
 
 
192
#undef i
 
193
#endif // BOOST_PP_IS_ITERATING