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

« back to all changes in this revision

Viewing changes to boost/boost/mpl/apply.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/apply.hpp header file
 
3
// See http://www.boost.org for updates, documentation, and revision history.
 
4
//-----------------------------------------------------------------------------
 
5
//
 
6
// Copyright (c) 2000-03
 
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_APPLY_HPP_INCLUDED
 
22
#define BOOST_MPL_APPLY_HPP_INCLUDED
 
23
 
 
24
#if !defined(BOOST_MPL_PREPROCESSING_MODE)
 
25
#   include "boost/mpl/arg_fwd.hpp"
 
26
#   include "boost/mpl/void.hpp"
 
27
#   include "boost/mpl/aux_/arity.hpp"
 
28
#   include "boost/mpl/aux_/msvc_never_true.hpp"
 
29
#   include "boost/type_traits/same_traits.hpp"
 
30
#endif
 
31
 
 
32
#include "boost/mpl/aux_/config/use_preprocessed.hpp"
 
33
 
 
34
#if !defined(BOOST_MPL_NO_PREPROCESSED_HEADERS) \
 
35
 && !defined(BOOST_MPL_PREPROCESSING_MODE)
 
36
 
 
37
#   define BOOST_MPL_PREPROCESSED_HEADER apply.hpp
 
38
#   include "boost/mpl/aux_/include_preprocessed.hpp"
 
39
 
 
40
#else
 
41
 
 
42
#   include "boost/mpl/limits/arity.hpp"
 
43
#   include "boost/mpl/aux_/lambda_support.hpp"
 
44
#   include "boost/mpl/aux_/preprocessor/params.hpp"
 
45
#   include "boost/mpl/aux_/preprocessor/default_params.hpp"
 
46
#   include "boost/mpl/aux_/preprocessor/partial_spec_params.hpp"
 
47
#   include "boost/mpl/aux_/preprocessor/enum.hpp"
 
48
#   include "boost/mpl/aux_/preprocessor/add.hpp"
 
49
#   include "boost/mpl/aux_/config/dtp.hpp"
 
50
#   include "boost/mpl/aux_/config/nttp.hpp"
 
51
#   include "boost/mpl/aux_/config/eti.hpp"
 
52
#   include "boost/mpl/aux_/config/lambda.hpp"
 
53
 
 
54
#   include "boost/preprocessor/comma_if.hpp"
 
55
#   include "boost/preprocessor/inc.hpp"
 
56
#   include "boost/preprocessor/iterate.hpp"
 
57
 
 
58
#   include "boost/config.hpp"
 
59
 
 
60
// agurt, 15/jan/02: top-level 'apply' template gives an ICE on MSVC
 
61
// (for known reasons)
 
62
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
 
63
#   define BOOST_MPL_NO_APPLY_TEMPLATE
 
64
#endif
 
65
 
 
66
namespace boost {
 
67
namespace mpl {
 
68
 
 
69
// local macros, #undef-ined at the end of the header
 
70
#   define AUX_APPLY_PARAMS(param) \
 
71
    BOOST_MPL_PP_PARAMS( \
 
72
          BOOST_MPL_METAFUNCTION_MAX_ARITY \
 
73
        , param \
 
74
        ) \
 
75
    /**/
 
76
 
 
77
#   define AUX_APPLY_DEFAULT_PARAMS(param, value) \
 
78
    BOOST_MPL_PP_DEFAULT_PARAMS( \
 
79
          BOOST_MPL_METAFUNCTION_MAX_ARITY \
 
80
        , param \
 
81
        , value \
 
82
        ) \
 
83
    /**/
 
84
 
 
85
#   define AUX_APPLY_N_PARAMS(n, param) \
 
86
    BOOST_MPL_PP_PARAMS(n, param) \
 
87
    /**/
 
88
 
 
89
#   define AUX_APPLY_N_COMMA_PARAMS(n, param) \
 
90
    BOOST_PP_COMMA_IF(n) \
 
91
    BOOST_MPL_PP_PARAMS(n, param) \
 
92
    /**/
 
93
 
 
94
#   define AUX_APPLY_N_PARTIAL_SPEC_PARAMS(n, param, def) \
 
95
    BOOST_PP_COMMA_IF(n) \
 
96
    BOOST_MPL_PP_PARTIAL_SPEC_PARAMS(n, param, def) \
 
97
    /**/
 
98
    
 
99
#   define AUX_APPLY_N_SPEC_PARAMS(n, param) \
 
100
    BOOST_MPL_PP_ENUM(BOOST_PP_INC(n), param) \
 
101
    /**/
 
102
 
 
103
#   if !defined(BOOST_MPL_NO_APPLY_TEMPLATE)
 
104
 
 
105
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 
106
// forward declaration
 
107
template<
 
108
      typename F, AUX_APPLY_DEFAULT_PARAMS(typename T, void_)
 
109
    >
 
110
struct apply;
 
111
#else
 
112
namespace aux {
 
113
template< BOOST_MPL_AUX_NTTP_DECL(int, arity_) > struct apply_impl_chooser;
 
114
}
 
115
#endif
 
116
 
 
117
#   endif // BOOST_MPL_NO_APPLY_TEMPLATE
 
118
 
 
119
#define BOOST_PP_ITERATION_PARAMS_1 \
 
120
    (3,(0, BOOST_MPL_METAFUNCTION_MAX_ARITY, "boost/mpl/apply.hpp"))
 
121
#include BOOST_PP_ITERATE()
 
122
 
 
123
#   if !defined(BOOST_MPL_NO_APPLY_TEMPLATE)
 
124
// real C++ version is already taken care of
 
125
#   if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 
126
 
 
127
namespace aux {
 
128
// apply_count_args
 
129
#define BOOST_MPL_AUX_COUNT_ARGS_PREFIX apply
 
130
#define BOOST_MPL_AUX_COUNT_ARGS_DEFAULT void_
 
131
#define BOOST_MPL_AUX_COUNT_ARGS_ARITY BOOST_MPL_METAFUNCTION_MAX_ARITY
 
132
#include "boost/mpl/aux_/count_args.hpp"
 
133
} // namespace aux
 
134
 
 
135
template<
 
136
      typename F, AUX_APPLY_DEFAULT_PARAMS(typename T, void_)
 
137
    >
 
138
struct apply
 
139
    : aux::apply_impl_chooser< 
 
140
          aux::apply_count_args< AUX_APPLY_PARAMS(T) >::value
 
141
        >::template result_< F, AUX_APPLY_PARAMS(T) >::type
 
142
{
 
143
};
 
144
 
 
145
#   endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 
146
#   endif // BOOST_MPL_NO_APPLY_TEMPLATE
 
147
 
 
148
#   undef AUX_APPLY_N_SPEC_PARAMS
 
149
#   undef AUX_APPLY_N_PARTIAL_SPEC_PARAMS
 
150
#   undef AUX_APPLY_N_COMMA_PARAMS
 
151
#   undef AUX_APPLY_N_PARAMS
 
152
#   undef AUX_APPLY_DEFAULT_PARAMS
 
153
#   undef AUX_APPLY_PARAMS
 
154
 
 
155
} // namespace mpl
 
156
} // namespace boost
 
