1 /*============================================================================== 2 Copyright (c) 2005-2010 Joel de Guzman 3 Copyright (c) 2010 Thomas Heller 4 Copyright (c) 2015 John Fletcher 5 6 Distributed under the Boost Software License, Version 1.0. (See accompanying 7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 ==============================================================================*/ 9 #ifndef BOOST_PHOENIX_FUNCTION_ADAPT_FUNCTION_HPP 10 #define BOOST_PHOENIX_FUNCTION_ADAPT_FUNCTION_HPP 11 12 #include <boost/phoenix/core/limits.hpp> 13 #include <boost/phoenix/core/detail/function_eval.hpp> 14 #include <boost/preprocessor/repetition/repeat.hpp> 15 16 #define BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY(RESULT, NAME, FUNC) \ 17 namespace detail0 \ 18 { \ 19 struct BOOST_PP_CAT(NAME, _impl_nullary) \ 20 { \ 21 typedef RESULT result_type; \ 22 \ 23 result_type \ 24 operator()() const \ 25 { \ 26 return FUNC(); \ 27 } \ 28 }; \ 29 } \ 30 \ 31 inline \ 32 boost::phoenix::detail::expression::function_eval< \ 33 detail0:: BOOST_PP_CAT(NAME, _impl_nullary) \ 34 >::type const \ 35 NAME() \ 36 { \ 37 return boost::phoenix::detail::expression:: \ 38 function_eval<detail0:: BOOST_PP_CAT(NAME, _impl_nullary)> \ 39 ::make(detail0:: BOOST_PP_CAT(NAME, _impl_nullary)()); \ 40 } \ 41 /**/ 42 43 #define BOOST_PHOENIX_ADAPT_FUNCTION(RESULT, NAME, FUNC, N) \ 44 namespace detail1 \ 45 { \ 46 struct BOOST_PP_CAT(BOOST_PP_CAT(NAME, _impl_), N) \ 47 { \ 48 template <typename Sig> \ 49 struct result; \ 50 \ 51 template <typename This, BOOST_PHOENIX_typename_A(N)> \ 52 struct result<This(BOOST_PHOENIX_A(N))> \ 53 {typedef RESULT type;}; \ 54 \ 55 template <BOOST_PHOENIX_typename_A(N)> \ 56 RESULT \ 57 operator()(BOOST_PHOENIX_A_ref_a(N)) const \ 58 { \ 59 return FUNC(BOOST_PHOENIX_a(N)); \ 60 } \ 61 }; \ 62 } \ 63 \ 64 template <BOOST_PHOENIX_typename_A(N)> \ 65 inline \ 66 typename \ 67 boost::phoenix::detail::expression::function_eval< \ 68 detail1:: BOOST_PP_CAT(BOOST_PP_CAT(NAME, _impl_), N) \ 69 , BOOST_PHOENIX_A(N)>::type const \ 70 NAME(BOOST_PHOENIX_A_const_ref_a(N)) \ 71 { \ 72 return boost::phoenix::detail::expression:: \ 73 function_eval< \ 74 detail1:: BOOST_PP_CAT(BOOST_PP_CAT(NAME, _impl_), N) \ 75 , BOOST_PHOENIX_A(N) \ 76 >::make( \ 77 detail1:: BOOST_PP_CAT(BOOST_PP_CAT(NAME, _impl_), N)() \ 78 , BOOST_PHOENIX_a(N) \ 79 ); \ 80 } \ 81 /**/ 82 83 #define BOOST_PHOENIX_ADAPT_FUNCTION_VARARG(RESULT, NAME, FUNC) \ 84 BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY(NAME, FUNC) \ 85 BOOST_PP_REPEAT_FROM_TO( \ 86 1 \ 87 , BOOST_PHOENIX_LIMIT \ 88 , BOOST_PHOENIX_ADAPT_FUNCTION_VARARG_R \ 89 , (RESULT, NAME, FUNC) \ 90 ) \ 91 /**/ 92 93 #define BOOST_PHOENIX_ADAPT_FUNCTION_VARARG_R(Z, N, D) \ 94 BOOST_PHOENIX_ADAPT_FUNCTION( \ 95 BOOST_PP_TUPLE_ELEM(3, 0, D) \ 96 , BOOST_PP_TUPLE_ELEM(3, 1, D) \ 97 , BOOST_PP_TUPLE_ELEM(3, 2, D) \ 98 , N \ 99 ) \ 100 /**/ 101 102 #endif 103