1 // Copyright David Abrahams, Daniel Wallin 2003. Use, modification and
2 // distribution is subject to the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_PARAMETER_MACROS_050412_HPP
7 #define BOOST_PARAMETER_MACROS_050412_HPP
9 #include <boost/preprocessor/tuple/elem.hpp>
10 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
11 #include <boost/preprocessor/arithmetic/inc.hpp>
12 #include <boost/preprocessor/logical/bool.hpp>
13 #include <boost/preprocessor/punctuation/comma_if.hpp>
14 #include <boost/preprocessor/control/expr_if.hpp>
15 #include <boost/preprocessor/repetition/enum_params.hpp>
16 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
17 #include <boost/preprocessor/cat.hpp>
19 #define BOOST_PARAMETER_FUN_TEMPLATE_HEAD1(n) \
20 template<BOOST_PP_ENUM_PARAMS(n, class T)>
22 #define BOOST_PARAMETER_FUN_TEMPLATE_HEAD0(n)
24 #ifndef BOOST_NO_SFINAE
26 # define BOOST_PARAMETER_MATCH_TYPE(n, param) \
27 BOOST_PP_EXPR_IF(n, typename) param::match \
29 BOOST_PP_ENUM_PARAMS(n, T) \
34 # define BOOST_PARAMETER_MATCH_TYPE(n, param) param
38 #define BOOST_PARAMETER_FUN_DECL(z, n, params) \
40 BOOST_PP_CAT(BOOST_PARAMETER_FUN_TEMPLATE_HEAD, BOOST_PP_BOOL(n))(n) \
42 BOOST_PP_TUPLE_ELEM(3, 0, params) \
43 BOOST_PP_TUPLE_ELEM(3, 1, params)( \
44 BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& p) \
45 BOOST_PP_COMMA_IF(n) \
46 BOOST_PARAMETER_MATCH_TYPE(n,BOOST_PP_TUPLE_ELEM(3, 2, params)) \
47 kw = BOOST_PP_TUPLE_ELEM(3, 2, params)() \
50 return BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 1, params), _with_named_params)( \
51 kw(BOOST_PP_ENUM_PARAMS(n, p)) \
57 // template<class Params>
58 // ret name ## _with_named_params(Params const&);
61 // ret name(T0 const& p0, typename parameters::match<T0>::type kw = parameters())
63 // return name ## _with_named_params(kw(p0));
66 // template<class T0, ..., class TN>
67 // ret name(T0 const& p0, ..., TN const& PN
68 // , typename parameters::match<T0, ..., TN>::type kw = parameters())
70 // return name ## _with_named_params(kw(p0, ..., pN));
73 // template<class Params>
74 // ret name ## _with_named_params(Params const&)
76 // lo and hi determines the min and max arity of the generated functions.
78 #define BOOST_PARAMETER_FUN(ret, name, lo, hi, parameters) \
80 template<class Params> \
81 ret BOOST_PP_CAT(name, _with_named_params)(Params const&); \
83 BOOST_PP_REPEAT_FROM_TO( \
84 lo, BOOST_PP_INC(hi), BOOST_PARAMETER_FUN_DECL, (ret, name, parameters)) \
86 template<class Params> \
87 ret BOOST_PP_CAT(name, _with_named_params)(Params const& p)
89 #define BOOST_PARAMETER_MEMFUN(ret, name, lo, hi, parameters) \
91 BOOST_PP_REPEAT_FROM_TO( \
92 lo, BOOST_PP_INC(hi), BOOST_PARAMETER_FUN_DECL, (ret, name, parameters)) \
94 template<class Params> \
95 ret BOOST_PP_CAT(name, _with_named_params)(Params const& p)
97 #endif // BOOST_PARAMETER_MACROS_050412_HPP