File indexing completed on 2025-12-16 09:45:46
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef DOXYGEN
0009
0010 #if !BOOST_PP_IS_ITERATING
0011 # ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
0012 # define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
0013
0014 # include <boost/functional/overloaded_function/detail/base.hpp>
0015 # include <boost/functional/overloaded_function/detail/function_type.hpp>
0016 # include <boost/functional/overloaded_function/config.hpp>
0017 # include <boost/typeof/typeof.hpp>
0018 # include <boost/preprocessor/iteration/iterate.hpp>
0019 # include <boost/preprocessor/repetition/enum.hpp>
0020 # include <boost/preprocessor/repetition/repeat.hpp>
0021 # include <boost/preprocessor/control/expr_iif.hpp>
0022 # include <boost/preprocessor/control/expr_if.hpp>
0023 # include <boost/preprocessor/comparison/greater.hpp>
0024 # include <boost/preprocessor/comparison/less.hpp>
0025 # include <boost/preprocessor/cat.hpp>
0026 # include <boost/preprocessor/arithmetic/add.hpp>
0027 # include <boost/preprocessor/arithmetic/sub.hpp>
0028 # include <boost/preprocessor/tuple/eat.hpp>
0029 # include <boost/preprocessor/logical/and.hpp>
0030 # include <boost/preprocessor/logical/not.hpp>
0031 # include <boost/preprocessor/facilities/expand.hpp>
0032
0033 #define BOOST_FUNCTIONAL_f_type(z, n, unused) \
0034 BOOST_PP_CAT(F, n)
0035
0036 #define BOOST_FUNCTIONAL_f_arg(z, n, unused) \
0037 BOOST_PP_CAT(f, n)
0038
0039 #define BOOST_FUNCTIONAL_f_tparam(z, n, unused) \
0040 typename BOOST_FUNCTIONAL_f_type(z, n, ~) \
0041
0042 #define BOOST_FUNCTIONAL_f_tparam_dflt(z, n, is_tspec) \
0043 BOOST_FUNCTIONAL_f_tparam(z, n, ~) \
0044 \
0045 BOOST_PP_EXPR_IIF(BOOST_PP_AND(BOOST_PP_NOT(is_tspec), \
0046 BOOST_PP_GREATER(n, 1)), \
0047 = void \
0048 )
0049
0050 #define BOOST_FUNCTIONAL_f_arg_decl(z, n, unused) \
0051 BOOST_FUNCTIONAL_f_type(z, n, ~) \
0052 BOOST_FUNCTIONAL_f_arg(z, n, ~)
0053
0054 #define BOOST_FUNCTIONAL_g_type(z, n, unused) \
0055 BOOST_PP_CAT(G, n)
0056
0057 #define BOOST_FUNCTIONAL_g_arg(z, n, unused) \
0058 BOOST_PP_CAT(g, n)
0059
0060 #define BOOST_FUNCTIONAL_g_tparam(z, n, unused) \
0061 typename BOOST_FUNCTIONAL_g_type(z, n, ~)
0062
0063 #define BOOST_FUNCTIONAL_g_arg_decl(z, n, unused) \
0064 BOOST_FUNCTIONAL_g_type(z, n, ~) \
0065 BOOST_FUNCTIONAL_g_arg(z, n, ~)
0066
0067 #define BOOST_FUNCTIONAL_base(z, n, unused) \
0068 ::boost::overloaded_function_detail::base< \
0069 BOOST_FUNCTIONAL_f_type(z, n, ~) \
0070 >
0071
0072 #define BOOST_FUNCTIONAL_inherit(z, n, unused) \
0073 public BOOST_FUNCTIONAL_base(z, n, ~)
0074
0075 #define BOOST_FUNCTIONAL_base_init(z, n, unused) \
0076 BOOST_FUNCTIONAL_base(z, n, ~)(BOOST_FUNCTIONAL_g_arg(z, n, ~))
0077
0078 #define BOOST_FUNCTIONAL_using_operator_call(z, n, unused) \
0079 using BOOST_FUNCTIONAL_base(z, n, ~)::operator();
0080
0081 #define BOOST_FUNCTIONAL_function_type(z, n, unused) \
0082 typename ::boost::overloaded_function_detail::function_type< \
0083 BOOST_FUNCTIONAL_f_type(z, n, ~) \
0084 >::type
0085
0086 # define BOOST_PP_ITERATION_PARAMS_1 \
0087 \
0088 \
0089 (3, (2, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
0090 "boost/functional/overloaded_function.hpp"))
0091 # include BOOST_PP_ITERATE()
0092
0093 #undef BOOST_FUNCTIONAL_f_type
0094 #undef BOOST_FUNCTIONAL_f_arg
0095 #undef BOOST_FUNCTIONAL_f_tparam
0096 #undef BOOST_FUNCTIONAL_f_arg_decl
0097 #undef BOOST_FUNCTIONAL_f_tparam_dflt
0098 #undef BOOST_FUNCTIONAL_g_type
0099 #undef BOOST_FUNCTIONAL_g_arg
0100 #undef BOOST_FUNCTIONAL_g_tparam
0101 #undef BOOST_FUNCTIONAL_g_arg_decl
0102 #undef BOOST_FUNCTIONAL_base
0103 #undef BOOST_FUNCTIONAL_inherit
0104 #undef BOOST_FUNCTIONAL_base_init
0105 #undef BOOST_FUNCTIONAL_using_operator_call
0106 #undef BOOST_FUNCTIONAL_function_type
0107
0108 # endif
0109
0110 #elif BOOST_PP_ITERATION_DEPTH() == 1
0111 # define BOOST_FUNCTIONAL_overloads \
0112 \
0113 \
0114 BOOST_PP_ADD(2, BOOST_PP_SUB( \
0115 BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
0116 BOOST_PP_FRAME_ITERATION(1)))
0117 # define BOOST_FUNCTIONAL_is_tspec \
0118 \
0119 BOOST_PP_LESS(BOOST_FUNCTIONAL_overloads, \
0120 BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX)
0121
0122
0123 # include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
0124
0125 namespace boost {
0126
0127 template<
0128 BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam_dflt,
0129 BOOST_FUNCTIONAL_is_tspec)
0130 >
0131 class overloaded_function
0132
0133 BOOST_PP_EXPR_IIF(BOOST_PP_EXPAND(BOOST_FUNCTIONAL_is_tspec), <)
0134 BOOST_PP_IIF(BOOST_FUNCTIONAL_is_tspec,
0135 BOOST_PP_ENUM
0136 ,
0137 BOOST_PP_TUPLE_EAT(3)
0138 )(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_type, ~)
0139 BOOST_PP_EXPR_IIF(BOOST_PP_EXPAND(BOOST_FUNCTIONAL_is_tspec), >)
0140
0141 : BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
0142 BOOST_FUNCTIONAL_inherit, ~)
0143 {
0144 public:
0145 template<
0146 BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_g_tparam, ~)
0147 > inline overloaded_function(
0148 BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
0149 BOOST_FUNCTIONAL_g_arg_decl, ~))
0150
0151 : BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
0152 BOOST_FUNCTIONAL_base_init, ~)
0153 {}
0154
0155 BOOST_PP_REPEAT(BOOST_FUNCTIONAL_overloads,
0156 BOOST_FUNCTIONAL_using_operator_call, ~)
0157 };
0158
0159 template<
0160 BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam, ~)
0161 >
0162 overloaded_function<
0163 BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_function_type, ~)
0164 > make_overloaded_function(
0165 BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg_decl, ~)
0166 ) {
0167 return overloaded_function<
0168 BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
0169 BOOST_FUNCTIONAL_function_type, ~)
0170 >(BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg, ~));
0171 }
0172
0173 }
0174
0175
0176 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::overloaded_function,
0177 BOOST_FUNCTIONAL_overloads)
0178
0179 # undef BOOST_FUNCTIONAL_overloads
0180 # undef BOOST_FUNCTIONAL_is_tspec
0181 #endif
0182
0183
0184
0185 #else
0186
0187
0188
0189
0190
0191
0192 namespace boost {
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230 template<typename F1, typename F2, ...>
0231 class overloaded_function {
0232 public:
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244 overloaded_function(const boost::function<F1>&,
0245 const boost::function<F2>&, ...);
0246
0247
0248
0249
0250
0251
0252
0253
0254 typename boost::function_traits<F1>::result_type operator()(
0255 typename boost::function_traits<F1>::arg1_type,
0256 typename boost::function_traits<F1>::arg2_type,
0257 ...) const;
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270 typename boost::function_traits<F2>::result_type operator()(
0271 typename boost::function_traits<F2>::arg1_type,
0272 typename boost::function_traits<F2>::arg2_type,
0273 ...) const;
0274 };
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303 template<typename F1, typename F2, ...>
0304 overloaded_function<
0305 __function_type__<F1>, __function_type__<F2>, ...
0306 > make_overloaded_function(F1 f1, F2 f2, ...);
0307
0308 }
0309
0310 #endif
0311