157
 
 
158
#endif // BOOST_MPL_USE_PREPROCESSED_HEADERS
 
159
#endif // BOOST_MPL_APPLY_HPP_INCLUDED
 
160
 
 
161
///// iteration, depth == 1
 
162
 
 
163
#elif BOOST_PP_ITERATION_DEPTH() == 1
 
164
 
 
165
#   define i BOOST_PP_FRAME_ITERATION(1)
 
166
#   if i == 0
 
167
 
 
168
template< typename F >
 
169
struct apply0 : F
 
170
{
 
171
    BOOST_MPL_AUX_LAMBDA_SUPPORT(1, apply0, (F))
 
172
};
 
173
 
 
174
#if defined(BOOST_MPL_MSVC_ETI_BUG)
 
175
//: workaround for the ETI bug
 
176
template<>
 
177
struct apply0<int>
 
178
{
 
179
    typedef int type;
 
180
};
 
181
#endif
 
182
 
 
183
#   else // i > 0
 
184
 
 
185
#   if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
 
186
// MSVC version
 
187
 
 
188
namespace aux {
 
189
// msvc_apply##i
 
190
#define BOOST_MPL_AUX_MSVC_DTW_NAME BOOST_PP_CAT(msvc_apply,i)
 
191
#define BOOST_MPL_AUX_MSVC_DTW_ORIGINAL_NAME apply
 
192
#define BOOST_MPL_AUX_MSVC_DTW_ARITY i
 
193
#include "boost/mpl/aux_/msvc_dtw.hpp"
 
194
} // namespace aux
 
195
 
 
196
template<
 
197
      typename F, AUX_APPLY_N_PARAMS(i, typename T)
 
198
    >
 
199
struct BOOST_PP_CAT(apply,i)
 
200
    : BOOST_PP_CAT(aux::msvc_apply,i)<F>::template result_<
 
201
          AUX_APPLY_N_PARAMS(i, T)
 
202
        >
 
203
{
 
204
    BOOST_MPL_AUX_LAMBDA_SUPPORT(
 
205
          BOOST_PP_INC(i)
 
206
        , BOOST_PP_CAT(apply,i)
 
207
        , (F, AUX_APPLY_N_PARAMS(i,T))
 
208
        )
 
209
};
 
210
 
 
211
#   elif defined(BOOST_BROKEN_DEFAULT_TEMPLATE_PARAMETERS_IN_NESTED_TEMPLATES)
 
212
// MWCW/Borland version
 
213
 
 
214
namespace aux {
 
215
template<
 
216
      int N, typename F, AUX_APPLY_N_PARAMS(i, typename T)
 
217
    >
 
218
struct BOOST_PP_CAT(apply_impl,i);
 
219
}
 
220
 
 
221
#define BOOST_PP_ITERATION_PARAMS_2 \
 
222
    (3,(0, BOOST_MPL_METAFUNCTION_MAX_ARITY - i, "boost/mpl/apply.hpp"))
 
