Chris@16: #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES) Chris@16: Chris@16: #include Chris@16: Chris@16: #elif !defined(BOOST_PP_IS_ITERATING) Chris@16: Chris@16: #define BOOST_PROTO_CHILD_N_TYPE(Z, N, Expr) \ Chris@16: typedef typename proto::result_of::child_c::type BOOST_PP_CAT(child, N); \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_CHILD_N(Z, N, expr) \ Chris@16: proto::child_c(expr) \ Chris@16: /**/ Chris@16: Chris@16: #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) Chris@16: #pragma wave option(preserve: 2, line: 0, output: "preprocessed/callable_eval.hpp") Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file callable_eval.hpp Chris@16: /// Contains specializations of the callable_eval\<\> class template. Chris@16: // Chris@16: // Copyright 2008 Eric Niebler. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) Chris@16: #pragma wave option(preserve: 1) Chris@16: #endif Chris@16: Chris@16: #define BOOST_PP_ITERATION_PARAMS_1 \ Chris@16: (3, (1, BOOST_PROTO_MAX_ARITY, )) Chris@16: #include BOOST_PP_ITERATE() Chris@16: Chris@16: #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) Chris@16: #pragma wave option(output: null) Chris@16: #endif Chris@16: Chris@16: #undef BOOST_PROTO_CHILD_N_TYPE Chris@16: #undef BOOST_PROTO_CHILD_N Chris@16: Chris@16: #else Chris@16: Chris@16: #define N BOOST_PP_ITERATION() Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: template Chris@16: struct is_expr_handled Chris@16: { Chris@16: static callable_context_wrapper &sctx_; Chris@16: static Expr &sexpr_; Chris@16: static typename Expr::proto_tag &stag_; Chris@16: Chris@16: static const bool value = Chris@16: sizeof(yes_type) == Chris@16: sizeof( Chris@16: detail::check_is_expr_handled( Chris@16: (sctx_( Chris@16: stag_ Chris@16: BOOST_PP_ENUM_TRAILING(N, BOOST_PROTO_CHILD_N, sexpr_) Chris@16: ), 0) Chris@16: ) Chris@16: ); Chris@16: Chris@16: typedef mpl::bool_ type; Chris@16: }; Chris@16: } Chris@16: Chris@16: namespace context Chris@16: { Chris@16: /// \brief A BinaryFunction that accepts a Proto expression and a Chris@16: /// callable context and calls the context with the expression tag Chris@16: /// and children as arguments, effectively fanning the expression Chris@16: /// out. Chris@16: /// Chris@16: /// callable_eval\<\> requires that \c Context is a Chris@16: /// PolymorphicFunctionObject that can be invoked with \c Expr's Chris@16: /// tag and children as expressions, as follows: Chris@16: /// Chris@16: /// \code Chris@16: /// context(Expr::proto_tag(), child_c\<0\>(expr), child_c\<1\>(expr), ...) Chris@16: /// \endcode Chris@16: template Chris@16: struct callable_eval Chris@16: { Chris@16: BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD_N_TYPE, Expr) Chris@16: Chris@16: typedef Chris@16: typename BOOST_PROTO_RESULT_OF< Chris@16: Context( Chris@16: typename Expr::proto_tag Chris@16: BOOST_PP_ENUM_TRAILING_PARAMS(N, child) Chris@16: ) Chris@16: >::type Chris@16: result_type; Chris@16: Chris@16: /// \param expr The current expression Chris@16: /// \param context The callable evaluation context Chris@16: /// \return context(Expr::proto_tag(), child_c\<0\>(expr), child_c\<1\>(expr), ...) Chris@16: result_type operator ()(Expr &expr, Context &context) const Chris@16: { Chris@16: return context( Chris@16: typename Expr::proto_tag() Chris@16: BOOST_PP_ENUM_TRAILING(N, BOOST_PROTO_CHILD_N, expr) Chris@16: ); Chris@16: } Chris@16: }; Chris@16: } Chris@16: Chris@16: #undef N Chris@16: Chris@16: #endif