[12] | 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) |
---|
| 5 | |
---|
| 6 | #ifndef BOOST_PARAMETER_MACROS_050412_HPP |
---|
| 7 | #define BOOST_PARAMETER_MACROS_050412_HPP |
---|
| 8 | |
---|
| 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> |
---|
| 18 | |
---|
| 19 | #define BOOST_PARAMETER_FUN_TEMPLATE_HEAD1(n) \ |
---|
| 20 | template<BOOST_PP_ENUM_PARAMS(n, class T)> |
---|
| 21 | |
---|
| 22 | #define BOOST_PARAMETER_FUN_TEMPLATE_HEAD0(n) |
---|
| 23 | |
---|
| 24 | #ifndef BOOST_NO_SFINAE |
---|
| 25 | |
---|
| 26 | # define BOOST_PARAMETER_MATCH_TYPE(n, param) \ |
---|
| 27 | BOOST_PP_EXPR_IF(n, typename) param::match \ |
---|
| 28 | < \ |
---|
| 29 | BOOST_PP_ENUM_PARAMS(n, T) \ |
---|
| 30 | >::type |
---|
| 31 | |
---|
| 32 | #else |
---|
| 33 | |
---|
| 34 | # define BOOST_PARAMETER_MATCH_TYPE(n, param) param |
---|
| 35 | |
---|
| 36 | #endif |
---|
| 37 | |
---|
| 38 | #define BOOST_PARAMETER_FUN_DECL(z, n, params) \ |
---|
| 39 | \ |
---|
| 40 | BOOST_PP_CAT(BOOST_PARAMETER_FUN_TEMPLATE_HEAD, BOOST_PP_BOOL(n))(n) \ |
---|
| 41 | \ |
---|
| 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)() \ |
---|
| 48 | ) \ |
---|
| 49 | { \ |
---|
| 50 | return BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 1, params), _with_named_params)( \ |
---|
| 51 | kw(BOOST_PP_ENUM_PARAMS(n, p)) \ |
---|
| 52 | ); \ |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | // Generates: |
---|
| 56 | // |
---|
| 57 | // template<class Params> |
---|
| 58 | // ret name ## _with_named_params(Params const&); |
---|
| 59 | // |
---|
| 60 | // template<class T0> |
---|
| 61 | // ret name(T0 const& p0, typename parameters::match<T0>::type kw = parameters()) |
---|
| 62 | // { |
---|
| 63 | // return name ## _with_named_params(kw(p0)); |
---|
| 64 | // } |
---|
| 65 | // |
---|
| 66 | // template<class T0, ..., class TN> |
---|
| 67 | // ret name(T0 const& p0, ..., TN const& PN |
---|
| 68 | // , typename parameters::match<T0, ..., TN>::type kw = parameters()) |
---|
| 69 | // { |
---|
| 70 | // return name ## _with_named_params(kw(p0, ..., pN)); |
---|
| 71 | // } |
---|
| 72 | // |
---|
| 73 | // template<class Params> |
---|
| 74 | // ret name ## _with_named_params(Params const&) |
---|
| 75 | // |
---|
| 76 | // lo and hi determines the min and max arity of the generated functions. |
---|
| 77 | |
---|
| 78 | #define BOOST_PARAMETER_FUN(ret, name, lo, hi, parameters) \ |
---|
| 79 | \ |
---|
| 80 | template<class Params> \ |
---|
| 81 | ret BOOST_PP_CAT(name, _with_named_params)(Params const&); \ |
---|
| 82 | \ |
---|
| 83 | BOOST_PP_REPEAT_FROM_TO( \ |
---|
| 84 | lo, BOOST_PP_INC(hi), BOOST_PARAMETER_FUN_DECL, (ret, name, parameters)) \ |
---|
| 85 | \ |
---|
| 86 | template<class Params> \ |
---|
| 87 | ret BOOST_PP_CAT(name, _with_named_params)(Params const& p) |
---|
| 88 | |
---|
| 89 | #define BOOST_PARAMETER_MEMFUN(ret, name, lo, hi, parameters) \ |
---|
| 90 | \ |
---|
| 91 | BOOST_PP_REPEAT_FROM_TO( \ |
---|
| 92 | lo, BOOST_PP_INC(hi), BOOST_PARAMETER_FUN_DECL, (ret, name, parameters)) \ |
---|
| 93 | \ |
---|
| 94 | template<class Params> \ |
---|
| 95 | ret BOOST_PP_CAT(name, _with_named_params)(Params const& p) |
---|
| 96 | |
---|
| 97 | #endif // BOOST_PARAMETER_MACROS_050412_HPP |
---|
| 98 | |
---|