223
#include BOOST_PP_ITERATE()
 
224
 
 
225
template<
 
226
      typename F, AUX_APPLY_N_PARAMS(i, typename T)
 
227
    >
 
228
struct BOOST_PP_CAT(apply,i)
 
229
    : BOOST_PP_CAT(aux::apply_impl,i)<
 
230
          ::boost::mpl::aux::arity<F,i>::value
 
231
        , F
 
232
        , AUX_APPLY_N_PARAMS(i, T)
 
233
        >::type
 
234
{
 
235
    BOOST_MPL_AUX_LAMBDA_SUPPORT(
 
236
          BOOST_PP_INC(i)
 
237
        , BOOST_PP_CAT(apply,i)
 
238
        , (F, AUX_APPLY_N_PARAMS(i,T))
 
239
        )
 
240
};
 
241
 
 
242
#   else
 
243
// ISO98 C++
 
244
 
 
245
template<
 
246
      typename F, AUX_APPLY_N_PARAMS(i, typename T)
 
247
    >
 
248
struct BOOST_PP_CAT(apply,i)
 
249
    : F::template apply<
 
250
          AUX_APPLY_N_PARAMS(i, T)
 
251
        >
 
252
{
 
253
    BOOST_MPL_AUX_LAMBDA_SUPPORT(
 
254
          BOOST_PP_INC(i)
 
255
        , BOOST_PP_CAT(apply,i)
 
256
        , (F, AUX_APPLY_N_PARAMS(i,T))
 
257
        )
 
258
};
 
259
 
 
260
#   endif // workarounds
 
261
 
 
262
#if defined(BOOST_MPL_MSVC_ETI_BUG)
 
263
//: workaround for ETI bug
 
264
template<>
 
265
struct BOOST_PP_CAT(apply,i)<AUX_APPLY_N_SPEC_PARAMS(i, int)>
 
266
{
 
267
    typedef int type;
 
268
};
 
269
#endif
 
270
 
 
271
#   endif // i > 0
 
272
 
 
273
#   if !defined(BOOST_MPL_NO_APPLY_TEMPLATE)
 
274
#   if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 
275
 
 
276
#if i == BOOST_MPL_METAFUNCTION_MAX_ARITY
 
277
 
 
278
//: primary template (not a specialization!)
 
279
template<
 
280
      typename F AUX_APPLY_N_COMMA_PARAMS(i, typename T)
 
281
    >
 
282
struct apply
 
283
    : BOOST_PP_CAT(apply,i)< F AUX_APPLY_N_COMMA_PARAMS(i, T) >
 
284
{
 
285
};
 
286
 
 
287
#else
 
288
 
 
289
template<
 
290
      typename F AUX_APPLY_N_COMMA_PARAMS(i, typename T)
 
291
    >
 
292
struct apply< F AUX_APPLY_N_PARTIAL_SPEC_PARAMS(i, T, void_) >
 
293
    : BOOST_PP_CAT(apply,i)< F AUX_APPLY_N_COMMA_PARAMS(i, T) >
 
294
{
 
295
};
 
296
 
 
297
#endif // i == BOOST_MPL_METAFUNCTION_MAX_ARITY
 
298
 
 
299
#   else
 
300
 
 
301
namespace aux {
 
302
 
 
303
template<>
 
304
struct apply_impl_chooser<i>
 
305
{
 
306
    template<
 
307
          typename F, AUX_APPLY_PARAMS(typename T)
 
308
        >
 
309
    struct result_
 
310
    {
 
311
        typedef BOOST_PP_CAT(apply,i)<
 
312
              F AUX_APPLY_N_COMMA_PARAMS(i, T)
 
313
            > type;
 
314
    };
 
315
};
 
316
 
 
317
} // namespace aux
 
318
 
 
319
#   endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 
320
#   endif // BOOST_MPL_NO_APPLY_TEMPLATE
 
321
 
 
322
#   undef i
 
323
 
 
324
///// iteration, depth == 2
 
325
 
 
326
#elif BOOST_PP_ITERATION_DEPTH() == 2
 
327
 
 
328
#   define j BOOST_PP_FRAME_ITERATION(2)
 
329
 
 
330
namespace aux {
 
331
 
 
332
template<
 
333
      typename F, AUX_APPLY_N_PARAMS(i, typename T)
 
334
    >
 
335
struct BOOST_PP_CAT(apply_impl,i)<
 
336
          BOOST_MPL_PP_ADD(i, j)
 
337
        , F
 
338
        , AUX_APPLY_N_PARAMS(i, T)
 
339
        >
 
340
{
 
341
    typedef typename F::template apply<
 
342
          AUX_APPLY_N_PARAMS(i, T)
 
343
        BOOST_PP_COMMA_IF(j) BOOST_MPL_PP_ENUM(j, void_)
 
344
        > type;
 
345
};
 
346
 
 
347
} // namespace aux
 
348
 
 
349
#   undef j
 
350
 
 
351
#endif // BOOST_PP_IS_ITERATING